Vous êtes sur la page 1sur 4

1.

Write a C++ Program to design a Easy Calculator


#include<iostream.h>
#include<conio.h>
#include<A.h>
void main()
{
long double x,y;
char ch,ar;
do
{
clrscr();
cout<<"
*WELCOME TO JIT'S CALCULATOR*
";
cout<<"
This is a Calculator containing the following functions

Addition
Subtraction
Multiplication
Division
Percentage

Power
";
cout<<"
Type
[+] for Addition
[-] for Subtraction
[*] for
Multiplication
[/] for Division
[%] for Percentage
[^] for
Power";
cout<<"Enter Function To use = ";
cin>>ch;
cout<<(char)7;
cout<<endl;
//For Addition
if(ch=='+')
{
clrscr();
cout<<"You are using Addition";
cout<<"Enter First Number= ";
cin>>x;

cout<<"Enter Second Number= ";


cin>>y;

cout<<"Your answer is ";


cout<<x+y;
cout<<(char)7;
}
// For Subtraction
if(ch=='-')
{
clrscr();
cout<<"You are using Subtraction";
cout<<"Enter First Number= ";
cin>>x;
cout<<"Enter Second Number= ";
cin>>y;
cout<<"Your answer is ";
cout<<x-y;
cout<<(char)7;
}
// For Multiplication
if(ch=='*')
{
clrscr();
cout<<"You are using Multiplication";
cout<<"Enter First Number= ";
cin>>x;
cout<<"Enter Second Number= ";
cin>>y;
cout<<"Your answer is ";
cout<<x*y;
cout<<(char)7;
}
// For Division
if(ch=='/')
{
clrscr();
cout<<"You are using Division";
cout<<"Enter First Number= ";
cin>>x;
cout<<"
Enter Second Number= ";
cin>>y;
cout<<"
Your answer is ";
cout<<x/y;
cout<<(char)7;
}
// For Percentage
if(ch=='%')
{
clrscr();
cout<<"You are using Percentage";
cout<<"Enter Number= ";
cin>>x;
cout<<"Enter Percentage= ";
cin>>y;
cout<<"Your answer is ";
cout<<y/100*x;
cout<<(char)7;
}
//For Power
if(ch=='^')
{
clrscr();
cout<<"You are using Power";
cout<<"Enter Number= ";
cin>>x;
cout<<"Enter Power= ";
cin>>y;
cout<<"Your answer is ";
cout<<pow(x,y);
cout<<(char)7;
}
cout<<endl;
cout<<"Do you want to continue..Y/N?";
cin>>ar;

}
while(ar=='Y'|| ar=='y');
if(ar=='N' || ar=='n')
{
cout<<"Thankyou for using this Calculator.Good Bye.";
cout<<"Press any key to exit.......";
}

getch();
cout<<(char)7;

2. Write a C++ PROGRAM TO PRINT ALL POSSIBLE PERMUTATIONS OF


FIRST N NAUTURAL NOs

#include<iostream.h>
#include<conio.h>
#include<string.h>

int count=0;

//func to display the sequence


void dis(char a[],int n)
{
for(int jk=n-1;jk>=0;jk--)
{
cout<<a[jk];
}
cout<<"";
}

//function to left shift last n elements


//of the array by one position
void shift(char a[],int n)
{
char s;
s=a[n-1];
for(int i=n-1;i>0;i--)
a[i]=a[i-1];
a[0]=s;
}

//func to find all possible arrangements


void per(char a[],int m,int n)
{
for(int i=0;i<m;i++)
{
if(m>1)
{
shift(a,m);
per(a,m-1,n); //genetrating the tree
}
else
{
dis(a,n); //displaying the leaf nodes of the tree
count++;
}
}
}

void main()
{
// char *a;
int n;
clrscr();

cout<<"Enter a no : ";
cin>>n;

char *a = new (char[n]);

for(int i=0;i<n;i++)
a[i] = n-i+48;

// dis(a,n);

cout<<"Possible permutations are :


";
per(a,n,n);
cout<<"Total No Of Permutations Is "<<count;
getch();
}

/**************************************/
OUTPUT
------

Enter a no : 3
Possible permutations are :
213
231
321
312
132
123
Total No Of Permutations Is 6
/**************************************/

Vous aimerez peut-être aussi