标签:
#include<iostream.h> void main() { const int n=10; int i,j,k=0,b[n],m=0,a[n]; cout<<"请输入10个数,空格键隔开"; for(i=0;i<n;i++) { cin>>a[i]; } cout<<"不重复的数是"; for(i=0;i<n;i++) { for(j=0;j<n;j++) { if(a[i]==a[j]) k++; } if(k==1) { b[m]=a[i]; m++; } k=0; } if(m>0) { for(i=0;i<m;i++) cout<<b[i]<<" "; cout<<endl; } else cout<<"b[n]为空"<<endl; }
#include<iostream.h> void main() { const int n=100; int a[n]; int i,j,min,max,n1=0,n2=0,sum=0,number; double average; cout<<"请输入“人数”并按enter键继续"; cin>>number; cout<<"请输入成绩,空格键隔开"; for(i=0;i<number;i++) { cin>>a[i]; if(a[i]<0 || a[i]>100) { cout<<"输入成绩有误"; number=0; break; } } if(number!=0) { min=a[1]; max=a[1]; for(i=0;i<number;i++) { if(a[i]>max) max=a[i]; if(a[i]<min) min=a[i]; } for(i=0;i<number;i++) { sum=sum+a[i]; if(a[i]==max) n1++; if(a[i]==min) n2++; } average=double(sum)/number; cout<<"最高分是"<<max<<"有"<<n1<<"人"<<" "<<"最低分是"<<min<<"有"<<n2<<"人"<<" "<<"平均分是"<<average<<endl; } }
#include<iostream.h> void main() { const int n=10; int a[n]={1,-1,2,-2,3}; int i,sum1=0,sum2=0; cout<<"请输入10个数,空格键隔开"; for(i=0;i<n;i++) { cin>>a[i]; } for(i=0;i<n;i++) { if(a[i]>0) sum1=sum1+a[i]; else if(a[i]<0) sum2=sum2+a[i]; } cout<<"正数的和是"<<sum1<<" "<<"负数的和是"<<sum2<<endl; }
标签:
原文地址:http://blog.csdn.net/czkzg/article/details/51346833