Write the following functions that: (2 ½ X 4 =10)
a) Request the user to input a 5 digit number and reverse the given number and print it.
b) Request the user to input two floats and outputs the largest of the inputs.
c) Request the user to input an integer and, if the number is divisible by two, divides it by
two, otherwise multiplies it by three and output the result.
d) Request the user for three integers and output whether any of them are equal. Use only
one if-else-statement
Write a C (main) program to provide the above functions as options to the user using
switch statement and perform the functions accordingly.
Answers
Answer:
hioiiioiiiiiiiii[◇•♡●♤》□¡¤¡¤♡○♡○◇•
Answer:
#include<stdio.h>
#include<conio.h>
char option;
void reverse_number(int);
void largest_number(float,float);
void dividemulti(int);
void find_equal(int,int,int);
menu()
{
printf(" \n(a) Reverse Number.");
printf("\n(b) Find Largest Number");
printf ("\n(c) Divide Number.");
printf("\n(d) Find Equal Number" );
printf("\nEnter option A OR B OR C OR D");
scanf("%c",&option);
}
void reverse_number(int num)
{
int rem=0;
printf("Reverse Number is \t");
while(num>0)
{
rem=num%10;
num=num/10;
printf("%d",rem);
}
}
void dividemulti(int a)
{
int num;
if(a%2==0)
{
a=a/2;
printf("Number is divisble by 2 Result is%d",a);
}
if(a%2!=0)
{
a=a*3;
printf("Number is Not divisible by 2 so the Result after Multiply by 3 is%d",a);
}
}
void largest_number(float a, float b)
{
if(a>b)
{
printf("A is Largest Number\t %f",a);
}
eles
if(a<b)
{
printf("B is Largest Number\t %f",b);
}
}
void find_equaI(int n1,int n2,int n3)
{
if(n1==n2 && n1!=n3 || n1==n3 && n1!=n2 || n2==n1 && n2!=n3 || n2==n3 && n2!=n2 || n3==n1 && n3!=n2 || n3==n2 && n3!=n1)
{
printf("\nPrintf NUMBER ARE EQUAL");
}
else
{
printf("\nNumber is not Equal");
}
}
void main()
{
int n,num1,a 1,b1,c1;
float a,b;
clrscr();
menu();
switch(option)
{
case'a':
{
printf("Enter Number\n");
scanf("%d",&n);
reverse_number(n);
break;
}
case ’b':
{
printf("Enter Two float Numbers\n");
scanf("%f%f",&a,&b);
largest_number(a,b);
break;
}
case 'c':
{
printf("Enter Number ");
scanf("%d",&num1);
dividemulti(num1);
break;
}
case 'd':
{
printf("Enter Three number");
scanf("%d%d%d",&a1,&b1,&c1);
find_equal(a1,b1,c1);
break;
}
default:
{
printf("INVALID OPTION");
}
}
getch();
}
Idk if it will work properly