//WAP TO SHOW THE FUNCTIONING OF "switch case "statement.
#include
#include
void main()
{
long int fact=1,num,i,ch;
clrscr();
while(1)
{
printf("\n\n1.FACTORIAL");
printf("\n\n2.TO CHECK THE NO.FOR PRIME");
printf("\n\n3.TO CHECK THE NO.FOR EVEN OR ODD");
printf("\n\n4.TO EXIT");
printf("\n\n5.ENTER YOUR CHOICE=");
scanf("%li",&ch);
switch(ch)
{
case 1:
printf("\nENTER THE NUMBER=");
scanf("%li",&num);
for(i=1;i<=num;i++)
fact=fact*i;
printf("\n\n\nFACTORIAL OF A NUMBER=%li",fact);
break;
case 2:
printf("\nENTER THE NUMBER=");
scanf("%d",&num);
i=2;
while(i<=num-1)
{
if(num%i==0)
{
printf("\n\n\nENTERED NO.IS NOT A PRIME NO.");
break;
}
i++;
}
if(i==num)
printf("\n\n\nENTERED NUMBER IS A PRIME NUMBER");
break;
case 3:
printf("\nENTER THE NUMBER=");
scanf("%d",num);
if(num%2==0)
printf("NUMBER ENTERED IS A EVEN NUMBER");
else
printf("NUMBER ENTERED IS A ODD NUMBER");
break;
case 4:
exit() ;
getch();
}}}
/******OUTPUT******
1.FACTORIAL
2.TO CHECK THE NO.FOR PRIME
3.TO CHECK THE NO.FOR EVEN OR ODD
4.TO EXIT
5.ENTER YOUR CHOICE=1
ENTER THE NUMBER=5
FACTORIAL OF A NUMBER=120
1.FACTORIAL
2.TO CHECK THE NO.FOR PRIME
3.TO CHECK THE NO.FOR EVEN OR ODD
4.TO EXIT
5.ENTER YOUR CHOICE=2
ENTER THE NUMBER=3
ENTERED NUMBER IS A PRIME NUMBER
1.FACTORIAL
2.TO CHECK THE NO.FOR PRIME
3.TO CHECK THE NO.FOR EVEN OR ODD
4.TO EXIT
5.ENTER YOUR CHOICE=3
ENTER THE NUMBER=2
NUMBER ENTERED IS A ODD NUMBER
1.FACTORIAL
2.TO CHECK THE NO.FOR PRIME
3.TO CHECK THE NO.FOR EVEN OR ODD
4.TO EXIT
5.ENTER YOUR CHOICE=4
Null pointer assignment
*/
No comments:
Post a Comment