急!有谁帮我解决几个简单的C语言问题啊!只有1天时间了

来源:百度知道 编辑:UC知道 时间:2024/05/10 04:34:47
填空题
1.从键盘输入10个数存入数组a中,统计数组下标是奇数且数组元素值为偶数的元素个数。
#include <stdio.h>
main()
{int a[10],i,s;
___ /*$BLANK1$*/
for(i=0;___;i++) /*$BLANK2$*/
{scanf("%d",&a[i]);
if(i%2==1__a[i]%2==0) /*$BLANK3$*/
s++;
}
printf("%d\n",s);
}

2.从键盘输入10个数寸如数组a中,再将数组中的元素逆序存放后输出
#include <stdio.h>
main()
{int a[10],i,j,t;
i=0;
while(___) /*$BLANK1$*/
{scanf("%d",&a[i]);
i++;}
i=0;
___ /*$BLANK2$*/
while(i<j)
{t=a[i];a[i]=a[j];a[j]=t;
i++;
___ /*$BLANK3$*/
}
for(i=0;i<10;i++)
printf("%d ",a[i]);
}

3.完善程序,使5×5数组的主对角线元素的值为1,其他元素的值为0。
#include<stdio.h>
long fac(int n)
{
int i;long s;
s=0; /*$ERROR1$*/
i=1;
while(i<n) /*$ERROR2$*/
{s=s*i;
i++;}
return s;
}

第3题 程序与题目意思不一致,按程序的意思是求一个数n的阶乘!
楼主自己检查一下

// 1
#include <stdio.h>
main()
{
int a[10],i,s;
s=0;/*$BLANK1$*/
for(i=0;i<10;i++) /*$BLANK2$*/
{
scanf("%d",&a[i]);
if(i%2==1&&a[i]%2==0) /*$BLANK3$*/
s++;
}
printf("%d\n",s);
}

//2
#include <stdio.h>
main()
{int a[10],i,j,t;
i=0;
while(i<10) /*$BLANK1$*/
{scanf("%d",&a[i]);
i++;}
i=0;
j=9; /*$BLANK2$*/
while(i<j)
{t=a[i];a[i]=a[j];a[j]=t;
i++;
j--; /*$BLANK3$*/
}
for(i=0;i<10;i++)
printf("%d ",a[i]);
}

//3
#include<stdio.h>
long fac(int n)
{
int i;long s;
s=1; /*$ERROR1$*/
i=1;
while(i<=n) /*$ERROR2$*/
{s=s*i;
i++;}
return