Question #243866

 LOOP: (TURBOc++)


PRG14. Write a program that will accept 10 numbers, identify if the number is odd or even, then finds the sum of all odd numbers, all even numbers, and total of all the numbers entered.

 


PLEASE USE:

#include<stdio.h>

#include<conio.h>


scanf

printf

 


example:

#include<stdio.h>

#include<conio.h>

main()

{

int n=1, x=20;

clrscr();

printf("While Loop Example");


while (n<=5)

{

gotoxy(x, 3);printf(" %d", n);

n++;x=x+5;

}

getch();

}


Expert's answer

#include <stdio.h>
#include <stdlib.h>
#include<conio.h>
int main()
{
    int i, x; 
    int oddSum=0,evenSum=0;
    printf("Enter the ten numbers:\n");
    for(i=0; i<10; i++){
    scanf("%d",&x);
        if(x%2==0)
            evenSum=evenSum+x;
        else
            oddSum=oddSum+x;


    }
    printf("Sum of all odd numbers are: %d",oddSum);
    printf("\nSum of all even numbers are: %d",evenSum);
    int total=
    printf("\nSum of all entered numbers are:%d",oddSum+evenSum);
    getch();
    return 0;
}
LATEST TUTORIALS
APPROVED BY CLIENTS