标签:
项目1:数组分离
#include<iostream> using namespace std; int main() { int a[10],b[10],c[10],i; cout<<"请输入10个整数:"<<endl; for(i=0;i<10;i++) cin>>a[i]; for(i=0;i<10;i++) { if(a[i]%2!=0) { cout<<"奇数为:"; b[10]=a[i]; cout<<b[10]<<endl; } else { cout<<"偶数为:"; c[10]=a[i]; cout<<c[10]; } } return 0; }
项目3:成绩
#include<iostream> using namespace std; int main() { int score[10]; double aver; cout<<"请按学号输入小组成员成绩"<<endl; for(int i=0;i<10;i++) { cout<<"第"<<i<<"号同学成绩为:"; cin>>score[i]; if (score[i]>100||score[i]<0) cout<<"出错"<<endl; } int max=0,min=100,total=0; for(i=0;i<10;i++) { total+=score[i]; if(max<score[i]) max=score[i]; if(min>score[i]) min=score[i]; } aver=total/10.0; cout<<"最高成绩为:"<<max<<"分"<<endl; cout<<"最低成绩为:"<<min<<"分"<<endl; cout<<"平均成绩为:"<<aver<<"分"<<endl; int maxNum=0,minNum=0; for(i=0;i<10;i++) { if(max==score[i]) maxNum++; if(min==score[i]) minNum++; } cout<<"小组最高成绩为:"<<max<<"分,共有 "<<maxNum<<" 人,他们的学号是:"; for(i=0; i<10; i++) { if(max==score[i]) cout<<i<<" "<<","; } cout<<endl; cout<<"小组最低成绩为:"<<min<<"分,共有 "<<minNum<<" 人,他们的学号是:"; for(i=0; i<10; i++) { if(min==score[i]) cout<<i<<" "<<","; } cout<<endl; return 0; }
项目5:求和
#include<iostream> using namespace std; int main() { double a[10],sum1=0,sum2=0; cout<<"请输入十个数"<<endl; for(int i=0;i<10;i++) { cin>>a[i]; } for(i=0;i<10;i++) { if(a[i]>0) sum1+=a[i]; else if (a[i]<0) sum2+=a[i]; } cout<<"所有正数和为"<<sum1<<endl; cout<<"所有负数和为"<<sum2<<endl; return 0; }
标签:
原文地址:http://blog.csdn.net/zewen96/article/details/51317815