Write a program to fill the entire screen with a smiling face. The smiling face has an ASCII value 1.
Write a program to fill the entire screen with a smiling face. The smiling face has an ASCII value 1.
- Get link
- X
- Other Apps
/*Program to find factorial of a number, the number is prime or not ,the number is odd or even,exit
Author: Knowledge desk , Date: Decmber10,2020*/
#include<stdio.h>
#include<conio.h>
main()
{
int num;
printf("Enter 1 to find factorial of a number.");
printf("Enter 2 to find number is prime or not.");
printf("Enter 3 to find number is odd or even.");
printf("Enter 4 to exit.");
clrscr();
printf("Enter a value :");
scanf("%d",&num);
switch(num)
{
case 1:
printf("\nYou enter 1 to find the factorial of a number");
// Program to find factorial of a number //
{
int n,i,fact=1;
printf("\nEnter an integer:");
scanf("%d",&n);
if(n < 0)
{
printf("\nfactorial of anegative number does not exist.");
}
else
{
for(i=1;i<=n;i++)
{
fact *= i;
}
printf("\nThe factorial for %d =%11u",n,fact);
}
}
break;
case 2:
printf("\nYou enter 2 to find the number is prime or not");
// Program to find the number is prime or not//
{
int num,count = 0, i;
printf("\nEnter a digit to find the prime number :");
scanf("%d",&num);
for(i=2;i<=num/2;i++)
{
if(num%i==0)
{
count++;
}
}
if (count == 0)
{
printf("\n\nThe number is prime %d.",num);
}
else
{
printf("\n\nThe number is not prime %d.",num);
}
}
break;
case 3:
printf("\nYou enter 3 to find odd or even.");
// Program to find odd or even //
{
int num;
printf("\nEnter a number to find odd or even :");
scanf("%d",&num);
if(num%2==0)
{
printf("\nThe number is even.%d",num);
}
else
{
printf("\nThe number is not even.%d",num);
}
}
break;
case 4:
printf("\n You enter 4 to exit ");
exit(0);
break;
default :
printf("\n Please enter a valid number");
}
getch();
return(0);
}
Comments
Post a Comment