第一题
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 }
时间: 2024-10-05 22:22:26