Question
MUST BE WRITTEN IN C PLEASE KEEP IT SIMPLE. I AM NEW AT PROGRAMMING. 1. Write a loop that reads positive integers from standard input
MUST BE WRITTEN IN C
PLEASE KEEP IT SIMPLE. I AM NEW AT PROGRAMMING.
1. Write a loop that reads positive integers from standard input and that terminates when it reads an integer that is not positive. After the loop terminates, it prints out the sum of all the even integers read and the sum of all the odd integers read. Declare any variables that are needed
WHAT I HAVE
int number=0, sum_even=0, sum_odd=0;
while (number>=0)
{
printf("enter a positive number (negative number to terminate) :");
scanf("%d",&number);
if(number<=0)
break;
else
if(number%2 == 0)
sun_even+=number;
else
sum_odd+=number;
}
printf(" sum of all even numbers : %d",sum_even);
printf(" sum of all odd numbers : %d",sum_odd);
2. Given an int variable n that has already been declared, write some code that repeatedly reads a value into n until at last a number between 1 and 10 (inclusive) has been entered.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started