In: Computer Science
Write a c program that prints the final sum of all values from 1 to n only when n is a positive value. The program is to print "Poor!" when the final sum is less than 70, print "Good" when the sum is between 71 and 90. or "Great!" when the sum is 91 or better.
Program Code Screenshot:
Sample output:
The screenshots are attached below for reference.
Please follow them for proper indentation and output.
Program to
copy:
#include <stdio.h>
int main()
{
int n,i;
int s=0;
printf("Enter value of n : ");
scanf("%d",&n);//read input number
if(n>0){//if it is positive number
for(i=1;i<=n;i++){
s=s+i;//get sum
}
}
printf("The final sum is %d\n",s);//print sum
if(s<70)
printf("Poor!");//print message on console based on value of
sum
else if(s>=71 && s<90)
printf("Good!");
else if(s>=91)
printf("Great!");
return 0;
}
Note:
Please let me know in case of any help needed in the comments section.
Plese upvote my answer. Thank you.