Monday 6 August 2012

Loop control structure002


Write a program to print all the number from one to five (intrger) along with the sum.

#include <stdio.h>
#include <conio.h>


void main ( )
{
        int            a = 1, s = 0;
        clrscr ( );

        while ( a <= 5 )
        {              
                     printf ("\n\n %d ",a);
                     s = s + a;
                     a = a + 1;
        }
        printf ("\n SUM = %d",s);
        getch( );


No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...