ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel
  • »
  • Technology»
  • Computers & Software»
  • Computer Science & Programming

find the sum of first N natural numbers

Updated on March 22, 2010

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....... :-)


    0 of 8192 characters used
    Post Comment

    • profile image

      jewel mathew pm 3 years ago


    • profile image

      jewel 3 years ago


    • profile image

      kirti shinde 5 years ago

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

    • profile image

      shijo 7 years ago

      give an output also

    • profile image

      Ishan 7 years ago

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