华农C语言题目及答案(完整版)

合集下载

test5华农汇编期末试卷(有答案版)

test5华农汇编期末试卷(有答案版)

TEST5一、简答题1.下面程序段执行后,寄存器BX的值是多少?MOV BX,25PUSH BXMOV CL,4SHL BX,CLPOP AXSUB BX,AXBX的值为3752.对于这样的程序段:CMP AX, BXJAE NEXTXCHG AX, BXNEXT: CMP BX,CXJAE DONEXCHG BX, CXDONE: ┆试回答:①上述程序执行后,原有AX,BX,CX中最小数存放在那个寄存器?CX②这三个数是带符号数还是无符号数?带符号数3. 执行下面的程序段后,AX寄存器的内容是多少?MOV AX,1234HMOV BX,56HMOV CL,8ROL AX,CLADD AX,BXAX的内容为3468H4.有程序段:MOV DL,0A5HMOV AL, DLCBWMOV BL,60HIDIV BL上述程序段运行时,会出现什么结果?存放在什么位置?程序把AX中的有符号数FFA5H除以60H,得到AX=2AH、DX=4H;5. 已知BUF开始的数据区中存放有10个大、小写字母,下面程序段完成的功能是什么?MOV CX,10LEA BX,BUFK2:MOV DL,[BX]CMP DL,5AHJA K3MOV AH,2INT 21HK3: INC BXLOOP K2┇把BUF中的大写字母在屏幕中显示出来二、程序填空题1.下面程序通过堆栈传递参数方法,完成将ary为首地址的count个字数据累加,不考虑溢出,并将结果保存在sum中。

请在标号处填上缺少的一条指令。

prog segmentorg 100hassume cs:prog,ds:prog,es:prog,ss:progmain proc nearmov bx,offset arypush bx___________________ MOV BX,COUNT①push bxmov bx,offset sumpush bxcall proaddint 20hmain endpary dw 123,-54,267,…… ;一系列的数count equ ($-ary)/2sum dw ?proadd proc nearpush bp___________________ MOV BP,SP②push axpush cxpush sipush dimov si,[bp+8]___________________ MOV CX,[BP+6] ③mov di,[bp+4]xor ax,axnext: add ax,[si]___________________ADD SI,2④loop next___________________MOV [DI],AX ⑤pop dipop sipop cxpop axpop bpret 6proadd endpprog endsend main2. 以下.COM结构程序使用冒泡法完成对首地址为ARRAY的一系列有符号数从小到大排序。

华南农业大学《C语言程序设计》 2017(下)C语言试卷(A)及答案

华南农业大学《C语言程序设计》 2017(下)C语言试卷(A)及答案

华南农业大学期末考试试卷(A卷)2017学年第2学期考试科目:C语言程序设计考试类型:(闭卷)考试考试时间:120 分钟学号姓名年级专业考生注意1、本考卷包括试卷和答卷。

一、二大题为客观题,在“机读卡”上答题;三、四大题为主观题,在“答卷”上答题,写在试卷上不得分。

2、必须在机读卡和答卷上正确填写学号、姓名和班级等内容,否则会影响你的考试成绩。

3、机读卡的学生代号区如果只有10位,则只需填写学号后10位。

4、试卷的反面可以打草稿。

考试结束时,“机读卡”、“答卷”和试卷都要上交。

一、判断题(在机读卡上答题,本题共20小题,每小题1分,共20分)请用2B型铅笔涂答题卡,按题号顺序,正确的判断涂黑”A”、错误的判断涂黑”B”1. ASCII码就是汉字机内码。

2. 计算机内存的基本存储单位是比特(Bit)。

3. 程序是动态的,进程是静态的。

4. 使用高级语言编写程序时一般不需要考虑具体的计算机结构。

5. 数据578可能是十进制数,也可能是八进制数。

6. 函数的函数体包括数据说明部分和执行语句部分,两部分不可以交叉出现。

7. C语言程序总是从代码中的第一个函数开始,按顺序执行至最后一个函数。

8. 存放字符序列的字符数组中,最后一个元素必须是字符' \0 '。

9. 函数的实际参数和形式参数可以使用相同的变量名。

10. C语言通常都在main( ) 函数的函数体内对其他函数进行定义。

11. 语句for( i=0 ; i++<10 ; ) ; 执行结束后,变量i的值为10。

12. 所有逻辑运算符的优先级都低于关系运算符。

13. C语言的main( )函数可以任意调用其他函数,但是不能使用其它函数中定义的变量。

14. 带参数的宏无指定类型,其参数也无类型约束。

15. break语句不能单独使用,必须出现在循环语句的循环体内。

16. C语言的输入输出功能既能通过调用标准库函数实现,也能通过输入输出语句实现。

华南农业大学C语言程序设计考卷

华南农业大学C语言程序设计考卷

华南农业大学期末考试试卷( B 卷)第1学期考试科目:程序设计考试类型:(闭卷)考试时间:120 分钟学号姓名年级专业考试须知:1.答案必须写在“答题卡”上,写在试卷上不得分。

2.考试结束时,只回收答题卡,不回收试卷。

3. 必须在答题卡上对旳填写班级、学号、姓名等内容,否则没有考试成绩。

一、单选题(每题2分,共30分)1、下面标记符中,不合法旳顾客标记符为()A) Pad B) a_10 C) _12ab D) int2、调用scanf(“%d,%d”,&a,&b);时,对旳旳键盘输入是()A) 10,20 B) a=10,b=20C) 10:20 D) 10 203、能体现条件0≤x ≤100旳体现式是()A) 0<= x <=100 B. x >=0, x<=100C) 0≤x ≤100 D) x>=0&& x<=1004、设有:int a=1,b=2,c=3,d=4,m=2,n=2;执行(m=a>b) && (n=c>d) 后n旳值为()A) 0 B) 1 C) 2 D) 35、若num、a、b和c都是int型变量,则执行体现式num=(a=4,b=16,c=32);后num旳值为()A) 4 B) 16 C) 32 D) 526、对字符串“Cat”进行完整赋值旳操作是()A) char s[3] = {‘C’,’a’,’t’}; B) char s[] = “Cat”;C) char s[3] = {“Cat”}; D) char s[3]; s= “Cat”;7、如下程序段旳输出成果是()int a=1234;printf(“%2d\n”,a);A) 12 B) 34C) 1234 D) 提示出错、无成果8、设x、y均为整型变量,且x=10,y=3,则如下语句旳输出成果是printf(“%d,%d\n”,x--,--y); ()A)10,3 B)9,3 C)9,2 D)10,29、在Turbo C中,设int a[10];假设数组a开始于内存单元,则a[2]旳存储始于()A) B) C) D)10、在C语言中,引用数组元素时,其数组下标旳数据类型容许是()A)整型常量B)整型体现式C)整型常量或整型体现式D)任何类型旳体现式11、若有int s[4] = {1,2,3,4};,则s[s[0]+2*s[2]-s[3]] 旳值是()A) 1 B) 2 C) 3 D) 412、用数组名作为函数旳实参时,传递给形参旳是()A) 数组旳首地址B) 数组旳第1个元素C) 数组中旳所有元素D) 数组旳元素个数13、如下程序旳输出成果是()main(){ char ch[3][5]={“AAAA”,”BBB”,”CC”};printf(“%s”,ch[1]);}A) “AAAA”B)”BBB”C)”BBBCC”D)”CC”14、有如下程序段int k=0;while(k=1) k++;while循环执行旳次数是()A) 无限次B)有语法错,不能执行C) 一次也不执行D) 执行1次15、设有如下阐明语句struct stu{ int a;float b;} stutype;则下面旳论述不对旳旳是()A)struct是构造体类型旳核心字B)struct stu是顾客定义旳构造体类型C)stutype是顾客定义旳构造体类型名D)a和b都是构造体成员名二、判断题(对旳打“√”,错旳打“×”,每题1分,共10分)1、C程序执行旳入口是main函数,因此main函数必须放在程序旳开头。

2022年华中农业大学公共课《C语言》科目期末试卷B(有答案)

2022年华中农业大学公共课《C语言》科目期末试卷B(有答案)

2022年华中农业大学公共课《C语言》科目期末试卷B(有答案)一、填空题1、为建立如图10-5所示的存储结构(即每个结点两个域,data是数据域,next是指向结点的指针域),请将定义补充完整。

struct s{char data;_______}node;2、C语言源程序文件的后缀是;经过编译后,生成文件的后缀是;经过连接后,生成文件的后缀是3、结构化程序由________、________ 、________ 3种基本结构组成。

4、C语言所提供的基本数据类型包括:单精度型、双精度型、_______、_______和_______。

5、若有定义语句:inte=1,f=4,g=2;float m=10.5,n=4.0,k;,则执行表达式k=(e+f)/g+sqrt((double)n)*1.2/g+m后k的值是_______。

6、设有char a,b;若要通过a&b运算屏蔽掉a中的其他位,只保留第2和第8位(右起为第1位),则b的二进制数是_______。

7、函数swap(arr,n)可对arr数组从第1个元素到第n个元素分别进行两两元素交换。

在运行调用函数中的如下语句后,a[o]和a[1]的值分别为_______,原因是_______。

a[0]=1;a[1]=2;swap(a,2);8、设有如下定义:#define SWAP(T,X,Y){T=X;X=Y;Y=T;}以下程序段将通过调用宏实现变量x和y内容的交换,请填空。

Double x=2.5,y=6.4,z;SWAP(_______);9、设有宏定义如下:#define MIN(x,y)(x)>(y)?(x):(y)#define T(x,y,r)x*r*y/4则执行以下语句后,s1的值为_______,s2的值为_______。

int a=1,b=3,c=5,s1,s2;s1=MIN(a=b,b-a);s2=T(a++,a*++b,a+b+c);10、下面程序段的运行结果是_______。

test9华农汇编期末试卷(有答案版)

test9华农汇编期末试卷(有答案版)

一、阅读程序1.仔细阅读下面程序,说明该程序的功能。

CODE SEGMENTORG 100HASSUME CS:CODE,DS:DATA,ES:CODE,SS:CODE SORT PROC NEARMOV CX,NDEC CXLOOP1:PUSH CXMOV BX,0LOOP2:MOV AX,ARRAY[BX]CMP AX,ARRAY[BX+2]JLE CONTINUEXCHG AX,ARRAY[BX+2]MOV ARRAY[BX],AXCONTINUE:ADD BX,2LOOP LOOP2POP CXLOOP LOOP1MOV AH,4CHINT 21HARRAY DW 2,-9,8,0,12,16,1,-10,18,11N DW ($-ARRAY)/2SORT ENDPCODE ENDSEND SORT程序功能:把ARRAY中的数从小到大排序2.仔细阅读下面程序,说明该程序的功能。

DATA SEGMENTBUFF DB 128,?,128 DUP(?)CRLF DB 0DH,0AH,24HDATA ENDSSTACK SEGMENT STACKDW 100H DUP(?)TOP LABEL WORDSTACK ENDSCODE SEGMENTASSUME CS:CODE,DS:DATA,ES:DATA,SS:DATA MAIN PROC FARMOV AX,STACKMOV SS,AXLEA SP,TOPPUSH DSXOR AX,AXPUSH AXMOV AX,DATAMOV DS,AXLEA DX,BUFFMOV AH,0AHINT 21HMOV AH,9LEA DX,CRLFINT 21HLEA SI,BUFFINC SIMOV CL,[SI]XOR CH,CHADD SI,CXSTDNEXT: LODSBMOV DL,ALMOV AH,2INT 21HLOOP NEXTRETMAIN ENDPCODE ENDSEND MAIN程序功能:从键盘输入一段字符串,然后再下一行逆序输出3. 仔细阅读下面程序,说明该程序的功能。

华南农业大学c语言上机考试题目

华南农业大学c语言上机考试题目

1打印数字空心菱形Time Limit:1000MS Memory Limit:65536K题型: 编程题语言: 无限制描述由键盘输入n(n为奇数),打印如下图空心菱形例n=712 23 34 43 32 21输入格式整数输出格式如题输入样例3输出样例12 21作者Admin答案:#include <stdio.h>#include <math.h>int main(){int n,i,j;scanf("%d",&n);n/=2;for(i=-n;i<=n;++i){for(j=0;j<2*n+1-abs(i);++j){if(j==abs(i)||j==2*n-abs(i)){printf("%d",n-abs(i)+1);}else{printf("\040");}}printf("\n");}return 0;}2两数和为1909Time Limit:1000MS Memory Limit:65536K题型: 编程题语言: 无限制描述由键盘输入10个整数,编程判断是否存在两个数的和为1909,存在输出Y,不存在输出N输入格式10个整数,由空格分隔输出格式Y或者N输入样例2 1900 42 3123 31 23 343 213 34 9输出样例Y提示作者Admin#include<stdio.h>#include<stdlib.h>main(){int a[10];int i,j;int flag = 0;printf("input ten numbers:\n");for(i=0;i<10;i++)scanf("%d",&a[i]);for(i=0;i<10;i++){for(j=0;j<10;j++)if(a[j] + a[i] == 1909 && i!=j){flag = 1;break;}}if(flag) printf("Y\n");else printf("N\n");system("pause");}3回文串的判断Time Limit:1000MS Memory Limit:65536K题型: 编程题语言: 无限制描述回文串是指一个字符串从左读到右与从右读到左是一样的,现由键盘输入一行字符(最多不超过80个字符,以回车结束),判断能否通过去掉0个或1个字符,使得字符串成为回文串,如果可以输出Y,否则输出N输入格式一行字符输出格式Y或N输入样例abca输出样例Y提示提示,去掉c字符,即可成为回文串作者Admin#include "stdio.h"#include "string.h"int main(){int n;char a[100]="abca";int i,j,flag;n=strlen(a);i=0;j=n-1;flag=0; // characters qty need insertedwhile ( (flag<2) // only need 0 or 1 character&& ((i+1)<=(j-1)) // have character to compare){if (a[i]==a[j]) {i++; j--;}else if (a[i]==a[j-1]) {flag++; i++; j-=2;}else if (a[i+1]==a[j]) {flag++; i+=2; j--;}else flag=2;}if (flag<2) printf("Y");else printf("N");return 0;}二:#include<stdio.h>#include<conio.h>#define SIZE 20int isPalindrome(char []); /* Prototype only send the number and type of arguments to the Compiler. */main(){ /*Local Declarations*/char str[SIZE];/*Statements*/printf("请输入字符串,以回车结束:\n");scanf("%s",str); /*Record the string.*/if(isPalindrome(str)==0) /*The string is not a palindrome.*/ { printf("The string is not a palindrome.\n"); }else /*The string is a palindrome.*/{ printf("The string is a palindrome.\n"); }system("pause");return 0;}三:#include<stdio.h>#include<string.h>void main(){char str[20],copy[20];char temp;char *head,*tail;printf("Please input a string:\n");gets(str);strcpy(copy,str);head=str;tail=str+strlen(str)-1;while(head<tail){temp=*head;*head++=*tail;*tail--=temp;}if(strcmp(copy,str)==0)printf("该字符串为回文。

华农-2015学年第1学期C语言A卷参考答案

华农-2015学年第1学期C语言A卷参考答案

C参考答案2015学年第1学期考试科目:C语言程序设计一、单项选择题(机读,每小题2分,共40分)二、判断题(机读,正确的判断涂黑“A”、错误的判断涂黑“B”每小题1分,共20分)三、阅读程序填空题(每空1分,共20分)四、编写程序题(每小题各10分,共20分)1.#include <stdio.h>#include <string.h>int main(){ char str1[80],str2[80],str3[80],temp[80];int i;printf("Input 3 Strings:\n");gets(str1); //输入3个字符串gets(str2);gets(str3);if(strcmp(str1, str2) > 0) //如果str[0]>str[1], 交换它们的值 { strcpy(temp, str1);strcpy(str1, str2);strcpy(str2, temp);}if(strcmp(str1, str3) > 0) //如果str[0]>str[2], 交换它们的值 { strcpy(temp, str1);strcpy(str1, str3);strcpy(str3, temp);}if(strcmp(str2, str3) > 0) //如果str[1]>str[2], 交换它们的值 { strcpy(temp, str2);strcpy(str2, str3);strcpy(str3, temp);}printf("After sorted: \n");puts(str1); //输出排序后的3个字符串puts(str2);puts(str3);return 0;}2.#include <stdio.h>#include <math.h>main(){ int i,temp,rmd,sum;for(i=100; i<=999; i++){ temp=i; sum=0;while(temp>0){ rmd=temp%10;sum+=pow(rmd,3); //此处若不会使用pow函数,可以用连乘替代。

华农C语言教材习题答案

华农C语言教材习题答案

注:答案仅供参考分期还款:#include <stdio.h>#include <math.h>int main(){double d, p,r;scanf("%lf%lf%lf",&d,&p,&r);printf("%.1f", log10(p/(p-d*r))/log10(1+r));return 0;}计算分段函数函数值:#include <stdio.h>int main(){double x;scanf("%lf",&x);if(x<1) printf("%.2f", x);else if(x>=1 && x<10) printf("%.2f", 2*x-1);else printf("%.2f", 3*x-11);}成绩等级评分:#include <stdio.h>#include <math.h>int main(){int score;scanf("%d", &score);if(score>100 || score<0)printf("error");else if(score>=90)printf("A");else if(score>=80)printf("B");else if(score>=70)printf("C");else if(score>=60)printf("D");elseprintf("E");return 0;}20秒后时间:#include <stdio.h>#include <stdlib.h>int main(){int h,m,s;scanf("%d:%d:%d", &h,&m,&s);s=s+20;if(s>59){s=s%60;m++;if(m>59){m=m%60;h++;if(h>23)h=0;}}printf("%02d:%02d:%02d\n", h, m, s);return 0;}分期还款(加强版):#include <stdio.h>#include <math.h>int main(){double d, p,r;scanf("%lf%lf%lf",&d,&p,&r);if(d==0)printf("0.0\n");else if(d*(1+r)-p>d)printf("God\n");else{printf("%.1f", log10(p/(p-d*r))/log10(1+r));}return 0;}字母分类统计:#include <stdio.h>#include <math.h>int main(){char ch;int nL=0, nN=0, nS=0, nO=0;while((ch=getchar())!='\n'){if(ch>='a'&&ch<='z'||ch>='A'&&ch<='Z')nL++;else if (ch>='0'&&ch<='9')nN++;else if (ch==' ')nS++;elsenO++;}printf("%d %d %d %d\n", nL, nN, nS, nO);return 0;}计算数列和:#include<stdio.h>main(){ int i,n;double a=2,b=1,s=0;scanf("%d",&n);for(i=1;i<=n;i++){ s=s+a/b;a=a+b;b=a-b;}printf("%.4f\n",s);}自由落体:#include <stdio.h>#include <math.h>int main(){double sum=-100, d=100;int i,n;scanf("%d", &n);for(i=1; i<=n; i++){sum+=2*d;d/=2;}printf("%.3f %.3f", sum, d);return 0;}迭代法求平方根:#include <stdio.h>#include <math.h>int main(){double a, x0, x1=1;scanf("%lf", &a);do{x0=x1;x1=1.0/2*(x1+a/x1);}while(fabs(x1-x0)>=1e-5);printf("%.4lf\n", x1);return 0;}打印三角形:#include <stdio.h>#define abs(x) ((x)>=0?(x):-(x))int main(){int n,i,j;scanf("%d", &n);for(i=-(n-1); i<=(n-1); i++){for(j=0; j<abs(i); j++)printf(" ");for(j=0; j<n-abs(i); j++)printf("*");printf("\n");}return 0;}勾股数:#include <stdio.h>#include <math.h>int main(){int i,j,k,n;scanf("%d", &n);for(i=1; i<=n; i++)for(j=i; j<=n; j++){k=(int)sqrt(i*i+j*j);if(k*k==i*i+j*j && k<=n)printf("%d %d %d\n", i,j,k);}return 0;}插入数据:int n,i;scanf("%d", &n);for(i=14; i>=0; i--)if(a[i]>n) a[i+1]=a[i];else break;a[i+1]=n;输出不同的数:#include"stdio.h"main(){ int a[20];int i,t,p=0;for(i=0;i<10;i++){ scanf("%d",&a[i]);for(t=0;t<i;t++)if(a[t]==a[i])break;if(t==i)printf("%d\n", a[i]);}}鞍点:#include <stdio.h>#include <stdlib.h>int main(){int i,j,a[3][4],flag=0,col,r;for(i=0;i<3;i++)for(j=0;j<4;j++)scanf("%d",&a[i][j]);for(i=0;i<3;i++){col=0;for(j=1;j<4;j++)if(a[i][j]>a[i][col]) col=j;for(j=0;j<4;j++){if(a[i][j]==a[i][col]){for(r=0;r<3;r++)if(a[r][j]<a[i][j]) break;if(r==3){printf("%d\n", a[i][j]);flag=1;}}}}if(!flag)printf("NO\n");return 0;}回文串:#include "stdio.h"#include "string.h"main(){ int i, j;char buf[100];scanf("%s",buf);for(i=0, j=strlen(buf)-1;i<j; i++, j--)if(buf[i]!=buf[j]) break;if(i>=j)printf("Y");elseprintf("N");}ASCII码值之和的差:#include <stdio.h>int sum(char *s){int t=0,i=0;while(s[i]!='\0')t+=s[i++];return t;}int main(){char s1[81],s2[82];gets(s1);gets(s2);printf("%d", sum(s1)-sum(s2));return 0;}所有数字之和:#include "stdio.h"int sum(int n){int ret=0;while(n>0){ret+=n%10;n/=10;}return ret;}main(){int n;scanf("%d", &n);printf("%d", sum(n));}元音字母:#include "stdio.h"void yuan(char *s,char *s2){while(*s!='\0'){if(*s=='a' ||*s=='o' ||*s=='e' ||*s=='i' ||*s=='u' || *s=='A' ||*s=='O' ||*s=='E' ||*s=='I' ||*s=='U'){*s2=*s; s2++;}s++;}*s2='\0';}main(){char str[81], str2[81];gets(str);yuan(str,str2);printf("%s", str2);}字符统计:#include <stdio.h>#include <string.h>#include <math.h>int nL=0, nN=0;int statistics(char *s){int ret=0;while(*s!='\0'){if(*s>='a'&&*s<='z'||*s>='A'&&*s<='Z')nL++;else if (*s>='0'&&*s<='9')nN++;else if (*s==' ')ret++;s++;}return ret;}int main(){char s[81];int nS;gets(s);nS = statistics(s);printf("%d %d %d\n", nL, nN, nS);return 0;}选择排序:#include <stdio.h>int sort(int a[], int n){int i,j,k,tmp;for(i=0;i<n-1; i++){k=i;for(j=i+1; j<n; j++)if(a[k]>a[j]) k=j;tmp=a[k];a[k]=a[i];a[i]=tmp;}}int main(){int a[10];int i;for(i=0; i<10; i++) scanf("%d", &a[i]);sort(a,10);for(i=0; i<10; i++) printf("%d\n", a[i]);return 0;}x的n次方:#include <stdio.h>int F(int x, int n){if(n==1) return x;else return F(x, n-1)*x;}int main(){int x, n;scanf("%d%d", &x, &n);printf("%d", F(x, n));return 0;}行列互换:#include <stdio.h>void s *a, int *b){int temp;temp=*a;*a=*b;*b=temp;}void col(int a[][4], int i, int j){int k;for(k=0; k<4; k++)s[k][i], &a[k][j]);}void row(int a[][4], int i, int j){int k;for(k=0; k<4; k++)s[i][k], &a[j][k]);}int main(){int a[4][4];int i,j;for(i=0; i<4; i++)for(j=0; j<4; j++)scanf("%d", &a[i][j]);col(a,0,2);row(a,0,2);col(a,1,3);row(a,1,3);col(a,0,3);row(a,0,3);for(i=0; i<4; i++){for(j=0; j<4; j++)printf("%d ", a[i][j]);printf("\n");}return 0;}学生信息统计:#include <stdio.h>void average(double a[][5], int n) {int i,j;double sum;for(i=0; i<n; i++){sum=0;for(j=0; j<5; j++)sum+=a[i][j];printf("%.2f ", sum/5);}printf("\n");}void average2(double a[][5], int n){int i,j;double sum;for(j=0; j<5; j++){sum=0;for(i=0; i<n; i++)sum+=a[i][j];printf("%.2f ", sum/n);}printf("\n");}void top(double a[][5], int n){int i,j; double max;for(j=0; j<5; j++){max=a[0][j];for(i=1; i<n; i++)if(a[i][j]>max) max = a[i][j];printf("%.2f ", max);}printf("\n");}int main(){double a[10][5];int i, j;for(i=0; i<10; i++)for(j=0; j<5; j++)scanf("%lf", &a[i][j]);average(a,10);average2(a,10);top(a,10);return 0;}一年的第几天:#include <stdio.h>struct DATE{int year;int month;int day;};int days(struct DATE date){int day,sum;if(date.year%4==0&&date.year%100!=0||date.year%400==0) {day=29;}else{day=28;};switch(date.month){case 1:sum=0;break;case 2:sum=31;break;case 3:sum=31+day;break;case 4:sum=62+day;break;case 5:sum=92+day;break;case 6:sum=123+day;break;case 7:sum=153+day;break;case 8:sum=184+day;break;case 9:sum=215+day;break;case 10:sum=245+day;break;case 11:sum=276+day;break;case 12:sum=306+day;break;};return(sum+date.day);}int main(){struct DATE d;scanf("%d-%d-%d", &d.year, &d.month, &d.day);printf("%d", days(d));}学生成绩表:#include <stdio.h>struct data{int num;char name[20];double score[3];double average;};int main(){int i,j;struct data stu[10],tmp;for(i=0; i<10; i++){scanf("%d%s%lf%lf%lf", &stu[i].num, stu[i].name, stu[i].score, stu[i].score+1, stu[i].score+2);stu[i].average=stu[i].score[0]+stu[i].score[1]+stu[i].score[2]; } for(i=0; i<9; i++)for(j=0; j<9-i; j++){if(stu[j].average<stu[j+1].average){tmp=stu[j];stu[j]=stu[j+1];stu[j+1]=tmp;} }for(i=0; i<10; i++){printf("%d %s %.0lf %.0lf %.0lf\n", stu[i].num, stu[i].name, stu[i].score[0], stu[i].score[1], stu[i].score[2]);}return 0;}。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
int main()
{
printf("The first C Program\n");
return 0;
}
[题目1001:计算a+b]
由键盘输入两个整数,计算并输出两个整数的和。
答案
#include <stdio.h>
#include <stdlib.h>
int main()
{int a,b;
scanf ("%d%d",&a,&b);
#include <stdlib.h>
int main()
{int a,b;
scanf("%d%d",&a,&b);
printf ("%d",a+b);
}
[题目1014:求圆面积]
由键盘输入圆半径r,请计算该圆的面积。(注:π取3.14159,结果保留两位小数位;另外,程序只要能对r在0到10000范围的情况输出正确答案即可)
f=d/10;
printf("%d,%d,%d,%f,%f,%f", a,b,c,d,e,f);
}
答案
$line1$
0,2,1,15.000000,1.000000,1.500000
[题目1118:赋值表达式与赋值语句,写出程序运行结果]
阅读下面程序,写出运行结果:
#include "stdio.h"
{
printf("C:\\ABC.TXT\n");
return 0;
}
[题目1119:基本运算,写出程序运行结果]
阅读下面程序,写出运行结果:
#include "stdio.h"
main()
{ int a, b, c;
float d=15, e, f;
a=35%7;
b=15/10;
c=b++;
e=15/10;
{if(x>y)return x;
else return y;
}
int main()
{int a,b;
scanf("%d%d",&a,&b);
printf("%d\n",max(a,b));
}
[题目1117:变量定义,按要求完成程序]
下面给出一个可以运行的程序,但是缺少部分语句,请按右边的提示补充完整缺少的语句。
答案
#include <stdio.h>
#include <stdlib.h>
#define PI 3.1415926
int main()
{float r,area;
scanf("%f",&r);
area=PI*r*r;
printf("%6.2f",area);
getchar();
}
[题目1015:计算摄氏温度值]
答案
#include <stdio.h>
#include <stdlib.h>
int main()
{int a;
scanf("%c",&a);
printf ("%c",a);
}
[题目1127:计算加法]
编程实现由键盘输入一个加法式,输出正确的结果。
(两个加数均为整数)
答案
#include <stdio.h>
int a,b;
$line2$
float i,j;
[题目6568:在显示屏上显示指定字符]
要求编写一个程序,在显示屏上显示如下内容(全为半角字符,且不包括空格):C:\ABC.TXT
[提示]
注意转义字符在程序中的使用。
答案
#include <stdio.h>
#include <stdlib.h>
int main()
int main()
{float a;
int b, c;
char d, e;
a=3.5;
b=a;
c=330;
d=c;
e='\141;
printf("%f,%d,%d,%c,%c", a,b,c,d,e);
}
答案
$line1$
3.500000,3,330,J,a
[题目1126:字符的输入与输出]
编程实现由键盘输入一个字符后,在屏幕上输出该字符。
if(a>b)
{t=a;
a=b;
b=t;
}
if(a>c)
{t=a;
a=c;
c=t;
}
if(b>c)
{t=b;
b=c;
c=t;
}
printf("%d,%d,%d",a,b,c);
return 0;
}
[题目1016:字符变换]
由键盘输入5个字符,将其中的大写字母变成小写,其它类型的字符不变,并按输入顺序逐个输出。
#include "stdio.h"
main()
{ int a, b; /*定义整型变量a和b*/
int i, j; /*定义实型变量i和j*/
a=5;
b=6;
i=3.14; j=i*a*b;
printf("a=%d,b=%d,i=%f,j=%f\n", a, b, i, j);
}
答案
$line1$
printf("%d\n%d",b,c);
}
[题目1018:数的排序]
由键盘输入三个整数a、b、c,按从小到大的顺序输出这三个数。
答案
#include <stdio.h>
#include <stdlib.h>
int main()
{int a,b,c,t;
scanf("%d,%d,%d",&a,&b,&c);
getchar();
}
[题目11127:各个数字]
从键盘输入一个3位数的正整数,要求先后输出该数字的百位数字与个位数字,各占一行。
答案
#include <stdio.h>
#include <stdlib.h>
int main()
{int a,b,c;
scanf("%d",&a);
b=a/100%10;c=a%10;
printf("%d",a+b);
return 0;
}
[题目11126:输出a与b中的较大值]
下面程序实现由键盘输入两个整数a和b,判断并输出a与b中较大值。请在计算机上执行并验证该程序的正确性,之后提交到在线评判系统。
答案
#include <stdio.h>
#include <stdlib.h>
int max(int x,int y)
[题目6567:The first C Program]
将下列程序输入
visual c++
,编译、连接和运行该程序。
#include"stdio.h"
main()
{
printf("The first C Program\n");
}
答案
#include <stdio.h>
#include <stdlib.h>
从键盘输入一个华氏温度值,要求按格式输出其对应的摄氏温度值,精确到小数点后两位。
数学公式描述为:C=5*(F-32)/9
答案
#include <stdio.h>
#include <F,C;
scanf("%f",&F);
C=(F-32)*5/9;
printf("%.2f",C);
相关文档
最新文档