1. Write a menu driven program to
take a number and choice as input
print reverse of the number if choice
is 'R' print factorial of number if
choice is 'F' print count of digit of
number if choice is 'C' print sum of
digit of number if choice is 'S' print
'wrong choice's otherwise.
Answers
Answered by
3
class hi
{
public void main(int n, chat ch)
{
int d, rev=0, i, f=1, c=0;
switch(ch)
{
case'R':
while(n>0)
{
d=n%10;
rev=rev*10+d;
n/=10;
}
System. out. println("Reverse="+rev) ;
break;
case'F':
for(i=1; i<=n; i++)
{
f*=i;
}
System. out. println("Factorial="+f) ;
break;
case'C':
while(n>0)
{
d=n%10;
c++;
n/=10;
}
System. out. println("No. of digits="+c) ;
break;
case'S':
while(n>0)
{
d=n%10;
s+=d
n/=10;
}
System. out. println("Sum of digits="+s) ;
break;
default:
System. out. println("wrong choice") ;
}
}
}
Similar questions