当前位置:首页 > 河南科技大学c语言题库
/**************found************/
for(i=1;i<=M;i+=2)
{ a+=i;
/**************found************/
b=i+1; c+=b; }
printf(\printf(\
}
32.实现在N行M列的二维数组中,找出每一行上的最大值,且原数组值不变。 例
如:如果二维数组元素的值为:
1 5 7 4 2 6 4 3 8 2 3 1
时,程序的运行结果应为:The max value in line 0 is 7
The max value in line 1 is 6 The max value in line 2 is 8
#define M 4 #define N 3 void main() { int i,j,p,x[N]
={1,5,7,4,2,6,4,3,8,2,3,1}; /************found************/
for(i=0;i { p=0; for(j=0;j /************found************/ x[i][p]=x[i][j]; 或p=j; printf(\ } } 33.查找n在数组a中最后一次出现的位置。 例如:如果a数组中的元素为:1,5,2,5,6,8,7,4,3,0, 当n=5时,程序的输出结果为:5 is No.3 。 当n=10时,程序的输出结果应为:10 not found !。 #include { int a[10]={1,5,2,5,6,8,7,4,3,0}; int i,k,n,f=0; scanf(\for(i=0;i<10;i++) /************found************/ if(n==a[i]) { f=1; /************found************/ k=i; } if (f) printf(\else printf(\ } 33.查找n在数组a中最后一次出现的位置。 例如:如果a数组中的元素为:1,5,2,5,6,8,7,4,3,0, 当n=5时,程序的输出结果为:5 is No.3 。 当n=10时,程序的输出结果应为:10 not found !。 #include { int a[10]={1,5,2,5,6,8,7,4,3,0}; int i,k,n,f=0; scanf(\for(i=0;i<10;i++) /************found************/ if(n==a[i]) { f=1; /************found************/ k=i; } if (f) printf(\else printf(\ } 34.求两个正整数x,y的最小公倍数。 例如:如果x=24,y=36,程序的输出应为:min is : 72。 #include void main() { int x,y,t,i; printf(\ scanf(\ if(x > y) {t = x; x = y; y = t;} /************found************/ for ( i=y; i<=x*y ;i++) { if(i%x==0 && i%y==0 ) break; } /************found************/ printf(\ } 35.求两个正整数x,y的最大公约数和最小公倍数。 例如:如果x=24,y=36,程序的输出应为: max is : 12, min is : 72 。 #include void main() { int x,y,t,max,min,i,n1,n2; scanf(\ if(x > y) {t = x; x = y; y = t;} n1=x; n2=y; t = n2 % n1; /************found************/ while( t!=0) 或while(t) { n2 = n1 ; n1 = t ; t = n2 % n1; } /************found************/ max = n1 ; min = x * y / max ; printf(\printf(\ } 目录 目录 1 改错题 1 填空题 10 编程题 18 按住Ctrl键,点击某目录项,当前页面自动跳转至该目录项所在的页码 改错题 改错题答题要求: 程序中有两处错误,错误都在提示行:/***********found***********/的下面 一行,请考生注意。请改正程序中的错误,使它能得出正确的结果。 注意:程序中的其它地方请考生不要随意改动,不得增行或删行,也不得更改程 序的结构!(注:红色的为已改过的) 1、从低位开始取出长整型变量s中奇数位上的数,依次构成一个新数放在t中。 例如,当s中的数为:7654321时,t中的数为:7531。 源文件: #include { long s, t, sl=10; printf(\scanf(\ /************found************/ t = s ; while ( s > 0) { s = s/100; t = s * sl + t; /************found************/ sl = sl*10; } printf(\} 2、先将在字符串s中的字符按正序存放到t串中,然后把s中的字符按逆序连接到t串的后面。例如:当s中的字符串为:\时,则t中的字符串应为:\。 源文件: #include { char s[80],t[80]; int i, sl; printf(\scanf(\sl = strlen(s); /************found************/ for( i=0; i for (i=0; i /************found************/ t[sl+i] = '\\0'; printf(\} 3、求两实数平方根之和,输出此和。例如:输入12和20,输出结果是:y = 7.936238。 源文件: #include /************found************/ double a, b, y; printf ( \scanf (\ /************found************/ y = sqrt(a)+sqrt(b) ;
共分享92篇相关文档