2011天津高职升本计算机C语言程序设计(ANSWER)
stdio.h>
main() { int n;
for( n=100 ; n<=999 ;n++) if(n%13!=0) continue ;
#include <stdio.h> long Sum(int n)
{ if(n> 1 )
return n+Sum(n-1) ;
else
return 1 ;
}
6. 阅读以下程序并填空。函数StrLength的功能
else printf(&uot;%d\n&uot;,n);}
2. 阅读以下程序并填空。以下程序的功能是:输
出100以内能被3整除且个位数为6的所有整数
#include <stdio.h> main()
{ int i,j;
for(i=0; i<=9 ;i++) 7. { j= i*10+6 ;
if(j%3!=0) continue; else printf(&uot;%d\n&uot;,j);
} }
3. 阅读以下程序并填空。以下的程序功能是:求
101至999之间所有能被13整除的整数之和和
个数
#include <stdio.h> main()
8. { int i,cnt; float sum=0; i=101; cnt=0; while( i<=999 )
{ if( i%13==0 )
{ sum+=i; cnt++; } i++ ; }
printf(&uot;sum=%f,cnt=%d\n&uot;,sum,cnt);} 4. 阅读以下程序并填空。该程序的功能是:用递
归的方法求菲波那契数列2,2,4,6,10,16,
26,42,68,110,??的第10项 #include <stdio.h> 9.long fib(int n)
{ if(n>= 3 )
return fib(n-1)+fib(n-2) ;
else
return 2 ; }
main()
{ printf(&uot;%ld\n&uot;,fib(10)); }
5. 阅读以下程序并填空。该程序的功能是:用递
归法求:1?2?3???n
1
是:计算并返回字符串s的长度 #include <stdio.h> int StrLength(char *s) { int i= 0 ;
while( s[i]!='\0' )
i++;
return i ; }
阅读以下程序并填空。函数delchar的功能是:
删除字符串s中的所有数字字符
#include <stdio.h> void delchar(char *s) { int i,n=0;
for(i=0;s[i]!='\0';i++)
if(!(s[i]>='0'&&s[i]<='9')) s[ n++ ]=s[i]; s[n]='\0' ; }
阅读以下程序并填空。以下程序的功能是:计
算:s?1?
112?3???
1n
#include <stdio.h> main()
{ int n;
float s=0 ; scanf(&uot;%d&uot;,&n); while(n>0) { s=s+ 1.0/n ; n-- ; }
printf(&uot;Result is:%f\n&uot;,s); }
阅读以下程序并填空。以下程序的功能是:实
现累加输入变量x各个数位之和
#include <stdio.h> main()
{ int x,s=0;
scanf(&uot;%d&uot;,&x);