LIVE Course for free

Rated by 1 million+ students
Get app now
0 votes
123 views
in Computer by (35 points)
edited by

Write a program that reads ten integers, and then prints the sum of the even and odd integers separately using suitable messages

Please log in or register to answer this question.

1 Answer

0 votes
by (21.7k points)

#include <stdio.h>

void main()
{
int i, num, odd_sum = 0, even_sum = 0;

printf("Enter the value of num\n");
scanf("%d", &num);
for (i = 1; i <= num; i++)
{
if (i % 2 == 0)
even_sum = even_sum + i;
else
odd_sum = odd_sum + i;
}
printf("Sum of all odd numbers = %d\n", odd_sum);
printf("Sum of all even numbers = %d\n", even_sum);
}

output :

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...