题目1:
写一个程序完成下列功能
1、输入一个分数score
2、score<60 输出E
3、60<=score<70 输出D
4、70<=score<80 输出C
5、80<=score<90 输出B
6、90<=score 输出A
编程:
#pragma warning(disable:4996)
#include <stdio.h>
void main()
{
int score;
printf("input a score\n");
scanf("%d", &score);
if (score < 60)
{
printf("E");
}
else if (score >= 60 && score < 70)
{
printf("D");
}
else if (score >= 70 && score < 80)
{
printf("C");
}
else if (score >= 80 && score < 90)
{
printf("B");
}
else if (score >= 90 )
{
printf("A");
}
}
题目2:
输入三个数a,b,c,按由小到大的顺序输出
编程:
①自己的方法
#pragma warning(disable:4996)
#include <stdio.h>
void main()
{
int a, b, c;
printf("input three numbers\n");
scanf("%d%d%d", &a, &b, &c);
if (a < b && b < c)
{
printf("%d %d %d",a,b,c);
}
else if (a < c && c < b)
{
printf("%d %d %d",a,c,b);
}
else if (b < a && a < c)
{
printf("%d %d %d",b,a,c);
}
else if (b < c && c < a)
{
printf("%d %d %d",b,c,a);
}
else if (c < a && a < b)
{
printf("%d %d %d",c,a,b);
}
else if (c < b && b < a)
{
printf("%d %d %d",c,b,a);
}
}
②老师的方法
#pragma warning(disable:4996)
#include <stdio.h>
void main()
{
int a, b, c, temp;
printf("input three numbers\n");
scanf("%d%d%d", &a, &b, &c);
if (a > b)
{
temp = a;
a = b;
b = temp;
}
if (a > c)
{
temp = a;
a = c;
c = temp;
}
if (b > c)
{
temp = b;
b = c;
c = temp;
}
printf("%d %d %d", a, b, c);
}