Wap to accept a number and reverse it. using If, else
Answers
Answered by
1
Example: Reverse an Integer
#include <stdio.h> int main() { int n, reversedNumber = 0, remainder; printf("Enter an integer: "); scanf("%d", &n); while(n != 0) { remainder = n%10; reversedNumber = reversedNumber*10 + remainder; n /= 10; } printf("Reversed Number = %d", reversedNumber); return 0; }
#include <stdio.h> int main() { int n, reversedNumber = 0, remainder; printf("Enter an integer: "); scanf("%d", &n); while(n != 0) { remainder = n%10; reversedNumber = reversedNumber*10 + remainder; n /= 10; } printf("Reversed Number = %d", reversedNumber); return 0; }
Answered by
0
int a,b;
printf("Enter a number");
scanf("%d",&a);
b = c(b);
printf("The reverse of this number : %d", b);
return 0;
}
int c(int b)
{
static d,e;
if(b)
{
e = b%10;
d = d * 10 + e;
c(b/10);
}
else
return 0;
return d;
}
Hope this helps!
printf("Enter a number");
scanf("%d",&a);
b = c(b);
printf("The reverse of this number : %d", b);
return 0;
}
int c(int b)
{
static d,e;
if(b)
{
e = b%10;
d = d * 10 + e;
c(b/10);
}
else
return 0;
return d;
}
Hope this helps!
Similar questions
Math,
1 year ago
Economy,
1 year ago
Chemistry,
1 year ago
Social Sciences,
1 year ago
Physics,
1 year ago