C语言设计经典英文练习题_第1页
C语言设计经典英文练习题_第2页
C语言设计经典英文练习题_第3页
C语言设计经典英文练习题_第4页
C语言设计经典英文练习题_第5页
已阅读5页,还剩7页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、.C PracticePrint 9*9 multiplication table? 1*1=1? 1*2=2 2*2=4? 1*3=3 2*3=6 3*3=9? 1*4=4,2*4=8,3*4=12 4*4=16? ? 1*9=9, .9*9=81#includeint main(void)int x,y,z;for(x=1;x=9;x+)for(y=1;y=x;y+)z=x*y;printf(%d*%d=%d,y,x,z);printf(n);Calculate 1+2!+3!+ 20!#includeint main ()int i;long long sum = 0, jc=1;for

2、 (i = 1; i = 20; +i)jc *= i;sum += jc;printf (%dn, sum);return 0;.Input x and print y Y=2X,X0;Y=4X-2,0=X=10#include int main()float x,y;printf(Please input X:);scanf(%f,&x);if(x0)y=2*x;else if(x10)y=4*x-2;elsey=6*x*(x+3);printf(Y=%fn,y);Input a string from keyboard, write a program to calculate the

3、number of alpha, digit space and other character.#includeint main()char str100;int i=0;int num=0,ch=0,blank=0,other=0;gets(str);while(stri!=0)if(stri=A & stri=a & stri=0 & stri=9)num+;else if(stri= )blank+;elseother+;i+;printf( 数字 %d 个,字母 %d 个,空格 %d 个,其他 %d 个n,num,ch,blank,other); return 0;.Read 5 i

4、nteger from keyboard to sort in descending order#includeint main()int a5=0;int i,j,t;printf( 请依次输入 5 个整数 n);for(i=0;i5;i+)/ 输入 5 个数scanf(%d,&ai);for(i=0;i5;i+)/ 从大到小排序for(j=i+1;j5;j+)if(aiaj)t=ai;ai=aj;aj=t;for(i=0;i2),write a function to generate and print first n Fibonacci numbers.#include #includ

5、e int main()int a=1,b=1,sum;int n,i;scanf(%d,&n);printf(%dn%dn,a,b);for (i=3;i=n;)sum=a+b;b=a;a=sum;if(i%1=0)printf(%dn,sum);i+;return 0;.Write a program to produce the alphabet set A to Z and then saved it into a file.#include#includeint main()FILE *fp;char ch, 10;printf( 输入文件名: n);scanf(%s, );if (

6、fp = fopen(, w) = NULL)printf(errorn);exit(0);for (ch = A; ch = A&ch = Z; ch+)fputc(ch, fp);putchar(ch);fclose(fp);putchar(10);return 0;Read a series of character from keyboard and write it to file, read to display it on screen.#include#includeint main()FILE *fp;char ch, 10;printf( 输入文件名: n);scanf(%

7、s, );if (fp = fopen(, w) = NULL)printf(errorn);exit(0);ch = getchar();.printf( 输入一行字符回车结束:n);while(ch=getchar()!=n)fputc(ch, fp);putchar(ch);fclose(fp);putchar(10);printf( 输入文件名: n);scanf(%s, );if (fp = fopen(e, r) = NULL)printf(errorn);exit(0);char a;if (fp = fopen(, r) = NULL)printf(errorn);exit(0

8、);while (!feof(fp)a = fgetc(fp);putchar(a);fclose(fp);return 0;Input one string from keyboard and use pointer to calculate to length of string#include#includeint main()char a20;char *p=a;scanf(%s, a);int i=0;while (*p != 0).p+;i+;printf(%dn, i);return 0;Give one strings and use pointer to copy this

9、string to another.#includeint main()char a20, b20;char *from=a, *to=b;scanf(%s, a);for(;*from != 0;)*to = *from;from+, to+;*to = 0;printf(%s, b);return 0;Write 1 to 20 to a file, read it and put the sum of these number at the end of file.#include#includeint main()FILE *f;int b20, j, sum = 0;for (j =

10、 0; j 20; j+)bj = j + 1;sum = sum + bj;char a10;printf( 输入文件名 :n);scanf(%s, a);if (f = fopen(a, w) = NULL).printf(error);exit(0);for (j = 0; j 20; j+)fprintf(f, %d , bj);fprintf(f, %d, sum);fclose(f);return 0;Use malloc() function to allocate 10 int units to 10 numbers and print it from 6th number u

11、sing pointer.#include#include#define len sizeof(int)int main()int *p10;int a10, i;for (i = 0; i 10; i+)scanf(%d, &ai);for (i = 0; i 10; i+)pi = (int *)malloc(len);*pi = ai;for (i = 5; i 10; i+)printf(%d , *pi);return 0;Write a function with two integer number arguments and two pointer arguments to c

12、alculate two number sum and difference, return the sum and difference with two pointers to calling function.#includeint main().int f(int *p1, int *p2);int g(int *p1, int *p2);int a, b;int *p1, *p2;p1 = &a, p2 = &b;scanf(%d %d, &a, &b);printf(%dn%d, f(p1, p2), g(p1, p2);return 0;int f(int *p1, int *p

13、2)int sum;sum = *p1 + *p2;return sum;int g(int *p1, int *p2)int dif;dif = *p1 - *p2;return dif;Using pointer to read an array of integer and print its elements in reverse order#include int main()int n, c, d, a100, b100;printf(Enter the number of elements in arrayn);scanf(%d, &n);printf(Enter the arr

14、ay elementsn);for (c = 0; c = 0; c-, d+)bd = ac;for (c = 0; c n; c+)ac = bc;printf(Reverse array isn);for (c = 0; c n; c+)printf(%dn, ac);return 0;.运算符与表达式:1.constant 常量2. variable 变量3. identify 标识符4. keywords 关键字5. sign 符号6. operator 运算符7. statement 语句8. syntax 语法9. expression 表达式10. initialition 初

15、始化11. number format 数据格式12 declaration 说明13. type conversion 类型转换14.define 、definition定义条件语句:1.select 选择2. expression 表达式3. logical expression 逻辑表达式4. Relational expression 关系表达式 5.priority 优先6. operation 运算7.structure 结构循环语句:1.circle 循环2. condition 条件3. variant 变量4. process过程 5.priority 优先6. operat

16、ion 运算数组:1. array 数组2. reference 引用3. element 元素4. address 地址5. sort 排序6. character 字符7. string 字符串8. application 应用函数:1.call 调用2.return value 返回值3.function函数4. declare 声明.5. parameter 参数 6.static 静态的7.extern 外部的指针:1. pointer 指针2. argument 参数3. array 数组4. declaration 声明5. represent 表示6. manipulate 处

17、理结构体、共用体、链表:1 structure 结构2 member 成员3 tag 标记4 function 函数5 enumerate 枚举6 union 联合(共用体)7 create 创建8 insert 插入9 delete 删除10 modify 修改文件:1、file 文件2、open 打开3、close 关闭4、read 读5、write写6、error 错误序号 主要章节常用英汉对照词汇备注1 运算符与表达式( operator and expression ) 汉语 英语常量 constant变量 variable标识符identify关键字keywords符号 sign运

18、算符operator语句 statement语法 syntax表达式Expression初始化Initialization数据格式number format说明 Declaration.类型转换type conversion定义 Define 、 definition2 条件语句( conditionstatement) 选择 select表达式expression逻辑表达式logical expression关系表达式Relational expression优先 priority运算 operation结构 structure3 循环语句(circle statement) 循环circle条件 condition变量 variant过程 process优先 priority运算 operation4 函数(function) 调用call返回值return value函数 function声明 declare参数 parameter静态的static外部的extern5 数组和指针(array andpointer) 数组 array 引用 reference元素 element 地址 address 排序 sort

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论