find the sum of first N natural numbers

sum of first N natural numbers



void main()


int s=0,i=1,n;


printf("Enter a value ");


while(i <= n)





printf("Sum of first %d natural numbers is %d",n,s)




NB: // ---> this is a comment. compiler will not execute the statements after this '//'.

#include<stdio.h> --------> header file

void main() --------------> main function

int s=0 -------> variable declaration & value assigning

clrscr() -----> built-in function for clearing the screen

printf() -----> built-in function for print a message and print the output.

scanf() ------> built-in funtion for accepting a value

getch() ------> built-in function for accepting a character.

for running the program you should press Ctrl + F9 keys together.


thanking you.

hope u get the result....... :-)

More by this Author

Comments 5 comments

Ishan 6 years ago

In the last printf statment u missed a semi-colon.

shijo 6 years ago

give an output also

kirti shinde 4 years ago

it's a very easy. it is understand lauguage.

jewel 2 years ago


jewel mathew pm 2 years ago


    Sign in or sign up and post using a HubPages Network account.

    0 of 8192 characters used
    Post Comment

    No HTML is allowed in comments, but URLs will be hyperlinked. Comments are not for promoting your articles or other sites.

    Click to Rate This Article