C语言读程序写结果练习题
更新时间:2023-07-28 01:00:01 阅读量: 实用文档 文档下载
C语言读程序写结果练习题
读程序写结果
一、数组
1. #include <stdio.h>
void main()
{
}
2. #include <stdio.h>
void main()
{
float b[6]={1.1,2.2,3.3,4.4,5.5,6.6},t; int i;
t=b[0];
for(i=0;i<5;i++)
b[i]=b[i+1];
b[5]=t;
for(i=0;i<6;i++)
printf(“%6.2f”,b[i]); }
void main()
{ int p[7]={11,13,14,15,16,17,18},i=0,k=0;
while(i<7 && p[i]%2)
{ k=k+p[i]; i++;}
printf("k=%d\n",k);
}
4. void main()
{int a[3][3]={1,3,5,7,9,11,13,15,17}; int sum=0,i,j;
for (i=0;i<3;i++)
for (j=0;j<3;j++)
{a[i][j]=i+j; int a[8]={1,0,1,0,1,0,1,0},i; for(i=2;i<8;i++) a[i]+= a[i-1] + a[i-2]; printf(“%5d”,a[i]); for(i=0;i<8;i++) 3. #include <stdio.h>
C语言读程序写结果练习题
if (i==j)
sum=sum+a[i][j];
}
printf("sum=%d",sum);
}
5. void main()
{int a[4][4],i,j,k;
for (i=0;i<4;i++)
for (j=0;j<4;j++)
a[i][j]=i-j;
for (i=0;i<4;i++)
{ for (j=0;j<=i;j++)
printf("%4d",a[i][j]);
printf("\n");
}
}
6. #include <stdio.h>
main()
{inti,s;
char s1[100],s2[100];
printf("input string1:\n");gets(s1); printf("input string2:\n");gets(s2); i=0;
while ((s1[i]==s2[i])&&(s1[i]!='\0')) i++;
if ((s1[i]=='\0')&&(s2[i]=='\0')) s=0; else s=s1[i]-s2[i];
printf("%d\n",s);
}
输入数据 aid
and
7. void main()
{
} charch[3][5]={ "AAAA","BBB","CC"}; printf("\"%s\"\n",ch[1]);
C语言读程序写结果练习题
1. 1 0 2 2 5 7 13 20
2. 2.20 3.30 4.40 5.50 6.60 1.10
3. k=24
4. sum=6
5.
1 0
2 1 0
3 2 1 0
6. -5
7. “BBB”
二、指针
1、
charcchar(char ch) { if (ch>=‘A’&&ch<=‘Z')
ch=ch-‘A'+‘a';
returnch; } voidmain() { char s[]="ABC+abc=defDEF",*p=s; while(*p) { *p=cchar(*p); p++; } printf("%s\n",s); }
2、
voidmain() {int a[5]={2,4,6,8,10},*p,* *k; p=a; k=&p; printf("%d",*(p++)); printf("%d\n",* *k); }
3、
funa(inta,int b ) { return a+b;} funb(inta,int b ) { return a-b;} sub(int(*t)(),intx,int y )
C语言读程序写结果练习题
voidmain() { int x ,(*p)(); p=funa; x=sub(p,9,3); x+=sub(funb,8,3); printf("%d\n",x); }
4、
voidmain() { char *s="12134211";
int v[4]={0,0,0,0} ;
intk,i; for(k=0;s[k];k++) { switch(s[k]) { case '1':i=0; case '2':i=1; case '3':i=2; case '4':i=3; } v[i]++; } for(k=0;k<4;k++)printf("%d",v[k]); }
5、# include "ctype.h"
void space(char *str) { int i ,t ; charts[81]; for(i=0,t=0 ;str[i]!='\0' ;i+=2) if(! isspace(*(str+i))&&(*(str+i)!='a')) ts[t++]=toupper(str[i]); ts[t]='\0' ;strcpy(str,ts); } voidmain() { char s[81]={"abcdefg"} ;
C语言读程序写结果练习题
}
6、
#include<stdio.h> sub1(char a ,char b) { char c ; c=a ;a=b ;b=c ;} sub2(char * a ,char b) { char c ; c=*a ;*a=b ;b=c ;} sub3(char * a ,char *b){ char c ; c=*a ;*a=*b ;*b=c ;} voidmain() { char a ,b ; a='A' ;b='B' ;sub3(&a ,&b); putchar(a);putchar(b); a='A' ;b='B' ;sub2(&a ,b); putchar(a);putchar(b); a='A' ;b='B' ;sub1(a ,b); putchar(a);putchar(b); }
7、
8、
voidprtv(int * x) {printf("%d\n",++*x); } voidmain() { int a=25 ;prtv(&a); } voidmain() { char b[ ]="ABCDEFG"; char *chp=&b[7]; while(--chp>&b[0]) putchar(*chp); putchar('\n'); }
9、
intaa[3][3]={{2},{4},{6}}; voidmain() { int i ,*p=&aa[0][0];
C语言读程序写结果练习题
{ if(i==1)aa[i][i+1]=*p+1; else ++p; printf("%d",*p); } }
10、
1、abc+abc=defdef 2、24
3、17
4、0008
5、CEG
6、BABBAB
7、GFEDCB 8、26 9、00
10、120 intf(int b[ ],int n) { int i ,r=1; for(i=0;i<=n;i++) r=r*b[i]; return r; } voidmain() { intx,a[]={2,3,4,5,6,7,8,9}; x=f(a,3); printf("%d\n",x); }
三、结构体 1、
#include <stdio.h> structabc { int a, b, c; }; main() { structabc s[2]={{1,2,3},{4,5,6}}; int t;
C语言读程序写结果练习题
2、
3、
4、
5、
printf("%d \n",t); } #include <stdio.h> structstu { intnum;char name[10];int age;}; void fun(structstu *p) { printf("%s\n" ,(*p).name); } voidmain() { structstu students[3]={{9801,"Zhang",20} ,{9802,"Wang", 19} , {9803,"Zhao",18} }; fun(students+2); } #include <stdio.h> voidmain() { enum team { my ,your=4 ,his ,her=his+10}; printf("%d%d%d%d\n",my,your,his,her); } #include <stdio.h> structst { intx;int *y;} *p ; intdt[4]={10,20,30,40}; structstaa[4]={50,&dt[0],60,&dt[1],70,&dt[2],80,&dt[3] }; void main() { p=aa; printf("%d, ", ++p->x); printf("%d, ",(++p)->x); printf("%d\n",++(*p->y)); } #include <stdio.h> unionmyun {struct
C语言读程序写结果练习题
6、
7、
8、 int k; } a; voidmain() { a.u.x=4; a.u.y=5; a.u.z=6; a.k=0; printf("%d\n",a.u.x); } #include <stdio.h> struct STU { charnum[10]; float score[3]; }; voidmain() { structSTU s[3]={{“20021”,90,95,85},{“20022”,95,80,75}, {“20023”,100,95,90}},*p=s; int i; float sum=0; for(i=0;i<3;i++) sum=sum+p->score[i]; printf(“%6.2f\n”,sum); } #include <stdio.h> #include <stdlib.h> struct NODE { intnum; struct NODE *next; }; voidmain() { struct NODE *p,*q,*r; p=(struct NODE*)malloc(sizeof(struct NODE)); q=(struct NODE*)malloc(sizeof(struct NODE)); r=(struct NODE*)malloc(sizeof(struct NODE)); p->num=10; q->num=20; r->num=30; p->next=q;q->next=r; printf(“%d\n”,p->num+q->next->num); }
C语言读程序写结果练习题
typedef union student { char name[10]; longsno; char sex; float score[4]; }STU; voidmain() { STU a[5]; printf(“%d\n”,sizeof(a)); }
1、 6
2、 Zhao
3、 04515
4、 51, 60, 21
5、 0
6、 270.00
7、 40
8、 80
正在阅读:
C语言读程序写结果练习题07-28
企业所得税汇算清缴纳税调整事项归纳07-31
2015年高考作文实用素材分类整理05-14
人教版小学五年级上册作文讲评与范文03-20
北京市2011怀柔初三物理一模试题(含答案) word - 图文11-08
OPC与PLC连接配置03-31
实验三、蒸馏、分馏和减压蒸馏10-13
住建局信息公开工作自查报告08-02
2017年广东专插本体检表06-04
- 教学能力大赛决赛获奖-教学实施报告-(完整图文版)
- 互联网+数据中心行业分析报告
- 2017上海杨浦区高三一模数学试题及答案
- 招商部差旅接待管理制度(4-25)
- 学生游玩安全注意事项
- 学生信息管理系统(文档模板供参考)
- 叉车门架有限元分析及系统设计
- 2014帮助残疾人志愿者服务情况记录
- 叶绿体中色素的提取和分离实验
- 中国食物成分表2020年最新权威完整改进版
- 推动国土资源领域生态文明建设
- 给水管道冲洗和消毒记录
- 计算机软件专业自我评价
- 高中数学必修1-5知识点归纳
- 2018-2022年中国第五代移动通信技术(5G)产业深度分析及发展前景研究报告发展趋势(目录)
- 生产车间巡查制度
- 2018版中国光热发电行业深度研究报告目录
- (通用)2019年中考数学总复习 第一章 第四节 数的开方与二次根式课件
- 2017_2018学年高中语文第二单元第4课说数课件粤教版
- 上市新药Lumateperone(卢美哌隆)合成检索总结报告
- 练习题
- 语言
- 结果
- 程序
- 共点力的平衡条件
- 2014年华中师大一附中高中招生考试理科综合测试物理题详解
- 松香蓖麻油改性醇酸树脂项目可行性研究报告(发改立项备案+2013年最新案例范文)详细编制方案
- 中国文具行业之优劣势
- 西宁市公交线路‘
- 人教版七年级下册中国历史复习资料打印
- 维持性血液透析患者心理护理
- 检测粉尘浓度的重要性
- 09金融联考406分复习经验谈
- 第四章 《西游记》与神魔小说
- CA1340杠杆加工工艺、工装夹具设计
- 如何成为一个优秀的策划
- 怎样从外型上选择优良的画眉鸟
- 人教版语文二年级下册教学计划
- 第七届飞思卡尔智能车比赛规则
- 北师大版生物必修3_第一节人体的代谢与稳态一内环境与稳态
- 2011年高考英语作文
- 社会主义新农村建设中的园林景观
- 红酒市场运营计划书
- 【7A文】云南省普通初中学生成长记录手册