欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

c语言改错和填空能运行吗,C语言改错填空编程

发布时间:2025/3/11 37 豆豆
生活随笔 收集整理的这篇文章主要介绍了 c语言改错和填空能运行吗,C语言改错填空编程 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

改错题

1、在考生文件夹下,给定程序MODI.C的功能是:

从低位开始取出长整型变量s中奇数位上的数,依次构成一个新数放在t中。例如,当s中的数为:7654321时,t中的数为:7531。

请修改并运行该程序,然后将源程序文件MODI.C上传。

#include

#include

main( )

{ long s, t, sl=10;

clrscr();

printf("\nPlease enter s:");

scanf("%ld", &s);

/************found************/

t = s / 10; s%10 改为 t=s%10;

while ( s > 0)

{ s = s/100;

t = s%10 * sl + t;

/************found************/

sl = sl*100 ;改为 S1=S1*10;

}

printf("The result is: %ld\n", t);

}

2、在考生文件夹下,给定程序MODI.C的功能是:

求一维数组a中的值为偶数的元素之和。例如,当一维数组a中的元素为:10,4,2,7,3,12,5,34,5,9 ,

程序的输出应为:The result is: 62

#include

#include

main()

{ int a[10]={10,4,2,7,3,12,5,34,5,9},i,s;

clrscr();

s = 0;

for ( i=0; i<10; i++)

/************found************/

if (i % 2 == 0) 改为if (a[i] % 2 == 0)

s = s + a[i];

/************found************/

print("The result is: %d\n", s);

}

3、在考生文件夹下,给定程序MODI.C的功能是:

求一维数组a中值为偶数的元素之和。

例如,当一维数组a中的元素为:10,4,2,7,3,12,5,34,5,9 ,

程序的输出应为:The result is: 62。

#include

#include

sum ( int arr[ ],int n )

{ int i,s;

clrscr();

s = 0;

for ( i=0; i

if (arr[i] % 2 == 0)

/************found************/

s = s + i; 改为s = s + [i];

return (s);

}

main()

{ int a[10]={10,4,2,7,3,12,5,34,5,9},i,s;

/************found************/

s = sum( a ,2 ); 改为s = sum( a ,10);

printf("The result is: %d\n", s);

}

4、在考生文件夹下,给定程序MODI.C的功能是:

求二维数组a中的最大值。

例如,当二维数组a中的元素为:

4 4 34

7 3 12

5 6 5

程序的输出应为:The max is: 34 。

#include

#include

main()

{ int a[3][3]={4,4,34,7,3,12,5,6,5},i,j,max;

clrscr();

max = a[0][0];

for ( i=0; i<3; i++)

for ( j=0; j<3; j++)

/************found************/

if (max > a[i][j])

{

/************found************/

max == a[i][j];

}

printf("The max is: %d\n", max);

}

5、在考生文件夹下,给定程序MODI.C的功能是:

求一维数组a中的最大元素及其下标。

例如,当一维数组a中的元素为:1,4,2,7,3,12,5,34,5,9,

程序的输出应为:The max is: 34,p

os is: 7 。

#include

#include

main()

{ int a[10]={1,4,2,7,3,12,5,34,5,9},i,max,pos;

clrscr();

max = a[0];

创作挑战赛新人创作奖励来咯,坚持创作打卡瓜分现金大奖

总结

以上是生活随笔为你收集整理的c语言改错和填空能运行吗,C语言改错填空编程的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。