63 155
Assignments Done
99,3%
Successfully Done
In July 2018

Answer to Question #45351 in C for Kate

Question #45351
5. Write a program that uses while loops to perform the following steps:
a. Prompt the user to input two integers: firstNum and secondNum (firstNum must be less than secondNum).
b. Output all odd numbers between firstNum and secondNum.
c. Output the sum of all even numbers between firstNum and secondNum.
d. Output the numbers and their squares.
e. Output the sum of the square of the odd numbers between firstNum and secondNum.

Thanks
Expert's answer
#include <stdio.h>
int main() {
int firstNum, secondNum, sumEven = 0, sumSqaureEven = 0;
printf("Please enter the firstNum and secondNum\n");
scanf("%d %d", &firstNum, &secondNum);
if ( firstNum> secondNum ) {
  printf("First number should be less than second\n");
  return 0;
}
printf("Even numbers:\n");
for ( int i = firstNum; i <= secondNum; i++ ) {
  if ( i % 2 == 0 ) {
sumEven += i;
  } else {
printf("%d ", i);
sumSqaureEven += i*i;
  }
}
printf("\nSum of all even numbers is %d\n", sumEven);
for ( int i = firstNum; i <= secondNum; i++ ) {
  printf("Number : %d Square version:%d\n", i, i*i);
}
printf("Sum of all  sqaures of odd numbers is %d\n", sumSqaureEven);
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions