C语言改错题,根据题目修改图中错误的源程序代码? c语言程序改错题题库
c语言中的程序改错题,指出程序中的错误并改正
#include<stdio.h>
int main( )
{
int i ,sum=0; // sum要赋初值
float average;
int score[10],p=score; // 这里将指针赋值给整型, 应改为 *p = score;
for(i=0;i<10;i++)
{
scanf("%d",p);
sum+=*p;
p++; // 这句应该放在这里,要加完之后再改变 p的值
}
average=sum/10; // 这里计算结果为整型,应该为 sum/10.0
printf("average=%f\n",average);
return 0;
}
C语言改错、填空、编程求解!!!
1.
#include <stdio.h>
main( )
{ long s, t, sl=10;
system("CLS");
printf("\nPlease enter s:"); scanf("%ld", &s);
/************found************/
t = s % 10;
while ( s > 0)
{ s = s/100;
t = s%10 * sl + t;
/************found************/
sl = sl*10;
}
printf("The result is: %ld\n", t);
}
2.
#include <stdio.h>
#define M 11
main()
{ int a[M],i;
system("CLS");
for(i=0;i<M-1;i++)
scanf("%d",&a[i]);
/************found************/
a[M-1]=a[0];
for(i=1;i<M-1;i++)
/************found************/
if(a[M-1]<a[i])
a[M-1]=a[i];
printf("Max is %d\n",a[M-1]);
}
3.
#include <conio.h>
#include <stdio.h>
long fun(int a, int b)
{ long c;
/***********begin***********/
c = (a/10)*1000+(a%10)*10+(b/10)*100+(b%10);
/***********end************/
return c;
}
main()
{ int a,b; long c;
system("CLS");
printf("Input a, b:"); scanf("%d,%d", &a, &b);
c = fun(a, b);
printf("The result is: %ld\n", c);
}
C语言改错题,请在原程序中改错····
#include
main( )
{
int a[10]= {1,2,3,4,5,6,7,8,9,10};
int i,t;
/**********error***************/
for(i=0;i<5;i++)
{
t=a[i];
/**********error***************/
a[i]=a[9-i] a[9-i]=t;
}
for(i=0;i<10;i++)
{
/**********error***************/
printf("%4d",a[10] );
}
C语言程序的改错
int main()
{double t=1.0;
int i;
for(i=2;i<=10;i++);
t+=1.0/i; //1.0/i
printf("t=%f\n",t);
return 0
}