Question: In C Language Write a program that computes the sum of the first n even inte- gers and the sum of the first n odd

In C Language

Write a program that computes the sum of the first n even inte- gers and the sum of the first n odd integers. The value for n should be entered interactively. Use the bottom two codes

for (cnt = 0, i = 1, j = 2; cnt < n; ++cnt, i += 2, j+= 2)

odd_sum =+ i, even_sum =+ j;

------------------------------------------------------------------------

do {

printf("Input a positive integer: ");

scanf("%d", &n);

if (error = (n <= 0))

printf(" ERROR: Do it again! ");

} while (error);

------------------------------------------------------------------------

Then write another version of the program that uses a while statement instead of a do statement to accomplish the same effect.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!