//__ Let me
demostrate you how to make menu :D :D :D :D
#include<iostream>
#include<conio.h>
#include<stdlib.h> //__ system("cls")
using namespace std;
char
prime_number(int number);
void
prime_function();
void
factorial_function();
int fact(int number);
int
add_number();
int main()
{
int choice = 0;
cout << "\n\n\n\t\t\t __
Menu __ ";
cout << "\n\n\t\t1.
Factorial of a Number";
cout << "\n\n\t\t2.
Prime Number between 1 to 50";
cout << "\n\n\t\t3. Sum
of first 10 Numbers";
cout << "\n\n Enter your good choice Mam - ";
cin >> choice;
switch(choice)
{
case 1: system("cls"); //__ To clear the screen ___
factorial_function();
break;
case 2: system("cls");
prime_function();
break;
case 3: system("cls");
cout << "\n\n\t\t__
Add numbers from 1 to 10\n\n Result -
";
cout << add_number();
break;
}
//__ lets start
getch();
return 0;
}
void
prime_function()
{
int counter = 0;
char result;
cout << "\n\n\t\t
___ Prime numbers between 1 to 50 ____\n\n\n\n
Prime Number - \n\n ";
for(counter = 1; counter <=
50; counter++)
{
result = prime_number(counter);
if (result == 'Y')
{
cout << counter << " , ";
}
}
cout << "\b\b ";
getch();
}
char
prime_number(int number)
{
int counter = 1, count = 0;
while(counter < number)
{
if ((number % counter) ==
0)
{
count++;
}
counter++;
}
if (count == 1)
{
return 'Y';
}
else
{
return 'N';
}
}
void
factorial_function()
{
int num,fac;
cout<<"\n\n\t
________Factorial of A Number_______\n\n";
cout << " Enter the Number -
";
cin>>num;
fac=fact(num);
cout<<"\n\n\t Factorial of " << num
<< " is " << fac
<< "\n";
getch();
}
int fact(int number)
{
//int result=1;
// if(number < 1)
// {
// cout<< "\n\n\t\t Please enter Positive Integer";
// }
// else
// {
// for(int i=1;i<=number;i++)
// {
// result=result*i;
// }
// }
// return result;
if (number == 1)
{
return 1;
}
else
{
return number *
fact(number - 1);
}
}
int
add_number()
{
int number = 1, sum = 0;
for(number = 1; number <=
10; number++)
{
sum = sum + number;
}
return sum;
}
No comments:
Post a Comment