1.编写程序,输入周一至周五中的任意一天,屏幕显示一条不同的短语,
#include
int main()
{
int day=0;
printf("输入星期几(要求输入1—7中的一个整数,例如星期六,输入 6)\n");
scanf("%d",&day);
switch(day)
{
case 1:printf("星期一快乐!");break;
case 2:printf("星期二快乐!");break;
case 3:printf("星期三快乐!");break;
case 4:printf("星期四快乐!");break;
case 5:printf("星期五快乐!");break;
case 6:printf("星期六快乐!");break;
case 7:printf("星期日快乐!");break;
default:printf("跟你说了要输入1—7中的一个整数");break;
}
printf("\n");
return 0;
}
2.编写一个通过键盘输入,并在屏幕上显示您的综合信息的程序
#include <stdio.h>
# include <math.h>
void main()
{
int nianling,shuxue,wuli,huaxue,yingyu;
char nianji;
float tizhong,shengao,tizhongyinzi,pingjun;
printf("请输入年级: ");
nianji=getchar();
//scanf("%c\n",&nianji);
printf("请输入年龄: ");
scanf("%d",&nianling);
printf("请输入身高: ");
scanf("%f",&shengao);
printf("请输入体重: ");
scanf("%f",&tizhong);
printf("请输入数学成绩: ");
scanf("%d",&shuxue);
printf("请输入物理成绩: ");
scanf("%d",&wuli);
printf("请输入化学成绩: ");
scanf("%d",&huaxue);
printf("请输入英语成绩: ");
scanf("%d",&yingyu);
tizhongyinzi=tizhong/shengao;
pingjun=(shuxue+wuli+huaxue+yingyu)/4.0;
printf("年级是: %c\n",nianji);
printf("年龄是: %d\n",nianling);
printf("身高是: %f\n",shengao);
printf("体重是: %f\n",tizhong);
printf("数学成绩是: %d\n",shuxue);
printf("物理成绩是: %d\n",wuli);
printf("化学成绩是: %d\n",huaxue);
printf("英语成绩是: %d\n",yingyu);
printf("体重因子是: %f\n",tizhongyinzi);
printf("平均分是: %f\n",pingjun);
}
转载请注明出处短句子网 » 编写程序在屏幕上显示一个短句