
正文
c语言函数后面能加分吗 c语言函数后面用加分号吗
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
C语言问题
可以的,指针指向了两个数组,我在vc上都通过了的
----------------
数组名就等于是首地址了啊,我不会用错的
(1)
#includestdio.h
main()
{
int A1(int A[4][4],int B[4][4]);
int q[4][4]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16},w[4][4]={17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32},a,b;
int *n,*m;
n=q;m=w;
A1(n,m);
}
int A1(int A[][4],int B[][4])
{
int C[4][4],D[4][4],E[4][4],i,j;
for(i=0;i4;i++)
for(j=0;j4;j++)
{C[i][j]=A[i][j]+B[i][j];
D[i][j]=A[i][j]-B[i][j];
E[i][j]=A[i][j]*B[i][j];}
printf("--------------------A------------------------\n");
for(i=0;i4;i++)
{{for(j=0;j4;j++)
printf("%7d",A[i][j]);}
printf("\n");}
printf("--------------------B------------------------\n");
for(i=0;i4;i++)
{{for(j=0;j4;j++)
printf("%7d",B[i][j]);}
printf("\n");}
printf("--------------------A+B------------------------\n");
for(i=0;i4;i++)
{{for(j=0;j4;j++)
printf("%7d",C[i][j]);}
printf("\n");}
printf("--------------------A-B------------------------\n");
for(i=0;i4;i++)
{{for(j=0;j4;j++)
printf("%7d",D[i][j]);}
printf("\n");}
printf("--------------------A*B------------------------\n");
for(i=0;i4;i++)
{{for(j=0;j4;j++)
printf("%7d",E[i][j]);}
printf("\n");}
}
(2)
int A2(int px[],int n)
{
int i,j,temp;
for(i=0;in;i++)
for(j=0;jn-i;j++)
if(px[j]px[j+1])
{temp=px[j];
px[j]=px[j+1];
px[j+1]=temp;}
}
(3)
char A3(char zf[])
{
int fh[2]={0,0},c;
for(i=0;(c=zf[i])!='\0';i++)
{
if(c='0' c='9') fh[0]++;
else fh[1]++;
}
return(fh);
}
(4)
long A4(long s)
{
long a,b=0,h=s,c,d;
for(d=1;d=s;d++)
for(c=0;a!=0;c++)
{
a=s%10;
b=b+a*a*a;
h=(s-a)/10;
}
if(b==d) printf(" %10d",d)
}
(5)
float A5(int s[],int n)
{
int i,j=0,sum=0;
float avg;
int ou[n];
for(i=0;in;i++)
{
if(s[i]%2==0) {ou[j]=s[i];
j++;sum=sum+ou[j];}
}
avg=sum/j;//可能不会得出精确值,flaot的
printf("avg=%f\n",avg);
printf("he shu=%d\n",j);
}
相关问答
Q1: 求C语言高手解释下 加分
#include "stdafx.h"
#include stdio.h
int main(int argc, char* argv[])
{
int m,n,flag;
//输出提示,在屏幕上显示The primers form 100 to 200 is:
printf("\nThe primers form 100 to 200 is:\n");
for(n=101;n=200;n+=2)//从101开始到200为止,遍历所有的奇数,判断是否为质数 {
flag=1;//标记变量,1代表是质数,0代表不是质数
//这个for循环从2一直到n/2判断其是不是n的因子,如果是,则不是质数
//用n/2不合适,应该是sqrt(n),即n的平方根
for(m=2;m=n/2;m++)
{
if(n%m==0)
{
flag=0;//设置标记变量
break;
}
}
if(flag==0)
continue;//假如不是变量则不输出,如果是输出该数
printf("%d,",n);
}
printf("\n");
return 0;
}
Q2: 求一段C语言的 队列 数据结构代码,能用的就加分啊!
#ifndef QUEUE_H
#define QUEUE_H
#include iostream
using std::cout;
using std::endl;
using std::ostream;
template class Type
class Queue {
friend ostream operator (ostream , const QueueType );
public:
static const int DefaultSize;
Queue(int = DefaultSize); //创建一个最大容量为MaxQueueSize的空队列
Queue(Type [], int, int = DefaultSize);
~Queue() {delete [] queue;}
bool IsFull(); //若元素个数等于队列的最大容量则返回true,否则返回false
void Add(const Type ); //若IsFull()为true,调用外处理函数QueueFull(),否则将item插入队尾
bool IsEmpty() const; //若队列中元素个数等于0,则返回true,否则返回false
Type * Delete(Type ); //若IsEmpty()为true,调用QueueEmpty()并返回0,否则删除队列前段元素并返回其指针
void Empty(); //清空队列
void QueueFull(); //扩充1倍的存储空间
void QueueEmpty(); //提示队列已空,元素不能出队
private:
int front, rear;
Type * queue;
int maxSize;
};
template class Type
const int QueueType::DefaultSize = 10;
template class Type
QueueType::Queue(int pMaxSize) {
queue = new Type [pMaxSize];
maxSize = pMaxSize;
front = rear = -1;
}
template class Type
QueueType::Queue(Type pArray[], int pSize, int pMaxSize) {
queue = new Type [pMaxSize];
for (int i = 0; i pSize; i++)
{
queue[i] = pArray[i];
}
front = -1; rear = pSize - 1;
maxSize = pMaxSize;
}
template class Type
bool QueueType::IsFull() {
if ( rear == maxSize - 1 ) return true;
else return false;
}
template class Type
bool QueueType::IsEmpty() const {
if ( rear == front ) return true;
else return false;
}
template class Type
void QueueType::Add(const Type pX) {
if (IsFull())
{
QueueFull();
queue[++rear] = pX;
}
else
{
queue[++rear] = pX;
}
}
template class Type
Type * QueueType::Delete(Type pX) {
if (IsEmpty())
{
QueueEmpty();
return 0;
}
else
{
pX = queue[++front];
return pX;
}
}
template class Type
void QueueType::QueueEmpty() {
cout "队列为空,不能进行出队操作!" endl;
}
template class Type
void QueueType::QueueFull() {
Type * newQueue = new Type [maxSize * 2];
for ( int i = front + 1; i = rear; i++ )
{
newQueue[i] = queue[i];
}
maxSize = maxSize * 2;
delete [] queue;
queue = newQueue;
cout "队列已满,现已增加空间为原来的2倍 " maxSize;
}
template class Type
void QueueType::Empty() {
front = rear = -1;
}
template class Type
ostream operator (ostream pOutput, const QueueType pQ) {
if (pQ.IsEmpty())
{
cout "空队列" endl;
return pOutput;
}
for ( int i = pQ.front + 1; i = pQ.rear; i++ )
{
pOutput pQ.queue[i] " ";
}
cout endl;
return pOutput;
}
#endif
Q3: C语言编写一个函数满足下列条件
y=x0?0:(x=10?x:(x=20?10:(x40?-0.5*x+20:_____)));上面的横线是因为大哗海糕剿蕹济革汐宫搂于等于40的情况你没有限定。如果已知X肯定小于40,那么最后一个判断可以去掉:y=x0?0:(x=10?x:(x=20?10:-0.5*x+20)); 这看上去很乱。再多的话可以用if写了。
条件应该是:x0时 y=0; 0x=10时 y=x; 10x=20时 y=10; 20x40时 y=-0.5*x+20;帮你用if else 和switch语句各写了个. 你看看.用if else结构:#include stdio.hint main()
{int x,y;scanf("%d",x);
if(x0) y=0;
else if(x=10) y=x;
else if(x=20) y=10;
else if(x40) y=-0.5*x+20; printf("y=%d\n",y);return 0;}
用switch case语句:#include stdio.hint main(){int x,y;scanf("%d",x);if(x0) y=0;else{switch(x/10) {case 0:y=x; break;
case 1: if(x==10) y=x;else y=10;break;
case 2: if(x==20) {y=10; break;}
case 3: y=-0.5*x+20; break;}}printf("y=%d\n",y);return 0;}
关于c语言函数后面能加分吗和c语言函数后面用加分号吗的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。







