Discover a world of knowledge at Westonci.ca, where experts and enthusiasts come together to answer your questions. Our Q&A platform offers a seamless experience for finding reliable answers from experts in various disciplines. Explore comprehensive solutions to your questions from knowledgeable professionals across various fields on our platform.

Write the code for a program that takes in an integer from the user and then calculates
the sum of all the numbers from 1 to the integer entered by the user. For example,
suppose the user entered the number 4; now, the output should be 10.


Sagot :

Answer:

Explanation:

#include<stdio.h>

#include<conio.h>

int main(){

int a,b=1,sum=0;

printf("Enter the number:");

scanf("%d",&a);

while(b<=a){

sum=sum+b;

b=b+1;

}

printf("The sum is %d\n",sum);

getch();

}

We appreciate your time. Please come back anytime for the latest information and answers to your questions. We hope this was helpful. Please come back whenever you need more information or answers to your queries. Stay curious and keep coming back to Westonci.ca for answers to all your burning questions.