Question

Write a program that reads a set of integers and then finds and prints the sum...

Write a program that reads a set of integers and then finds and prints the sum of the even and odd integers

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Sol: As the language is not mentioned so i giving the code in c


#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 :

Add a comment
Know the answer?
Add Answer to:
Write a program that reads a set of integers and then finds and prints the sum...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT