條件語句課后練習題-一道C語言練習題利用條件編譯實現:如果輸入
#include void main() { int a,b,c,e; printf("你要輸入幾個數字:"); scanf("%d",&a); if(a==2) { printf("輸入兩個數字:"); scanf("%d%d",&b,&c); e=b;b=c;c=e; } else if(a==3) { printf("輸入三個數字:"); scanf("%d%d%d",&b,&c,&e); if(b>c&&c>e) printf("%d%d",b,c); if(b>e&&e>c) printf("%d%d",b,e); if(e>c&&c>b) printf("%d%d",e,c); } }。
用if語句編寫這個C程序題
#includeint main(){ int a; char A,B,C,D,E; printf("輸入一個數a(在一到一百之間):"); scanf("%c,%c,%c,%c,%c,%d",&A,&B,&C,&D,&E,&a); if(a>=90) printf("A"); else if(a>=80) printf("B"); else if(a>=70) printf("C"); else if(a>=60) printf("D"); else printf("E"); return 0;}。
C語言的if語句編程
舉個例子 某單位馬上要加工資,增加金額取決于工齡和現工資兩個因素:對于工齡大于等于20年的,如果現工資高于2000,加200元,否則加180元;對于工齡小于20年的,如果現工資高于1500,加150元,否則加120元。
工齡和現工資從鍵盤輸入,編程求出下表加工資后的員工工資。 #include void main() { int y ; // 工齡 double s0 ; // 現工資 double s ; // 調整后工資 printf("輸入工齡:"); scanf("%d",&y); printf("輸入現工資:"); scanf("%lf",&s0); if (y>=20) if (s0>2000) s=s0+200; // 計算調整后工資 else s=s0+180; else if (s0>1500) s=s0+150; else s=s0+120; printf("調整后工資是%lf\n",s); } 。
C語言中,if語句的用法
if是真的話那么程序則執行if里的語句。。。
既然if是真,那么else當然不會運行。。
if else的意思是 如果if是真那么只運行if,如果(((if是假就運行else..)))
多練習下很容易掌握的,,,,每個else只能對他前面的一個if起作用也就是看else只看他前面的一個if
列:
main()
{
float grade;
int n1=0,n2=-1;
system("cls");
while(grade!=-1)
{
printf("grade[]:=");
scanf("%f",&grade);
if(grade>=60) (((((((如果grade大于等于60
n1++; (((((((((((((((那么n1+1;
else ((((((((((((((((else看他上一個if
n2++; (((((((((((((((即如果上一個if里是假。。。 那么n2+1
}
printf("YES---%d\tNO---%d",n1,n2);
getch();
}
收集C語言的例題
題目:請輸入星期幾的第一個字母來判斷一下是星期幾,如果第一個字母一樣,則繼續判斷第二個字母。
1.程序分析:用情況語句比較好,如果第一個字母一樣,則判斷用情況語句或if語句判斷第二個字母。
2.程序源代碼:
#include
void main()
{
char letter;
printf("please input the first letter of someday\n");
while ((letter=getch())!='Y')/*當所按字母為Y時才結束*/
{ switch (letter)
{case 'S':printf("please input second letter\n");
if((letter=getch())=='a')
printf("saturday\n");
else if ((letter=getch())=='u')
printf("sunday\n");
else printf("data error\n");
break;
case 'F':printf("friday\n");break;
case 'M':printf("monday\n");break;
case 'T':printf("please input second letter\n");
if((letter=getch())=='u')
printf("tuesday\n");
else if ((letter=getch())=='h')
printf("thursday\n");
else printf("data error\n");
break;
case 'W':printf("wednesday\n");break;
default: printf("data error\n");
}
}
}