Sunday 5 August 2012

Loop control structure001


Write a program to print all the number from one to ten (intrger).

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

void main ( )
{
        int          a = 1;
        clrscr ( );
        
        while ( a <= 10 )
        {                  
                  printf ("\n\n %d ",a);
                  a = a + 1;
        }                
        getch( );
}

Different method

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

void main ( )
{
        int          a = 1;
        clrscr ( );
         
        do
        {        
                printf ("\n\n %d ",a);
                a = a + 1;
        }while ( a <= 10 );
       
        getch( );
}

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...