航電oj2006-2008參考代碼

2006 求奇數的乘積

#define _CRT_SECURE_NO_WARNINGS 1c++

#include <stdio.h>ide

int main()
{code

int n,num,ret;
while(scanf("%d",&n)!=EOF)
{
    getchar();
    ret = 1;
    for(; n>0; n--)
    {
        scanf("%d",&num);
        if(num%2!=0)
            ret *= num;
    }
    printf("%d\n",ret);
}
return 0;

}get

---------------------------------------------------------------------------------

2007 平方和與立方和

#define _CRT_SECURE_NO_WARNINGS 1it

#include <stdio.h>
int my_math1(int x,int y)
{io

int i;
int sum = 0;
for(i=x; i<=y; i++)
{
    if(i%2==0)      //偶數平方和
        sum += i*i;
}
return sum;

}
int my_math2(int x,int y)
{class

int i;
int sum = 0;
for(i=x; i<=y; i++)
{
    if(i%2)         //奇數立方和
        sum += i*i*i;
}
return sum;

}統計

int main()
{di

int m,n,x,y,temp;
while(scanf("%d%d",&m,&n)!=EOF)
{
    getchar();
    if(m>n)//保證m小於n
    {
        temp = m;
        m = n;
        n = temp;
    }
    x = my_math1(m,n);
    y = my_math2(m,n);
    printf("%d %d\n",x,y);
}
return 0;

}view

---------------------------------------------------------------------------------

2008 數值統計

#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>
int main()
{

int n,a,b,c,num;
while(scanf("%d",&n)!=EOF)
{
    getchar();
    a = 0;
    b = 0;
    c = 0;
    if(n==0)
        break;
    else
    {
        for(; n>0; n--)
        {
            scanf("%f",&num);
            if(num<0)
                a++;//負數
            else if(num>0)
                c++;//正數
            else
                b++;//零
        }
        printf("%d %d %d\n",a,b,c);
    }
}
return 0;

}

相關文章
相關標籤/搜索