日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

作业 3 利用分支和循环结构解决问题

發布時間:2025/7/14 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 作业 3 利用分支和循环结构解决问题 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1、輸入一個整數x,計算分段函數。

/*計算分段函數*/ #include<stdio.h> int main() {float x=0,y=0;printf("請輸入x:");scanf("%f",&x);if(x>0)y=1;else if(x==0)y=0;elsey=-1;printf("當x=%f時,y=%f\n",x,y);return 0; }


?

2、輸入正整數n和成績,計算學生平均分和及格人數。

#include<stdio.h> int main(void) {int count,i,n;double grade,total;printf("Enter n:");scanf("%d",&n);total=0;count=0;for(i=1;i<=n;i++){printf("Enter grade#%d:\n",i);scanf("lf",&grade);total=total+grade;if(grade>=60){count++;}}printf("Grade average=%.2f\n",total/n);printf("Number of failures=%d\n",count);return 0; }

?

3、統計字母,空格,字符和其他字符。

#include<stdio.h> int main(void) {int digit,letter,other;char ch;int i;digit=letter=other=0;printf("Enter 15 characters:");for(i=1;i<=10;i++){ch=getchar();if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z'))letter++;else if(ch>='0'&&ch<='14')digit++;elseother++;}printf("letter=%d,digit=%d,other=%d\n",letter,digit,other);return 0; }


4、輸入年份,判斷是否為閏年。

#include<stdio.h> int main(void) {int n,year;printf("Enter a year: ");scanf("%d",&year);for(year++)if(year%100==n){printf("-1\n");break;}if(year%100!=n && year%4=n && year%400=n)printf("%d 是閏年。\n",year);elseprintf("-1\n");return 0; }

?

5、輸入五級制成績(A-E)。

#include<stdio.h> int main(void) {int score;char level;printf("請輸入成績:\n");scanf("%d",&score);if(score<80)if(score<70)if(score<60)printf("E\n");elseprintf("D\n");elseprintf("C\n");elseif(score<90)printf("B\n");elseprintf("A\n");return 0; }


6、查詢水果單價。

#include<stdio.h> int main(void) {int choice,i;double price;for(i=1;i<=5;i++){printf("[1]Select apples\n");printf("[2]Select pears\n");printf("[3]Select oranges\n");printf("[4]Select grapes\n");printf("[0]Exit\n");printf("Enter choice: ");scanf("%d",&choice);if(choice==0)break;switch(choice){case 1:price=3.00;break;case 2:price=2.50;break;case 3:price=4.10;break;case 4:price=10.20;break;default:price=0.00;break;}printf("price=%0.2f\n",price);}printf("Thanks\n");return 0; }

?

心得:在編程過程中會遇到很多困難,需要心平氣和的去找出來解決,想要自己會編程就要充分理解每行代碼所代表的是什么,有什么作用,才能使編出來的東西按照要求輸出。

問題:有時候編寫出來的if-else語句并不能起作用,只執行if后面的語句,這是怎么回事呢????

?

?

?

?

轉載于:https://www.cnblogs.com/zhangling213549/p/3378439.html

總結

以上是生活随笔為你收集整理的作业 3 利用分支和循环结构解决问题的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。