作业帮 > 综合 > 作业

求帮忙用C语言编写一段简单的程序,好的话我再加分

来源:学生作业帮 编辑:搜搜考试网作业帮 分类:综合作业 时间:2024/04/26 08:19:23
求帮忙用C语言编写一段简单的程序,好的话我再加分
输入一个三位数,若此数是水仙花数输出“Y”,否则输出“N”,若输入值不是三位数输出“data error”.提示:水仙花数是一个三位数,组成这个三位数的三个数字的立方和与这个三位数相等.如:153=13+53+33.判断是否是水仙花数需把构成三位数的三个数字分离出来并存入变量.
给出一个百分制成绩,要求输出成绩等级A、B、C、D.90 分以上为A,80~89分为B,70~79 分为C,60~69 分为D,60 分以下为E.事先编好程序,要求分别用if 语句和switch 语句实现.运行程序,并检查结果是否正确.
求帮忙用C语言编写一段简单的程序,好的话我再加分
水仙花数
#include
void main()
{
\x05int i,a,b,c;
printf("请输入一个三位数:");
scanf("%d",&i);
if(i999)
printf("data error");
else
{
a=i/100;
\x05b=(i-a*100)/10;
\x05c=(i-a*100-b*10);
\x05if(a*a*a+b*b*b+c*c*c==i)
\x05\x05printf("Y");
else
printf("N");
}
\x05
\x05printf("\n");
\x05}
成绩等级(switch)
#include
void main()
{
\x05float score;
\x05char grade;
\x05printf("input the student's score:");
\x05scanf("%f",&score);
\x05while(score>100||score
再问: 亲,还有那百分制分数的,万分感谢,麻烦了
再答: 成绩等级(if) #include void main() { float score; char grade; printf("input the student's score:"); scanf("%f",&score); while(score>100||score90||score==90) grade='A'; else if(score>80||score==80) grade='B'; else if(score>70||score==70) grade='C'; else if(score>60||score==60) grade='D'; else grade='E'; printf("score:%5.1f,grade:%c\n",score,grade); }