码迷,mamicode.com
首页 > 其他好文 > 详细

第六章 编程练习

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

标签:style   blog   io   ar   color   os   sp   for   on   

第一题

 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 }

 

  

第六章 编程练习

标签:style   blog   io   ar   color   os   sp   for   on   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!