C++ program to find prime number in C++
#include
#include
void main()
{
clrscr();
int number,count=0;
cout<<"Enter number to check it is prime
or not ";
cin>>number;
for(int
a=1;a<=number;a++)
{
if(number%a==0)
{
count++;
}
}
if(count==2)
{
cout<<" Prime number \n";
}
else
{
cout<<" Not a prime number \n";
}
getch();
}
Program take hours, minutes, seconds and print it in 24
hours & 12 hours format
#include
#include
void main()
{
clrscr();
int hours,mins,seconds,x;
cout<<"Enter hours=";
cin>>hours;
cout<<"\nEnter
minutes=";
cin>>mins;
cout<<"\nEnter
seconds=";
cin>>seconds;
if(hours > 24)
{
cout<<"Invalid
Entery";
}
else
{
cout<<"\n24
Hours Format\n";
cout<<"Hours
: Mins : Seconds\n"<<"
"<
if(hours > 12)
{
hours=hours-12;
cout<<"12 Hours Format\n";
cout<<"Hours
: Mins : Seconds\n"<<"
"<
}
else
{
cout<<"12
Hours Format\n";
cout<<"Hours :
Mins : Seconds\n"<<"
"<
}
}
}
Program to find greatest number between 3 number
using if else statement
#include
using namespace std;
int main()
{
int num1,num2,num3;
cout<<" Enter value for first
number";
cin>>num1;
cout<<" Enter value for second
number";
cin>>num2;
cout<<" Enter value for third
number";
cin>>num3;
if(num1>num2&&num1>num3)
{
cout<<" First number is
greatest:"<
}
else if(num2>num1&&num2>num3)
{
cout<<" Second number is
greatest"<
}
else
{
cout<<" Third number is
greatest"<
}
return 0;
}
C++ program to find factorial of number in c++
#include
#include
using namespace std;
int main()
{
int num,factorial=1;
cout<<" Enter number to find its factorial: ";
cin>>num;
for(int a=1;a<=num;a++)
{
factorial=factorial*a;
}
cout<<"Factorial of given number is ="<
return 0;
}
#include
using namespace std;
int main()
{
int num,factorial=1;
cout<<" Enter number to find its factorial: ";
cin>>num;
for(int a=1;a<=num;a++)
{
factorial=factorial*a;
}
cout<<"Factorial of given number is ="<
}
No comments:
Post a Comment