In: Computer Science
Design and implement an application that reads an integer value and prints the sum of all even integers between 2 and the input value, inclusive. Print an error message if the input value is less than 2 and prompt accordingly so that the user can enter the right number. Your program file will be called YourLastNameExamQ2
*Since programming language is not specified, I coded this program in 'C'.
*I have used online compiler to execute the code.. and the output screenshot is shared below.
*I have written the program for sum of all even numbers taking the range as inclusive as mentioned(i.e.., 2 and the input value are not considered).
CODE:
#include <stdio.h>
int main()
{
int num;
int flag=1,i,total=0;
while(flag){
printf("\nenter the integer number greater than 2: ");
scanf("%d",&num);
if(num<=2){
printf("\nerror!!! input value is not greater than 2.. try
again");
}
else{
flag=0;
}
}
for(i=3; i<num; i++){
if(i%2==0){
total=total+i;
}
}
printf("\nThe total sum of even numbers in the inclusive
range(2,%d) is %d",num,total);
return 0;
}
OUTPUT: