C语言求奇数和
发布网友
发布时间:2022-11-13 03:33
我来回答
共2个回答
热心网友
时间:2024-10-21 13:06
#include <stdio.h>
int main( )
{
int ri, repeat;
int x, sum;
scanf("%d", &repeat);
for(ri=1; ri<=repeat; ri++){
scanf("%d", &x);
sum=0;
while (x!=-1&&x!=0)
{
sum+=x%2?x:0;
scanf("%d",&x);
}
printf("%d\n", sum);
}
}
热心网友
时间:2024-10-21 13:06
#include <stdio.h>
int main( )
{
int ri, repeat;
int x, sum;
scanf("%d", &repeat);
int m[repeat]
for(ri=0; ri<repeat; ri++)
{
while (true)
{
scanf("%d", &x);
if(x>0)
{
if(x/2==1)
m[ri]+=x;
}
else
break;
}
}
for (int i=0;i<repeat;i++)
{
printf("%d\n", m[i]);
}
}