C++作业(五)

项目一  成绩

#include<iostream.h>  
void main()  
{  
    double ave;    
    int score[10],a,b,c,sum=0,x=0,y=0;  
    cout<<"小组同学的成绩"<<endl;    
    for(c=0;c<10;c++)    
        cin>>score[c];    
    a=score[0];    
    for(c=1;c<9;c++)    
        if(a<score[c])    
            a=score[c];  
    for(c=1;c<9;c++)  
        if(a==score[c])    
            a++;      
        {    
        b=score[0];    
    for(c=1;c<10;c++)
		    sum=sum+score[c];    
            if(b<score[c])    
                b=score[c];    
    for(c=1;c<10;c++)    
                if(score[c]==b)    
                    y++;      
            ave=sum/10.0;    
        }    
        cout<<"该组最高成绩为"<<a<<'\n'<<endl;    
        cout<<"该组最低成绩为"<<b<<'\n'<<endl;    
        cout<<"平均成绩为"<<ave<<endl;    
}    
项目二    数组分离

#include<iostream.h>    
void main()    
{    
    int a[10],b[10]={0},c[10]={0},x,y,z;  
    cout<<"请输入10个数"; 
    for(x=0;x<10;x++)    
        cin>>a[x];    
    for(x=0,y=0,z=0;x<10;x++)    
    {    
        if(a[x]%2)    
            b[y++]=a[x];   
        else c[z++]=a[x];    
    }    
    for(x=0;x<y;x++)    
        cout<<"奇数是"<<b[x];    
    cout<<endl;    
    for(x=0;x<z;x++)   
        cout<<"偶数是"<<c[x]; 
    cout<<endl;    
}    

项目三    求和

#include<iostream>      
using namespace std;      
int main()      
{   
    double a=0,b=0; 
    int c[10],x; 
    cout<<"请输入10个数:";  
    for(x=0;x<10;x++)  
    {  
        cin>>c[x];  
        if(c[x]>0)  
            a=c[x];  
        if(c[x]<0)  
            b=c[x];  
  
    }  
    cout<<"正数的和为:"<<a<<endl;  
    cout<<"负数的和为: "<<b<<endl;
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值