We are asked to input 10 integers where in we need to display:
1. The sum of all the odd numbers
2. The sum of all the even numbers

I do not know how to make a statement and i do not know whether to use for or while and also i do not know where it just going to compute for the sum of odd or even. :(( please help. :((

## All 8 Replies

Well we're not writing the code for you. What have you written so far?

To calculate even or odd numbers you would use the modulus operator and for your loop, you could use either a while or a for loop.

``````#include<stdio.h>
#include<conio.h>
main()
{
int a,b,c,d,e,f,g,h,i,j,sume,sumo;
printf("Enter 10 integers: \n");
scanf("%d%d%d%d%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f,&g,&h,&i,&j);``````

I had written this far. I really do not know what to do next about only adding the inputted odd or even integers. :D I thank you for not giving the code and teaching me.

modulus? really? but i don't know how the modulus can display the remainder? and also the code for it. :(

``````#include<stdio.h>
#include<conio.h>
main()
{
int a,b,c,d,e,f,g,h,i,j,sume,sumo;
printf("Enter 10 integers: \n");
scanf("%d%d%d%d%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f,&g,&h,&i,&j);``````

I had written this far. I really do not know what to do next about only adding the inputted odd or even integers. :D I thank you for not giving the code and teaching me.

modulus? really? but i don't know how the modulus can display the remainder? and also the code for it. :(

instead declare an array of integers.

``````#include <stdio.h>
#include<conio.h> // don't use it, there's no need of it and is not portable

int main(void) {// main should always return int

int numbers[10];//an array of 10 integers
int i;
printf("enter 10 integers separated by space or newline\n");
for(i=0;i<10;i++){
scanf("%d",&numbers[i]);
}
return 0;
}``````
``````#include<stdio.h>
#include<conio.h>

int main()
{
int a[10];
int i;
int esum=0,osum=0; // One for even sum and one for odd sum
printf("\n Enter 10 numbers : ");
for(i=0;i<10;i++)
scanf("%d",&a[i]);
for(i=0;i<10;i++)
{
if(a[i]%2==0)
esum=esum+a[i];
else
osum=osum+a[i];
}
printf("\n Even numbers sum is : %d",esum);
printf("\n Odd numbers sum is : %d\n",osum);
}``````

Try to work this program u will get the output what u required

it works! thanks. :D but i still don't know how does it work. :( could you please explain it? especially the this parts

``int esum=0,osum=0;``

why is it equal to 0? :D

``````for(i=0;i<10;i++)
scanf("%d",&a[i]);
for(i=0;i<10;i++)
{
if(a[i]%2==0)
esum=esum+a[i];
else
osum=osum+a[i];``````

why are there 2 for? is it one for even and odd? and why is it that the first one only has scanf?
and what is a? is it the same as multiplication? sorry for asking too many questions, i really do not understand it. :((
could you please explain and teach me? thank you. :)

int a[10];

is an array of integers which will store 10 elements and you don't need to store values in different elements.
a[0] to a[9] = 10 elements.

for(i=0;i<10;i++)

basic syntax:--
for(initialization;condtion;increment/decrement)
is a loop which start from i=0 till i reaches 10 means the block will execute 10 times for the value of incrementing i.

scanf("%d",&a);

is for taking input for different values of i's.
when i=0 ,i<10(in the condition part of loop) so true and value will be stored in a[0].
lly for i=1 scanf() inputs in a[1] and so for i<10 means upto i[9].
i.e 10 values are stored in a[0] to a.

loop and array is for not using of differnt variables.

again for accessing the values in a. need of for loop from i=0 to i=9 i.e i<10

now even numbers are divisible by 2.
% operator checks the remainder part means 4 % 2 =0
and 5 % 2 =1.

if(a % 2==0 ), means even number.
store the sum in another variable esum

now when we write int a; a block in memory at some address is allocated in memory named a. at that time some garbage value is stored at that address, so if its not initialized to zero then that garbage value will be added and desired output will not come.
so esum=0 and osum =0;

Ummmm....U need to study the basic concepts of C.Sorry We are not here to teach, you have to learn by yourself but we can help you in your part of code which you have difficulties.
follow the book The C programming language by K & R.

sorry about the teaching part,i forgot. :D my professor does not teach us and if he do, it is not that good and DIFFICULT TO UNDERSTAND and sometimes he just gives us the notes but do not explain it, so we are really on our own. BUT I REALLY APPRECIATE what you did. THANK YOU! :) sorry for bothering you.

I can understand ur problem. I think ur the beginner of programming language. Here a[10] means -----> a is an array name which can store 10 values. This program can write without using arrays. So, that's why i send another code for u..........

``````#include<stdio.h>
#include<conio.h>

int main()
{
int h;// How many numbers do u want to read its ur wish
int a;//Storing all numbers
int esum=0,osum=0;//one for even sum and one for odd sum
printf("\n How many numbers : ");
/*Now here to start to give the input number....
And u give much more numbers ......*/
scanf("%d",&h);
print("\n Enter %d numbers : ",h);
while(h>0)
{