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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

c语言绝对循环,c语言之循环

發(fā)布時間:2023/12/15 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c语言绝对循环,c语言之循环 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

1.

//程序功能:輸入一個正整數(shù)n,再輸入n個正整數(shù),求其中的偶數(shù)個數(shù)與偶數(shù)之和。

//提 示:除在指定位置添加語句之外,請不要改動程序中的其他內(nèi)容。

#include

int main(void)

{

hi:

int i, n, x,s,c;

s=0, c=0;

printf("輸入您需要計算的正整數(shù)的個數(shù):\n");

scanf("%d", &n);

printf("輸入%d個正整數(shù): \n",n);

for(i=1; i<=n; i )

{

scanf("%d", &x);

if(x%2==0)

{

s =1;

c =x;

}

}

printf("這些數(shù)中,偶數(shù)個數(shù) = %d個\n", s);

printf("這些偶數(shù)的和 = %d\n", c);

goto hi;

return 0;

}

2.

//程序功能:輸入一個正整數(shù)n,再輸入n個正整數(shù),輸入一個正整數(shù)n,再輸入n個正整數(shù),

// 統(tǒng)計n個整數(shù)之和與7的倍數(shù)的奇數(shù)平均值(輸出結(jié)果保留兩位小數(shù))。

//提 示:除在指定位置添加語句之外,請不要改動程序中的其他內(nèi)容。

#include

int main(void)

{

int i, n, x, zh, jsh, jsgs;

zh = 0;

jsh = 0;

jsgs = 0;

double average;

printf("輸入您需要的整數(shù)個數(shù):\n ");

scanf("%d", &n);

printf("輸入%d個正整數(shù): ",n);

for(i=1; i<=n; i )

{

scanf("%d", &x);

zh =x;

if(x%7==0 &&

x%2==1)

{

jsh =x;

jsgs =1;

}

}

average = 1.0*jsh/jsgs;

printf("總和=%d, 7的倍數(shù)的奇數(shù)平均值=%.2f\n", zh, average);

return 0;

}

3.

//程序功能:從鍵盤上輸入一批學(xué)生成績,統(tǒng)計這批成績中的最高分和最低分。

//提 示:除在指定位置添加語句之外,請不要改動程序中的其他內(nèi)容。

#include

int main(void)

{

int score, max, min;

printf("請輸入第1個學(xué)生的成績:\n");

scanf("%d", &score);

printf("輸入剩余學(xué)生的成績(以負數(shù)結(jié)束):\n ");

max = score, min = score;

for( ; score>0 ; )

{

if(score>max)

max = score;

if(score

min = score;

scanf("%d", &score);

}

printf("最高分=%d, 最低分=%d\n",max,min);

return 0;

}

4.

//程序功能:從鍵盤上輸入一個班的學(xué)生成績,輸出最值,評估教學(xué)效果。

//提 示:除在指定位置添加語句之外,請不要改動程序中的其他內(nèi)容。

#include

int main(void)

{

int score,max,min,sum,count;

printf("請輸入第1個學(xué)生的成績:\n");

scanf("%d", &score);

printf("輸入剩余學(xué)生的成績(以負數(shù)結(jié)束):\n ");

sum = 0, count = 0;

max = score, min = score;

for( ; score>=0 ; )

{

count =1;

sum =score;

if(score>max)

max = score;

if(score

min = score;

scanf("%d", &score);

}

printf("The class number is :%d", count);

printf("The highest score is :\n%d\n", max);

printf("The lowest score is :\n%d\n", min);

if(1.0*sum/count>4.0*(max

min)/5)printf("教學(xué)效果:好\n");

else if(1.0*sum/count<1.0*(max

min)/2)printf("教學(xué)效果:差\n");

else printf("教學(xué)效果:一般\n");

return 0;

}

printf("輸入一個正整數(shù): ");

scanf("%d", &m);

n = m;

sum = 0, wq = 1;

while(n>0)

{

digit = n;

if(digit%2 == 0)

sum =digit;

wq*=10;

n/=10;

}

printf("整數(shù)%d最高位的權(quán)是%d,各數(shù)位上偶數(shù)數(shù)字和是%d\n",m,wq/10,sum);

return 0;

}

7.

//程序功能:使用格里高利公式求π的近似值,要求精確到最后一項的絕對值小于10-4。

//提示:除在指定位置添加語句之外,請不要改動程序中的其他內(nèi)容。

#include

#include

int main(void)

{

int fm,flag;

double item,pi;

flag = 1;

fm = 1;

pi=0;

item = 1.0;

do

{

item =flag*1.0/fm;

pi = item;

flag = -flag;

fm = 2;

}

while(fabs(item) >= pow(10,-4));

pi = 4*pi;

printf("π的近似值等于%.4f\n",pi);

return 0;

}

8.

//程序功能:輸入一個正實數(shù)eps,按題目給出的公式求s的近似值,直到相鄰

// 兩項絕對值之差的絕對值小于eps。

//提示:除在指定位置添加語句之外,請不要改動程序中的其他內(nèi)容。

#include

#include

int main(void)

{

int fm,flag;

double eps,item1,item2,s;

printf("輸入一個正實數(shù)eps(如:0.0001): ");

scanf("%lf",&eps);

fm=1, flag=1, s=0;

do

{

item1 = flag*1.0/(fm 3);

item2 = flag*1.0/fm;

fm = fm 3;

flag =-flag;

s=s item2;

}

while(fabs(item1-item2) >= eps);

printf("S的近似值等于%.4f\n",s);

return 0;

}

9.

//程序功能:使用二重循環(huán)結(jié)構(gòu)(循環(huán)嵌套)編寫程序,計算s=1! 2! 3! … 10!。

//提 示:除在指定位置添加語句之外,請不要改動程序中的其他內(nèi)容。

#include

int main(void)

{

int i, j;

double item,sum;

item=1, sum=0;

for(j=1; j<=10; j )

for(i=1; i<=j; i )

{

i *= j;

item *= i;

sum =item;

}

printf("1! 2! 3! … 10!=%.0f\n", sum);

return 0;

}

10.

//程序功能:使用二重循環(huán)結(jié)構(gòu)(循環(huán)嵌套)編寫程序,計算s=a aa … aa…a(n個a)。

//提 示:除在指定位置添加語句之外,請不要改動程序中的其他內(nèi)容。

#include

int main(void)

{

int i, j, a, n;

double item,sum;

printf("輸入兩個正整數(shù)a和n(1位數(shù)): ");

scanf("%d",&a);

scanf("%d",&n);

item = 1;

sum = 0;

for(i=1; i<=n; i )

{

for(j=1; j<=i; j )

{

j*=i;

item*=a;

}

sum =item;

}

printf("a aa … aa…a(n個a)=%.0f\n", sum);

return 0;

}

11.

#include

#include

int main(void)

{

long int m;

long int n;

int i;

int j;

int k;

printf("請輸入一個整數(shù):");

scanf("%d", &m);

printf("數(shù)字%d從高位開始逐位分離并輸出的結(jié)果是:", m);

i=0;

n = m;

while(n>0)

{

n/=10;

i ;

}

j=i-1;

while(j>=0)

{

k=m/pow(10,j);

printf("%d,", k);

m=m-k*pow(10,j);

j=j-1;

}

return 0;

}

12.

#include

int main(void)

{

int x;

x=1;

int i;

for(i=1; i<=9; i )

x=(x 1)*2;

printf("猴子第一天共摘了%d個桃子\n", x);

return 0;

}

13.

水仙花數(shù)問題

#include

#include

int main(void)

{

int i, a, b, c, d;

int sum = 0;

printf("1-10000間的所有水仙花數(shù):\n");

for(i=1; i<=10000; i )

{

a = i;

b = (i-a)/10;

c =((i-a)/10-b)/10;

d = i/1000;

sum = pow(a,3) pow(b,3) pow(c,3) pow(d,3);

if(sum==i)

printf("%d\n", i);

}

return 0;

}

陳坤 2014/3/27 星期四 21:56

總結(jié)

以上是生活随笔為你收集整理的c语言绝对循环,c语言之循环的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。