Code 1:

1.

**Write a c program to reverse a given number**
2.

**C program to find reverse of a number**
3.

4.**C program to reverse the digits of a number****R**

**everse of a number in c using while loop**

#include<stdio.h>

int main(){

int num,r,reverse=0;

printf("Enter any number: ");

scanf("%d",&num);

while(num){

r=num%10;

reverse=reverse*10+r;

num=num/10;

}

printf("Reversed of number: %d",reverse);

return 0;

}

Sample output:

Enter any number: 12

Reversed of number: 21

Code 2:

**1. Reverse very large or big numbers beyond the range of long int**

**2. Reverse five digit number c program**

Logic is we accept the number as string

#include<stdio.h>

#define MAX 1000

int main(){

char num[MAX];

int i=0,j,flag=0;

printf("Enter any positive integer: ");

scanf("%s",num);

while(num[i]){

if(num[i] < 48 || num[i] > 57){

printf("Invalid integer number");

return 0;

}

i++;

}

printf("Reverse: ");

for(j=i-1;j>=0;j--)

if(flag==0 && num[j] ==48){

}

else{

printf("%c",num[j]);

flag =1;

}

return 0;

Sample output:

Enter any positive integer: 234561000045645679001237800000000000

Reverse: 8732100976546540000165432

Code 3:

**1. C program to reverse a number using for loop**

**2. How to find reverse of a number in c**

**3. Wap to reverse a number in c**

#include<stdio.h>

int main(){

int num,r,reverse=0;

printf("Enter any number: ");

scanf("%d",&num);

for(;num!=0;num=num/10){

r=num%10;

reverse=reverse*10+r;

}

printf("Reversed of number: %d",reverse);

return 0;

}

Sample output:

Enter any number: 123

Reversed of number: 321

Code 4:

1.

**C program to reverse a number using recursion**
#include<stdio.h>

int main(){

int num,reverse;

printf("Enter any number: ");

scanf("%d",&num);

reverse=rev(num);

printf("Reverse of number: %d",reverse);

return 0;

}

int rev(int num){

static sum,r;

if(num){

r=num%10;

sum=sum*10+r;

rev(num/10);

}

else

return 0;

return sum;

}

Sample output:

Enter any number: 456

Reverse of number: 654

1. Write a c program to reverse any number.

2. Write a c program to find out sum of digit of given number.

2. Write a c program to find out sum of digit of given number.

10. Write a c program to find out NCR factor of given number.

11. How to convert string to int without using library functions in c

12. Program in c to print 1 to 100 without using loop

13. C program for swapping of two numbers

14. Program to find largest of n numbers in c

15. Split number into digits in c programming

16. C program to count number of digits in a number

11. How to convert string to int without using library functions in c

12. Program in c to print 1 to 100 without using loop

13. C program for swapping of two numbers

14. Program to find largest of n numbers in c

15. Split number into digits in c programming

16. C program to count number of digits in a number

better.........

ReplyDeleteits helping me a lost

ReplyDeleteu can avoid recursion by directly writing this code

ReplyDeletewhile(num!=0)

{

r=num%10;

sum=sum *10 + r

num=num/10;

}

take num=12

ReplyDeletenow r=12%10=2

sum=0*10+2=2

num=12/10=1

now num becomes 1

r=1%10=1

sum=2*10+1=21

num=1/10=0 so now 0>0 does not satisfy

printf("%d",sum)

so reverse of 12 is 21

@raj this logic only possible for upto 9nums

ReplyDelete/*i think i hv a b8r code.....*/

ReplyDelete#include

main()

{

int a,b,c,d,e;

printf("Enter the Number to Find it's Reverse\n");

scanf("%d",&a);

while(a!=0)

{

b=a%10;

c=a/10;

printf("%d",b);

a=c;

}

}

your program is so easy to understand. thanks kapil bhai

Deletevery good

Deletekapil's prog is great and easy

ReplyDeleteit is good but not perfect

ReplyDeleteyours s good but

ReplyDeletein some case ther will some need to hav zero in 1st digit

like 1230 we need to get 0321

yours cant do that,..???

Hi sangeerth,

ReplyDeleteIn code 2 instead of

for(j=i-1;j>=0;j--)

if(flag==0 && num[j] ==48){

}

else{

printf("%c",num[j]);

flag =1;

}

Write only

for(j=i-1;j>=0;j--)

printf("%c",num[j]);

These programs to reverse a number are not workin in the case of numbers which ends with zeor . Please help. for example if we input 320 the reverse shows 23 only not zero at the beginning.

ReplyDeleteZero at the beginning of a number has no value anyways.

Delete@alida: because the reverse of 320 is 023 and the zero at the front of a whole number is ignored because it is not significant.

ReplyDelete@alida: because the reverse of 320 is 023 and the zero at the front of a whole number is ignored because it is not significant.

ReplyDeletewow wonderful..............dennis ritche is very happy in heaven

ReplyDelete/*U can write a 'c' program to search details of a person (simple program)*/

ReplyDelete#include

#include

#include

void main()

char n;

int p==2429;

printf("Enter a name);

scanf("%s",n);

printf("Password please");

if(n==khirod&&p==2429)

{

printf("details of khirod");

}

if(n==giri&&p==2429)

{

printf("details of giri");

}

{

.

.

.

.

.

}

getch();

}

hay frnz any body tell me which one video tutorial cd(disk) is best . where i will purchase it

ReplyDeletewrite a C program to calculate area and perimeter of circle according to user choice by using switch statement.

ReplyDeletegive me the answer as soon as possible

thank you

These links may help you:

DeleteC PROGRAM TO CALCULATE AREA OF A CIRCLE

Write a c program to find the perimeter of a circle

: Write a program that prints the following pattern.

ReplyDelete*

* *

* * *

* * * *

* * * * *

* * * * * *

#include

Deleteint main()

{

int row,i,j;

printf("Enter the row:");

scanf("%d",&row);

for(i=1;i<=row;i++){

for(j=1;j<=i;j++){

printf("*");

}

printf("\n");

}

getch();

return 0;

}

i am needs this programme.i hope you will help me......

ReplyDeleteWrite a program which adds two arrays with the help of their pointers.

ReplyDeleteUsing your method if u will calculate the reverse of 10 or 100 or 1000 and so on ...then it will return 1 and 1 and 1 respectively so on .it can not show 01 , 001 , 0001 as reverse.

ReplyDeletethanks but can you logics for using this code i.e:

ReplyDeleter=no%10;

no=no/10;

rno=rno*10+r;

if(num[i] < 48 || num[i] > 57)......

ReplyDeleteplz explain this condition ......

num[i] will return ASCII value of that character. ASCII value of '0' is 48 and '9' is 57.

Deletesome programs have errors

ReplyDeleteProgram to reverse a very large number.

ReplyDelete#include

#include

main()

{

char str[100];

int i, j;

scanf("%s",str);

for(i = strlen(str)-1; i >= 0; i--)

printf("%c",str[i]);

}

This comment has been removed by the author.

ReplyDeletedevlop an algorithm to find reverse of the given number.

ReplyDeletewhy the 1 code is not reversing the number 12345 to 54321...??????????

ReplyDeleteit should revrse all the numbers less than 32767 which is int max value..

ReplyDeletethis program won't work for 000002 as it's reverse shall be 200000 but the answer comes out to be 2.... please someone help me with this....

ReplyDeletewhy need of flag?? and why to take char ??cant we do it for large numbers..widout char??

ReplyDelete*

ReplyDelete***

*****

*******

*********

pls giv me the code for thiz...

void main()

Delete{

int r,c;

for(r=0;r<5;r++)//for row

{

for(c=0;c<=r*2;c++)

{

printf("*");

}

printf("\n");

}

}