I have this code wich makes 100 numbers random from 1 to 1000:
int Array[100];
for (int i=0; i %26lt; 100; ++i)
{
Array[i] = rand()%1000 + 1;
}
I need to make a code that totals the odd numbers only
Need more help with a C++ code?
int Array[100],i=0,sum=0,rem;
for (i=0; i %26lt; 100; ++i)
{
Array[i] = rand()%1000 + 1;
}
for(i=0,rem=0;i%26lt;100;i++)
{
rem=array[i]%2;
if(rem!=0)
{
sum=sum+array[i];
}
}
cout%26lt;%26lt;"\n"%26lt;%26lt;sum;
Reply:add after int array
long total = 0;
add this in the for loop
if(Array[i]%2 == 1){
total = total + Array[i];
}
hope this helps
Reply:array[i] = IHOPness+ sum;odd)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment