首页 > 其他 > 详细

第六章 编程练习

时间:2014-12-07 23:01:06      阅读:299      评论:0      收藏:0      [点我收藏+]

第一题

 1 #include<iostream>
 2 #include<cctype>
 3 using namespace std;
 4 int main()
 5 {
 6     char arr[80];
 7     char ch;
 8     cin.getline(arr,80);
 9     int i=0;
10     ch=arr[0];
11     while((ch!=@)&&(i<=80))
12     {
13         if((ch>=a)&&(ch<=z))cout<<char(toupper(ch));
14         else if((ch>=A)&&(ch<=Z))cout<<char(tolower(ch));
15         else cout<<ch;
16         i++;
17         ch=arr[i];
18     }
19     return 0;
20 }

第二题

 1 #include<iostream>
 2 #include<cctype>
 3 using namespace std;
 4 int main()
 5 {
 6     double temp;
 7     double donation[10];
 8     double sum=0;
 9     int count=0;
10     double ave=0;
11     int i;
12     for(i=0;i<10&&cin>>temp;i++)
13     {
14         donation[i]=temp;
15         sum+=donation[i];
16     }
17     ave=sum/i;
18     for(int j=0;j<i;j++)
19     {
20         if(donation[j]>ave)count++;
21     }
22     if(i!=10)cout<<"input error"<<endl;
23     cout<<"the number of digit you have input "<<i<<endl;
24     cout<<"ave="<<ave<<endl;
25     cout<<"count="<<count<<endl;
26     return 0;
27 }

 

  

第六章 编程练习

原文:http://www.cnblogs.com/taoxiuxia/p/4149971.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!