Question

In: Computer Science

Write a c program that prints the final sum of all values from 1 to n...

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.

Solutions

Expert Solution

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.


Related Solutions

Programming in C++ Write a program that prints the values in an array and the addresses...
Programming in C++ Write a program that prints the values in an array and the addresses of the array’s elements using four different techniques, as follows: Array index notation using array name Pointer/offset notation using array name Array index notation using a pointer Pointer/offset notation using a pointer Learning Objectives In this assignment, you will: Use functions with array and pointer arguments Use indexing and offset notations to access arrays Requirements Your code must use these eight functions, using these...
Write a c++ program that prints the count of all prime numbers between A and B...
Write a c++ program that prints the count of all prime numbers between A and B (inclusive), where A and B are defined as follows: A = Any 5 digit unique number B = A + 1000 Just a recap on prime numbers: A prime number is any number, greater or equal to 2, that is divisible ONLY by 1 and itself. Here are the first 10 prime numbers: 2, 5, 7, 11, 13, 17, 19, 23, and 29. Rules:...
Write a C++ program to read N numbers. Find sum, product, and average of N numbers
Write a C++ program to read N numbers. Find sum, product, and average of N numbers
Write a short main program that reads an integer n from standard input and prints (to...
Write a short main program that reads an integer n from standard input and prints (to standard output) n lines of * characters. The number of *’s per line should double each time, starting with 1. E.g., if n = 5, the output should be as follows: * ** **** ******** ****************
Write a program called x.c that reads an integer n from standard input, and prints an...
Write a program called x.c that reads an integer n from standard input, and prints an nxn pattern of asterisks and dashes in the shape of an "X". You can assume n is odd and >= 5. Solve this problem using only while loop. Solution: ./x Enter size: 5 *---* -*-*- --*-- -*-*- *---* ./x Enter size: 9 *-------* -*-----*- --*---*-- ---*-*--- ----*---- ---*-*--- --*---*-- -*-----*- *-------* ./x Enter size: 15 *-------------* -*-----------*- --*---------*-- ---*-------*--- ----*-----*---- -----*---*----- ------*-*------ -------*------- ------*-*------...
Write a program that prints the sum of its command-line arguments (assuming they are numbers). For...
Write a program that prints the sum of its command-line arguments (assuming they are numbers). For example, java Adder 3 2.5 -4.1 should print The sum is 1.4
• Write a C++ program to find the largest umber, smallest number and sum of all...
• Write a C++ program to find the largest umber, smallest number and sum of all the element of a given array of 20 integers • Note − Declare array to 20 numbers − Input values for 20 array elements − Find largest number − Find smallest number − Find sum of all numbers • Display the results
Write a program that prompts a user for an integer from 1 to 99 and prints...
Write a program that prompts a user for an integer from 1 to 99 and prints it as an amount in words. The program will loop in case the user wants to input an additional number. If the user enters -99, the program will exit. Example: Input: 89 Output: Eighty nine Input: 45 Output: Fourty five Input: -99 Output: Have a nice day. <program exits> For this project, you are to: 1) You should validate any data coming from the...
Write a program that prompts a user for an integer from 1 to 99 and prints...
Write a program that prompts a user for an integer from 1 to 99 and prints it as an amount in words. The program will loop in case the user wants to input an additional number. If the user enters -99, the program will exit. Example: Input: 89 Output: Eighty nine Input: 45 Output: Fourty five Input: -99 Output: Have a nice day. <program exits> c++ project. need help.
a). Write a program that asks the user to enter an integer N and prints two...
a). Write a program that asks the user to enter an integer N and prints two integers, root and power, such that 1 < power < 6 and N = root ** power. If no such pair of integers exists, it should print a message to that effect. There are two loops, one for power and one for root. Order the loops so that if N = 64, then your program find that N = 8 ** 2 rather than...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT