c语言作业题整理,C语言作业题整理..doc

第一次

编写一程序,通过键盘输入一华氏温度,将其转换为摄氏温度后输出。 公式为c=5/9(f - 32)

#include "stdio.h"

main()

{

float f=0,h=0;

printf("请输入华氏温度:");

scanf("%f",&f);

printf("转化为摄氏温度为:");

h=(float)5/9*(f-32);

printf("%.2f\n",h);

}

通过键盘输入一小写字母,将其转换为大写字母输出,并输出该大写字母的后一位字母和前一位字母(如果输入该大写字母为A,则其前一位字母为Z;如果输入该大写字母为Z,则其后一位字母为A)。

#include "stdio.h"

main()

{

char ch1,ch2,ch3,ch;

printf("请输入一个小写字母:\n");

while(scanf("%c",&ch),ch<97 || ch>122)

{

printf("您输入的符号不是小写字母,请重新输入一个小写字母:\n");

}

printf("其对应的大写字母和前后的大写字母分别为:\n");

if(ch=='a'){ch2=ch-32;ch1=ch2+25;ch3=ch2+1;}

else if(ch=='z'){ch2=ch-32;ch1=ch2-1;ch3=ch2-25;}

else {ch2=ch-32;ch1=ch2-1;ch3=ch2+1;}

printf("%c,%c,%c\n",ch1,ch2,ch3);

}

通过键盘输入一个两位的整数,试编写程序将其个位与十位分别以字符的方式输出。输出形式为:“the input number is 你输入的整数,the tens is 十位数字,the units is 个位数字。”如果输入的整数不正确,则输出“wrong input”

#include "stdio.h"

main()

{

int a,b1,b2;

printf("请输入一个两位正整数:\n");

scanf("%d",&a);

if(a<10||a>=100){

printf("输入不符合要求");

}else

{

b1=a%10;

b2=a/10;

printf("十位数是:%c\n个位数是:%c\n",b2+'0',b1+'0');

}

}给定方程ax^2+bx+c=0,试编写程序根据键盘输入实数a、b、c,能输出其根,要求:如果该方程有两个不同的根,则输出形式为"the Answer of ax^2+bx+c=0 is x1=根1,x2=根2"如果该方程有两个相同的根,则输出形式为"the Answer of ax^2+bx+c=0 is x1=X2=根"如果该方程无解,则输出形式为"the Answer of ax^2+bx+c=0 is none",其中a、b、c均为键盘输入,输出结果保留两位小数。#include "stdio.h"

#include "math.h"

main(){

float a,b,c,disc,x1,x2;

scanf("%f,%f,%f",&a,&b,&c);

disc=b*b-4*a*c;

if(disc==0){

x1=x2=-b/(2*a);

printf("the Answer of ax^2+bx+c is x1=x2=%.2f\n",x1);

}

else if(disc>0){

x1=(-b+sqrt(disc))/(2*a);

x2=(-b-sqrt(disc))/(2*a);

printf("the Answer of ax^2+bx+c is x1=%.2f,x2=%.2f\n",x1,x2);

}

else{printf("the Answer of ax^2+bx+c=0 is none\n");}

}

第二次

求1/3+3/5+5/7+…前20项之和。(本题要求分别以goto,for,do ...while,while四种循环语句实现)?

#include

int main()

{

int i;

float s=0;

for(i=1;i<=20;i++){

s+=(float)(2*i-1)/(2*i+1);

}

printf("s=%f\n",s);

return 0;

}

#include

int main()

{

int p,r,n,m;

printf("n,m:");

scanf("%d,%d",&n,&m);

if(p=n*m)

while(m!=0)

{r=n%m;

n=m;

m=r;}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值