12D I need help writing this program; Please use horizontal and vertical spacing
ID: 3625069 • Letter: 1
Question
12DI need help writing this program; Please use horizontal and vertical spacing. This is a C program not (C ++ program)
Write a program that will prompt the user for how many times your program should loop.
Store the result in the int variable howmany
Set sum equal to 0
Set counter equal to 1
While (counter is less than or equal to howmany)
sum = sum + counter
counter = counter + 1
End loop
(Notice that even though you will be writing a for loop the pseudocode uses a while loop structure)
Tell the user the sum of the numbers 1 to howmany equals sum
Thank the user for using your program
Exit your program with a return statement
Explanation / Answer
please rate - thanks
#include <stdio.h>
#include <conio.h>
int main()
{int howmany,sum=0,counter;
printf("How many times to loop? ");
scanf("%d",&howmany);
for(counter=1;counter<=howmany;counter++)
sum=sum+counter;
printf("The sum of the numbers from 1 to %d is %d ",howmany,sum);
getch();
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.