c语言工程作业,西工大c语言程序作业

本文提供了一系列C语言编程练习题及其解决方案,包括完全数判断、方程求根、乒乓球比赛配对等典型问题,适用于初学者实践与提高。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

《西工大c语言程序作业》由会员分享,可在线阅读,更多相关《西工大c语言程序作业(25页珍藏版)》请在技术文库上搜索。

1、第2 季:循环 第 1 题 Title 完全数 Time Limit 1000MS Memor y Limit 10000KB Descrip tion 一个数如果恰好等于它的因子之和,这 个数就称为“ 完数“ 。例如,6 的因子为 1、2、3,而 6=1+2+3,因此 6 是“完数 “。请编写程序,找出 1000 之内的所有完 数。 Input Output 每行按格式输出其因子:6=1+2+3 Sample Input Sample Output 6=1+2+3 28=1+2+4+7+14 496=1+2+4+8+16+31+62+124+248 1.完全数 #includeint mai。

2、n() int m,i,j,s; for(m=6;m #include int main() float x0,x1,a; scanf(“%f“,&a); x1=a/2; do x0=x1;x1=(x0+a/x0)/2; while(fabs(x0-x1)=0.00001); printf(“%.5fn“,x1); return 0; 第 3 题 Title 二分求根Time Limit 1000MS Memor y Limit 10000KB Descrip tion 请编写程序,用二分法求下面方程在 (10,10) 之间的根: Input 输入区间数据为实型、用空格隔开输出 均。 Outp。

3、ut 输出根为实型,保留两位小数。 Sample Input -10 10 Sample Output 2.00 3.二分求根 #include #include int main() float x0,x1,x2,f0,f1,f2;printf(“ 请输入 x1,x2 的值:“);scanf(“%f%f“,&x1,&x2);f1=2*x1*x1*x1-4*x1*x1+3*x1-6; f2=2*x2*x2*x2-4*x2*x2+3*x2-6;dox0=(x1+x2)/2;f0=2*x0*x0*x0-4*x0*x0+3*x0-6;if(f0*f1=1e-5);printf(“ 方程的根为:%.2。

4、fn“,x0);return 0; 第 4 题 Title VOL 大学乒乓球比赛 Time Limit 1000MS Memor 10000KBy Limit Descrip tion VOL 大学有两个乒乓球队进行比赛,各 出 3 人。甲队为 A 、B 、C 三人,乙队为 X、Y 、Z 三人,已抽签决定比赛名单, 有人向队员打听比赛的名单,A 说他不和 X 比,C 说他不和 X、Z 比,请编写程序 找出 3 对赛手的名单。 Input Output 输出赛手名单,一行一对。 Sample Input Sample Output A=Z B=X C=Y 4.VOL 大学乒乓球比赛 #incl。

5、ude int main() char i,j,k;for(i=X;i #include int main() int m,n,a,i,t; scanf(“%d%d“,&m,&n); if(mn) t=m; m=n; n=t; for(a=m;asqrt(a) printf(“%d “,a); printf(“n“); return 0; 第 6 题 Title 奇特的分数数列 Time Limit 1000MS Memor y Limit 10000KB Descrip tion 有一个分数数列: 求出这个数列前 20 项之和。 Input Output 输出保留六位小数。 Sample I。

6、nput Sample Output 32.660261 6.奇特的分数数列 #include int main() int i,x,y,a;float sum=0;x=2; y=1;for(i=1;i #include int main() int i8,i5,i3,i2,i1,n8,n5,n3,n2,n1; float max=0,term; for(i8=0;i8max) max=term;n1=i1; n2=i2; n3=i3; n5=i5; n8=i8; printf(“%d %d %d %d %dn“,n8,n5,n3,n2,n1); printf(“%.2fn“,max);/* 。

7、输出存款方式*/ return 0; 第 8 题 Title 整数位数 Time Limit 1000MS Memor y Limit 10000KB Descrip 编写程序输入一个数,输出其整数部分tion 的位数(例如输入 123.4 则输出 3,输入 0.6 则输出 0) 。 Input 输入为实型。 Output 输出为整型。 Sample Input 123.4 Sample Output 3 8.整数位数 #include int main() int x,n=0;float c=2.0;scanf(“%f“,&c);x=int(c);while(x!=0)n+;x=x/10;p。

8、rintf(“%dn“,n);return 0; 第 9 题 Title Time Limit 1000MS Memor y Limit 10000KB Descrip tion 编写程序利用下面公式计算 的近似值: Input Output 输出 为实型,保留六位小数。 Sample Input Sample Output 3.141591 9.计算 的近似值 #include #include int main() int a=1,f=1;double p=0;while(fabs(1.0/a)=1e-6) p=p+1.0/a*f;a=a+2;f=-f; printf(“pi=%.6lfn。

9、“,4*p);return 0; 第 10 题 Title 级数和 Time Limit 1000MS Memor y Limit 10000KB Descrip tion 编写程序求下面级数前 n 项的和,其中 n 从键盘上输入。 Input 输入 n 为整型。 Output 输出和为实型,保留六位小数。 Sample 5Input Sample Output 0.338462 10.级数和 #include #include int main() int i,n;double s=0; scanf(“%d“,&n);for(i=1;i #include int main() int i,n。

10、;double s=0; scanf(“%d“,&n);for(i=1;i int main() int n,i,j,s,k;scanf(“%d“,&n);for(i=1;i int main() int x,a,i,t;scanf(“%d%d“,&x,&a);t=1;for(i=0,t=1;i int main() int s1=2,i,j=2,s2=0,m=100,a1=1,a2=1,a3,t;for(i=1;i=m) a3=a1+2*a2;s1=s1+a3;j=j+1;s2=s1+a2+2*a3;t=a2;a2=a3;a1=t; printf(“%dn“,j);return 0; 第 1。

11、5 题 Title 五猴分桃Time Limit 1000MS Memor y Limit 10000KB Descrip tion 5 只猴子一起摘了 1 堆桃子。因为太累了, 它们商量决定,先睡一觉再分。过了不 知多久,1 只猴子来了。它见别的猴子没 来,便将这 1 堆桃子平均分成 5 份,结 果多了 1 个,就将多的这个吃了,拿走 其中的 1 堆。又过了不知多久,第 2 只 猴子来了。它不知道有 1 个同伴已经来 过,还以为自己是第 1 个到的呢。于是 将地上的桃子堆起来,平均分成 5 份, 发现也多了 1 个,同样吃了这 1 个,拿 走其中的 1 堆。第 3 只、第 4 只、第 5 只猴子都是这样问这 5 只猴子至少 摘了多少个桃子?第 5 个猴子走后还剩 下多少个桃子? Input Output 输出 5 只猴子至少摘了多少个桃子,第 5 个猴子走后还剩下多少个桃子。中间用 空格隔开。 Sample Input Sample Output 3121 1020 15.五猴分桃 #include int main() int s,p,s1,n;for(s=6;s+=5)p = s1 = s;for(n=1;n5&p=4)break; printf(“%dt%d“,s1,p);return 0; 。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值