Saturday, 7 July 2012

c program to reverse a number using (do-while,for loop)

For beginners
{I am going write the c program but before you need a c compiler.there are a lot of compilers. like dev c++  Download Code::Blocks, dev c++ its free and install it in your computer.open  dev c++ go to file-->new-->source file.} 


#include<stdio.h>
#include<conio.h>
main()
{
    int rn,n;
    printf("enter a number\n");
    scanf("%d",&n);
    do
    {
                  rn=n%10;
                  printf("%d",rn);
                  n=n/10;
                  }while(n!=0);
                  getch();
                  } 
or

#include<stdio.h>
#include<conio.h>
main()
{
    int rn,n;
    printf("enter a number\n");
    scanf("%d",&n);
    for(n=n;n!=0;n=n/10)
    {
                  rn=n%10;
                  printf("%d",rn);
                  }getch();
                  }



For beginners
{After typing this program go to execute-->compile & run-->a window will pop-up-->give file name:(anything u like)-->save as type: c source files-->click save.}

IS IT HELPFIL? comment.

1 comment: