Search & Find out

Saturday, November 21, 2009

Sum of 1 to 'n' numbers

 
        #include "stdio.h"
        #include"conio.h"



        void main()
        {
            int i,sum=0,n;
            clrscr();
            printf("Enter the number:\t");
            scanf("%d",&n);
            clrscr();


            for(i=1;i<=n;i++)
            {
                printf("%d\n",i);
                sum=sum+i;
            }


            printf("The sum of the integers is %d",sum);


        getch();
    }

0 comments:

Post a Comment

 

My Blog List

Term of Use