-->

WAP to get reverse of a number using function.

using turboc++
--------------------------------------------------------------------------------------------
//program to get reverse of a number using function.use no arguments and return some value

#include<stdio.h>                      //header file
#include<conio.h>
int reverse();                          // function prototype/declaration with return type zero.
int main()                              //main function
{
printf("reverse =%d",reverse());            // function callingwith output.
getch();
return 0;                                       //returns 0 value
}
int reverse()                              // function body line ; also called function definition
{
int s=0,rem;                             //initialization to value 1
 int n;                                       // variable declaration
 printf("enter a number\n");
 scanf("%d",&n);                            //input
for(;n!=0;)                     //loop running from 1 to 100 with increment 1 each time
{
    rem=n%10;               //finding remainder
    s=s*10+rem;
    n=n/10;                 //finding next integer number and trasnforming that into 'n'
}
 
return s;            //returning value       
}






---------------------------------------------------------------------------------------------------------------
using codeblocks:
-------------------------------
//program to get reverse of a number using function.use no arguments and return some value

#include<stdio.h>                      //header file
int reverse();                          // function prototype/declaration with return type zero.
int main()                              //main function
{
printf("reverse =%d",reverse());            // function callingwith output.
return 0;                                       //returns 0 value
}
int reverse()                              // function body line ; also called function definition
{
int s=0,rem;                             //initialization to value 1
 int n;                                       // variable declaration
 printf("enter a number\n");
 scanf("%d",&n);                            //input
for(;n!=0;)                     //loop running from 1 to 100 with increment 1 each time
{
    rem=n%10;               //finding remainder
    s=s*10+rem;
    n=n/10;                 //finding next integer number and trasnforming that into 'n'
}
 
return s;            //returning value       
}

No comments:

Post a Comment