PTA函数答案(整理)(一).pdfVIP

  • 196
  • 0
  • 约1.51万字
  • 约 25页
  • 2020-10-22 发布于广东
  • 举报
三、程序填空题 3 -32 程序阅读: 6#21# 下列程序将输出 (5分)。 # include stdio.h int s; int f(int m) { static int k=0; for(; k=m; k++) s++; return s; } int main(void ) { int s=1; s=f(2)+f(2); printf(%d#%d#, s, f(20)); return 0; } 四、函数 4-3 求 m 到 n 之和 (10 分) int sum(int m, int n) { int i; int s=0; for(i=m; i=n; i++) s= s + i; return (s); } 1 4-34 简单输出整数 (10 分) void PrintN ( int N ) { int i; for(i=1; i=N; i++) printf(%d\n, i); } 4-36 简单求和 (10 分) int Sum ( int List[], int N ) { int k; int sum=0; for(k=0; kN; k++) sum += List[k]; return sum; } 4-40 简单阶乘计算 (10 分) int Factorial( const int N ) { int i; int s=1; if( N 0 ) return 0; else if( N == 0) return 1; else for(i=1; i=N; i++) s*=i; return s; } 2 4-41 统计个位数字 (15 分) int Count_Digit(const int N, const int D) { int x; int count=0; int temp=0; x=N; if(x0) x=-x; do { temp=x%10; if(temp==D) count++; x=x/10; } while(x0); return count; } 4-43 找两个数中最大者 (10 分) int max( int a, int b ) { int max; if(a = b) max = a; else max = b; return max; } 3 4-44 数字金字塔 (15 分) void pyramid(int n) { int i, j, space; for(i=1; i = n; i++) { space =

文档评论(0)

1亿VIP精品文档

相关文档