html模版標題C++C程式語言 請問這個怎麼做
問題請看以下可以幫我完成他嗎隨機產生5個介於2-9的整數印出(1)此5個數字(2)此5個數字的平均(3)此5個數子中有幾個奇數、幾個偶數?****************/#include
#include#includeintmain(void){inti=1,a,b,c,d,e,even=0,odd=0;longtemptime;srand(time(&temptime));float...顯示更多請看以下可以幫我完成他嗎隨機產生5個介於2-9的整數印出(1)此5個數字(2)此5個數字的平均(3)此5個數子中有幾個奇數、幾個偶數?****************/#include#include#includeintmain(void){inti=1,a,b,c,d,e,even=0,odd=0;longtemptime;srand(time(&temptime));floatsum=0,avg;printf("
正修科大0024林進益");...return0;}
最佳解答
#include #include #include int main(void) { int a[5],b,c,d=0,e=0; float sum=0; srand(time(NULL)); printf("正修科大 0024 林進益
(1)
"); for(b=0;b<=4;b++) { c=rand()%8+2; a[b]=c; printf("%d
",a[b]); sum+=a[b]; if(a[b]%2==0) { d++; } else { e++; } } printf("
(2)
平均為:%.2f
(3)
共有%d個偶數 %d個奇數
",sum/5,d,e); system("pause"); return 0; } 希望有幫到你
其他答案
...
以上文章來自奇摩知識家,如有侵犯請留言告知
https://tw.answers.yahoo.com/question/index?qid=20090423000010KK08349
DD47F9E89D256822
留言列表