欢迎来到天天文库
浏览记录
ID:13238258
大小:17.04 KB
页数:6页
时间:2018-07-21
《c语言程序设计之循环结构》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、四、循环结构1、求1-1/4+1/7-1/10+1/13-1/16+……程序填空,不要改变与输入输出有关的语句。输入一个正整数repeat(02、h>#includeintmain(void){intdenominator,flag;intrepeat,ri;doubleeps,item,sum;scanf("%d",&repeat);for(ri=1;ri<=repeat;ri++){scanf("%le",&eps);sum=0;denominator=1;flag=1;item=1;while(fabs(item)>=eps){item=flag*1.0/denominator;sum=sum+item;denomi3、nator=denominator+3;flag=-flag;}printf("sum=%.6f",sum);}}2、求奇数和程序填空,不要改变与输入输出有关的语句。输入一个正整数repeat(04、heoddnumbersis116.#includeintmain(void){intx,sum;intrepeat,ri;scanf("%d",&repeat);for(ri=1;ri<=repeat;ri++){scanf("%d",&x);sum=0;while(x>0){if(x%2)sum=sum+x;scanf("%d",&x);}printf("Thesumoftheoddnumbersis%d.",sum);}}3、求整数的位数程序填空,不要改变与输入输出有5、关的语句。输入一个正整数repeat(06、.h>intmain(void){intcount,in;intrepeat,ri;scanf("%d",&repeat);for(ri=1;ri<=repeat;ri++){scanf("%d",&in);count=0;if(in<0)in=-in;do{count++;in=in/10;}while(in);printf("count=%d",count);}}4、求最小值程序填空,不要改变与输入输出有关的语句。输入一个正整数repeat(07、运算:输入一个正整数n,再输入n个整数,输出最小值。输入输出示例:括号内是说明输入3(repeat=3)4-2-12310004-9-11-83531输出min=-123min=-9min=1#includeintmain(void){inti,min,n,x;intrepeat,ri;scanf("%d",&repeat);for(ri=1;ri<=repeat;ri++){scanf("%d",&n);scanf("%d",&x);min=x;for(i=1;i8、){scanf("%d",&x);if(x
2、h>#includeintmain(void){intdenominator,flag;intrepeat,ri;doubleeps,item,sum;scanf("%d",&repeat);for(ri=1;ri<=repeat;ri++){scanf("%le",&eps);sum=0;denominator=1;flag=1;item=1;while(fabs(item)>=eps){item=flag*1.0/denominator;sum=sum+item;denomi
3、nator=denominator+3;flag=-flag;}printf("sum=%.6f",sum);}}2、求奇数和程序填空,不要改变与输入输出有关的语句。输入一个正整数repeat(04、heoddnumbersis116.#includeintmain(void){intx,sum;intrepeat,ri;scanf("%d",&repeat);for(ri=1;ri<=repeat;ri++){scanf("%d",&x);sum=0;while(x>0){if(x%2)sum=sum+x;scanf("%d",&x);}printf("Thesumoftheoddnumbersis%d.",sum);}}3、求整数的位数程序填空,不要改变与输入输出有5、关的语句。输入一个正整数repeat(06、.h>intmain(void){intcount,in;intrepeat,ri;scanf("%d",&repeat);for(ri=1;ri<=repeat;ri++){scanf("%d",&in);count=0;if(in<0)in=-in;do{count++;in=in/10;}while(in);printf("count=%d",count);}}4、求最小值程序填空,不要改变与输入输出有关的语句。输入一个正整数repeat(07、运算:输入一个正整数n,再输入n个整数,输出最小值。输入输出示例:括号内是说明输入3(repeat=3)4-2-12310004-9-11-83531输出min=-123min=-9min=1#includeintmain(void){inti,min,n,x;intrepeat,ri;scanf("%d",&repeat);for(ri=1;ri<=repeat;ri++){scanf("%d",&n);scanf("%d",&x);min=x;for(i=1;i8、){scanf("%d",&x);if(x
4、heoddnumbersis116.#includeintmain(void){intx,sum;intrepeat,ri;scanf("%d",&repeat);for(ri=1;ri<=repeat;ri++){scanf("%d",&x);sum=0;while(x>0){if(x%2)sum=sum+x;scanf("%d",&x);}printf("Thesumoftheoddnumbersis%d.",sum);}}3、求整数的位数程序填空,不要改变与输入输出有
5、关的语句。输入一个正整数repeat(06、.h>intmain(void){intcount,in;intrepeat,ri;scanf("%d",&repeat);for(ri=1;ri<=repeat;ri++){scanf("%d",&in);count=0;if(in<0)in=-in;do{count++;in=in/10;}while(in);printf("count=%d",count);}}4、求最小值程序填空,不要改变与输入输出有关的语句。输入一个正整数repeat(07、运算:输入一个正整数n,再输入n个整数,输出最小值。输入输出示例:括号内是说明输入3(repeat=3)4-2-12310004-9-11-83531输出min=-123min=-9min=1#includeintmain(void){inti,min,n,x;intrepeat,ri;scanf("%d",&repeat);for(ri=1;ri<=repeat;ri++){scanf("%d",&n);scanf("%d",&x);min=x;for(i=1;i8、){scanf("%d",&x);if(x
6、.h>intmain(void){intcount,in;intrepeat,ri;scanf("%d",&repeat);for(ri=1;ri<=repeat;ri++){scanf("%d",&in);count=0;if(in<0)in=-in;do{count++;in=in/10;}while(in);printf("count=%d",count);}}4、求最小值程序填空,不要改变与输入输出有关的语句。输入一个正整数repeat(07、运算:输入一个正整数n,再输入n个整数,输出最小值。输入输出示例:括号内是说明输入3(repeat=3)4-2-12310004-9-11-83531输出min=-123min=-9min=1#includeintmain(void){inti,min,n,x;intrepeat,ri;scanf("%d",&repeat);for(ri=1;ri<=repeat;ri++){scanf("%d",&n);scanf("%d",&x);min=x;for(i=1;i8、){scanf("%d",&x);if(x
7、运算:输入一个正整数n,再输入n个整数,输出最小值。输入输出示例:括号内是说明输入3(repeat=3)4-2-12310004-9-11-83531输出min=-123min=-9min=1#includeintmain(void){inti,min,n,x;intrepeat,ri;scanf("%d",&repeat);for(ri=1;ri<=repeat;ri++){scanf("%d",&n);scanf("%d",&x);min=x;for(i=1;i8、){scanf("%d",&x);if(x
8、){scanf("%d",&x);if(x
此文档下载收益归作者所有