欢迎来到天天文库
浏览记录
ID:59452664
大小:1.12 MB
页数:40页
时间:2020-09-17
《2019年C++语言程序设计第十讲ppt课件.ppt》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、例1:输入两个正整数a和n,求a+aa+aaa+aaaa+…+aaa…a(n个a)之和。例如,输入2和3,则求2+22+222=246。输入a和nfori=0ton-1sum+=t输出sumt=0t=t*10+a#includevoidmain(){intsum,a,n,i,t;cout<<"Inputa,n:";cin>>a>>n;t=0;sum=0;for(i=0;i2、a…a(n个a)之和。例如,输入2和3,则求2+22+222=246。#include#includevoidmain(){intsum,a,n,i,t;cout<<"Inputa,n:";cin>>a>>n;sum=0;t=0;for(i=0;i3、tream.h>#includevoidmain(){intn,i;floatjc,s;cout<<"Inputn:";cin>>n;jc=1;s=1;for(i=1;i<=n;i++){jc=jc*i;s+=1.0/jc;}cout<<"s="<4、oi???#includevoidmain(){intn,i,j;floatjc,s;printf("Inputn:");scanf("%d",&n);s=1;for(i=1;i<=n;i++){jc=1;for(j=1;j<=i;j++)jc=jc*j;s+=1.0/jc;}printf("s=%.3f",s);}#includevoidmain(){inti,b,s,g;for(i=100;i<1000;i++){b=i/100;s=i/10%10;g=i%10;if(b*b*b+s*s*s+g*g*g==i)cout5、<voidmain(){intn,b,s,g;for(b=1;b<=9;b++)for(s=0;s<=9;s++)for(g=0;g<=6、9;g++){n=100*b+10*s+g;if(b*b*b+s*s*s+g*g*g==n)cout<voidmain(){inta[100],x,n=0,count=0,i;cin>>x;while(x>0){a[n]=x;n++;cin>>x;}for(i=0;i7、count;}cin>>x;×输入xn=0count++fori=0ton-1a[i]%10!=0T输出a[i]Fx>0a[n]=xcount=0n++输入x输出count例5:用公式π/4≈1-1/3+1/5-1/7+…求π的近似值,直到最后一项的绝对值小于10-6为止。#includevoidmain(){floats=0,t;intn=1,f=1;t=1.0/n;while(t>=1e-6){s+=f*t;f=-f;n+=2;t=1.0/n;}cout<<"PI="<<4*s<=10-6f=-f输
2、a…a(n个a)之和。例如,输入2和3,则求2+22+222=246。#include#includevoidmain(){intsum,a,n,i,t;cout<<"Inputa,n:";cin>>a>>n;sum=0;t=0;for(i=0;i3、tream.h>#includevoidmain(){intn,i;floatjc,s;cout<<"Inputn:";cin>>n;jc=1;s=1;for(i=1;i<=n;i++){jc=jc*i;s+=1.0/jc;}cout<<"s="<4、oi???#includevoidmain(){intn,i,j;floatjc,s;printf("Inputn:");scanf("%d",&n);s=1;for(i=1;i<=n;i++){jc=1;for(j=1;j<=i;j++)jc=jc*j;s+=1.0/jc;}printf("s=%.3f",s);}#includevoidmain(){inti,b,s,g;for(i=100;i<1000;i++){b=i/100;s=i/10%10;g=i%10;if(b*b*b+s*s*s+g*g*g==i)cout5、<voidmain(){intn,b,s,g;for(b=1;b<=9;b++)for(s=0;s<=9;s++)for(g=0;g<=6、9;g++){n=100*b+10*s+g;if(b*b*b+s*s*s+g*g*g==n)cout<voidmain(){inta[100],x,n=0,count=0,i;cin>>x;while(x>0){a[n]=x;n++;cin>>x;}for(i=0;i7、count;}cin>>x;×输入xn=0count++fori=0ton-1a[i]%10!=0T输出a[i]Fx>0a[n]=xcount=0n++输入x输出count例5:用公式π/4≈1-1/3+1/5-1/7+…求π的近似值,直到最后一项的绝对值小于10-6为止。#includevoidmain(){floats=0,t;intn=1,f=1;t=1.0/n;while(t>=1e-6){s+=f*t;f=-f;n+=2;t=1.0/n;}cout<<"PI="<<4*s<=10-6f=-f输
3、tream.h>#includevoidmain(){intn,i;floatjc,s;cout<<"Inputn:";cin>>n;jc=1;s=1;for(i=1;i<=n;i++){jc=jc*i;s+=1.0/jc;}cout<<"s="<4、oi???#includevoidmain(){intn,i,j;floatjc,s;printf("Inputn:");scanf("%d",&n);s=1;for(i=1;i<=n;i++){jc=1;for(j=1;j<=i;j++)jc=jc*j;s+=1.0/jc;}printf("s=%.3f",s);}#includevoidmain(){inti,b,s,g;for(i=100;i<1000;i++){b=i/100;s=i/10%10;g=i%10;if(b*b*b+s*s*s+g*g*g==i)cout5、<voidmain(){intn,b,s,g;for(b=1;b<=9;b++)for(s=0;s<=9;s++)for(g=0;g<=6、9;g++){n=100*b+10*s+g;if(b*b*b+s*s*s+g*g*g==n)cout<voidmain(){inta[100],x,n=0,count=0,i;cin>>x;while(x>0){a[n]=x;n++;cin>>x;}for(i=0;i7、count;}cin>>x;×输入xn=0count++fori=0ton-1a[i]%10!=0T输出a[i]Fx>0a[n]=xcount=0n++输入x输出count例5:用公式π/4≈1-1/3+1/5-1/7+…求π的近似值,直到最后一项的绝对值小于10-6为止。#includevoidmain(){floats=0,t;intn=1,f=1;t=1.0/n;while(t>=1e-6){s+=f*t;f=-f;n+=2;t=1.0/n;}cout<<"PI="<<4*s<=10-6f=-f输
4、oi???#includevoidmain(){intn,i,j;floatjc,s;printf("Inputn:");scanf("%d",&n);s=1;for(i=1;i<=n;i++){jc=1;for(j=1;j<=i;j++)jc=jc*j;s+=1.0/jc;}printf("s=%.3f",s);}#includevoidmain(){inti,b,s,g;for(i=100;i<1000;i++){b=i/100;s=i/10%10;g=i%10;if(b*b*b+s*s*s+g*g*g==i)cout
5、<voidmain(){intn,b,s,g;for(b=1;b<=9;b++)for(s=0;s<=9;s++)for(g=0;g<=
6、9;g++){n=100*b+10*s+g;if(b*b*b+s*s*s+g*g*g==n)cout<voidmain(){inta[100],x,n=0,count=0,i;cin>>x;while(x>0){a[n]=x;n++;cin>>x;}for(i=0;i7、count;}cin>>x;×输入xn=0count++fori=0ton-1a[i]%10!=0T输出a[i]Fx>0a[n]=xcount=0n++输入x输出count例5:用公式π/4≈1-1/3+1/5-1/7+…求π的近似值,直到最后一项的绝对值小于10-6为止。#includevoidmain(){floats=0,t;intn=1,f=1;t=1.0/n;while(t>=1e-6){s+=f*t;f=-f;n+=2;t=1.0/n;}cout<<"PI="<<4*s<=10-6f=-f输
7、count;}cin>>x;×输入xn=0count++fori=0ton-1a[i]%10!=0T输出a[i]Fx>0a[n]=xcount=0n++输入x输出count例5:用公式π/4≈1-1/3+1/5-1/7+…求π的近似值,直到最后一项的绝对值小于10-6为止。#includevoidmain(){floats=0,t;intn=1,f=1;t=1.0/n;while(t>=1e-6){s+=f*t;f=-f;n+=2;t=1.0/n;}cout<<"PI="<<4*s<=10-6f=-f输
此文档下载收益归作者所有