简单c问题 新手一枚 欢迎指教
# include <stdio.h>
void main()
{
int large (int x, int y); /*函数声明*/
int a[10],b[10],i,n=0,m=0,k=0;
printf("enter array a;\n");
for(i=0;i<10;i++)
scanf("%d",&a[i]);
printf("\n");
printf("enter array b;\n");
for(i=0;i<10;i++)
scanf("%d",&b[i]);
printf("\n");
for(i=0;i<10;i++)
{
if(large(a[i],b[i])==1)
n=n+1;
else
if(large(a[i],b[i])==0)
m=m+1;
else
k=k+1;
}
printf("a[i]>b[i] %d times\na[i]=b[i] %d times\na[i]<b[i] %d times\n",n,m,k);
if(n>k)
printf("array a is larger than array b\n");
else
if(n<k)
printf("array a is smaller than array b\n");
else
printf("array a is equal to array b\n");
}
large(int x,int y)
{
int flag;
if(x>y)
flag=1;
else if(x<y)
flag=-1;
else flag=0;
return(flag);
}
一个数组元素做函数实参的小程序
用的是vc++2008
这个问题是什么原因呢 scanf和scanf_s有什么区别 c vc++
[解决办法]
http://zhidao.baidu.com/question/123882045.html
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int a[10], b[10], i, n = 0, m = 0, k = 0;
printf("enter array a;\n");
for (i = 0; i < 10; i++) scanf_s("%d", &a[i]);
printf("\n");
printf("enter array b;\n");
for (i = 0; i < 10; i++) scanf_s("%d", &b[i]);
printf("\n");
for (i = 0; i < 10; i++) a[i] > b[i] ? n++ : a[i] < b[i] ? k++ : m++;
printf("a[i]>b[i] %d times\na[i]=b[i] %d times\na[i]<b[i] %d times\n", n,
/**/ m, k);
if (n > k) printf("array a is larger than array b\n");
else if (n < k) printf("array a is smaller than array b\n");
else printf("array a is equal to array b\n");
system("pause");
return 0;
}