航电oj2006-2008参考代码
作者:互联网
2006 求奇数的乘积
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
int main()
{
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;
}
---------------------------------------------------------------------------------
2007 平方和与立方和
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
int my_math1(int x,int y)
{
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)
{
int i;
int sum = 0;
for(i=x; i<=y; i++)
{
if(i%2) //奇数立方和
sum += i*i*i;
}
return sum;
}
int main()
{
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;
}
---------------------------------------------------------------------------------
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;
}
标签:SECURE,int,航电,scanf,oj2006,ret,num,2008,my 来源: https://blog.51cto.com/14221754/2631111