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.

plz tell me the coding of this question

0 votes
asked Oct 30, 2017 by Fizza Sajjad (300 points)
Q: find the sum of n natural numbers?

4 Answers

0 votes
answered Nov 2, 2017 by Kelsi Riley (140 points)
int sumofnatural(int n)
{
    int sum = 0;
    for (int i = 0; i < n; i++)
    {
        sum += i;
    }
    return sum;
}
commented Nov 3, 2017 by Fizza Sajjad (300 points)
you give  wrong coding i was run this code on turbo then it gives error like(/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status)
commented Nov 4, 2017 by Kelsi Riley (140 points)
This is a function that you would have to call in main. Example
#include <stdio>

int main()
{
    cout << sumofnatural(9) <<endl;
    return 0;
}
commented Nov 5, 2017 by Fizza Sajjad (300 points)
oky i wil try it
commented Nov 5, 2017 by Fizza Sajjad (300 points)
in which city you can belong are you a programmer
commented Jan 24, 2018 by Robayet Al Hamim (270 points)
are you a programmer? xD @questioner
0 votes
answered Nov 8, 2017 by anonymous
o recorde mundial de velocidade no solo e de 1228 km/h atingindo por um carro movido a jato essa velociade no SI seria de
commented Apr 7, 2019 by anonymous
yes iam a programmer
 fiya
0 votes
answered Nov 8, 2017 by anonymous
#include <stdio.h>
int main()
{
    int n, i, sum = 0;
    
    printf("Enter a positive integer: ");
    scanf("%d",&n);

    for(i=1; i <= n; ++i)
    {
        sum += i;   // sum = sum+i;
    }

    printf("Sum = %d",sum);

    return 0;
}

commented Nov 8, 2017 by Fizza Sajjad (300 points)
sorry if you dont mind i dont understand your language can you plz explain in english:D
commented Nov 8, 2017 by anonymous
expected output

Enter a positive integer: 8                                                                                           
Sum = 36                                                                                                              
                                                                                                                      
...Program finished with exit code 0                                                                                  
Press ENTER to exit console.
commented Nov 8, 2017 by Fizza Sajjad (300 points)
thank you so much
0 votes
answered Nov 14, 2017 by anonymous

int sumofnatural(int n)
{
    return n*(n+1)/2;
}

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...