Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.
Login
Login
OnlineGDB Q&A
Questions
Unanswered
Tags
Ask a Question
Ask a Question
find the sum of all numbers upto n
+1
vote
asked
Apr 2, 2020
by
NAVYA SRI MUTHINENI
(
140
points)
Please
log in
or register to answer this question.
8 Answers
0
votes
answered
Apr 4, 2020
by
Bilal
(
170
points)
#include<stdio.h>
int main (){
int i,n,sum=0;
printf("Please enter a number:");
scanf("%d",&n);
for(i=1;i<=n;i++){
sum=sum+i;
}
printf("Sum of all number to n is : %d",sum);
return 0;
}
Please
log in
or register to add a comment.
0
votes
answered
Apr 4, 2020
by
Prabhat Nayak
(
220
points)
//i am doing by using c language
#include<stdio.h>
void main()
{
int i,n,sum;
printf("enter value of n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
sum+=i;
}
printf("sum is %d",sum);
}
Please
log in
or register to add a comment.
0
votes
answered
Apr 4, 2020
by
pjvendhan
(
140
points)
n=int(input("enter the last number ypu want:"))
sum=0
for i in range(0,n):
sum+=i
print(sum)
Please
log in
or register to add a comment.
+1
vote
answered
Apr 5, 2020
by
Luigi Rodorigo
(
280
points)
uint32_t sum(uint32_t n) { return n*(n+1)/2; // thank you gauss! }
Please
log in
or register to add a comment.
0
votes
answered
Apr 5, 2020
by
Frenst
(
140
points)
// same result without loop for
#include <stdio.h>
int main()
{
int i,n,sum=0,sum1=0;
printf("Please enter a number:");
scanf("%d",&n);
sum=(n+1)*n/2;
printf("Sum of all number to n is : %d",sum);
return 0;
}
Please
log in
or register to add a comment.
0
votes
answered
Apr 5, 2020
by
Manav Changela
(
190
points)
I used a simple formula from Arithmetic Progression
#include<stdio.h>
void main()
{
int n,sum;
printf("ENTER VALUE OF n:");
scanf("%d",&n);
sum=0.5*n*(1+n);
printf("\n sum=%d",sum);
}
Please
log in
or register to add a comment.
0
votes
answered
Apr 6, 2020
by
1916114
(
260
points)
#include <stdio.h>
int main
{
int a,i,c=0;
printf("ENTER THE NUMBER");
scanf("%d",&a0;
for(i=0;i<=a;i++)
c=c+i;
printf("the required sum%d",c);
return 0;
}
Please
log in
or register to add a comment.
0
votes
answered
Apr 6, 2020
by
Anmol Jain
(
150
points)
#include<stdio.h>
void main()
{
int i,n ,sum=0;
printf("Enter the number:");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
sum=sum+i;
}
printf("The sum of numbers upto 'n' is %d",sum);
}
Please
log in
or register to add a comment.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...