收藏 分销(赏)

练习5(answer).doc

上传人:pc****0 文档编号:7822871 上传时间:2025-01-19 格式:DOC 页数:5 大小:33KB 下载积分:10 金币
下载 相关 举报
练习5(answer).doc_第1页
第1页 / 共5页
练习5(answer).doc_第2页
第2页 / 共5页


点击查看更多>>
资源描述
练习 1.求1~100的偶数的和; #include <iostream> using namespace std; int main() { int i=1,sum=0; while(i<=100) { if(i%2==0)sum+=i; i++; } cout<<sum<<endl; return 0; } 2、从键盘连续输入字符,直到输入“回车”符为止, 统计输入的字符中’A’个数。 #include<iostream> using namespace std; int main() { int count=0; char ch; cout<<"Please a sentence,then press enter:"; ch=getchar(); while(ch!='\n') { if(ch=='A')count++; ch=getchar(); } cout<<"count="<<count<<endl; return 0; } 4.p86 第6题 #include <iostream> using namespace std; int main () {char c; int letters=0,space=0,digit=0,other=0; cout<<"enter one line::"<<endl; while((c=getchar())!='\n') {if (c>='a' && c<='z'||c>='A' && c<='Z') letters++; else if (c==' ') space++; else if (c>='0' && c<='9') digit++; else other++; } cout<<"letter:"<<letters<<", space:"<<space<<", digit:"<<digit<<", other:"<<other<<endl; return 0; } 3. 输出九九乘法表 1*1=1 1*2=2 2*2=4 1*3=3 2*3=6 3*3=9 …… 1*9=9 2*9=18 3*9=27 …… 9*9=81 #define N 9 #include <iostream> using namespace std; int main( ) { int i,j; for(i=1;i<=N;i++) { for(j=1;j<=i;j++ ) { cout<<i<<"*"<<j<<"=" <<i*j<<" "; } cout<<'\n'; } return 0; } 4. 输出以下图形 当N=4时,输出 * *** ***** ******* #include<iostream> using namespace std; int main() { int i,j; for(i=1;i<=4;i++) { for(j=1;j<=8-2*i; j++) cout<<' '; for(j=1;j<=2*i-1;j++) cout<<'*'; cout<<endl; } return 0; }
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 百科休闲 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服