Assignment#1 Solution
Assignment#1 Solution
#include<iostream.h>
bool prime(int);
void main()
{
int r;
int a;
if(r==false)
cout<<"The number is not prime"<<endl;
else
cout<<"The number is prime"<<endl;
bool prime(int c)
{
return true;
}
FACTORIAL
#include<iostream.h>
int factorial(int);
void main()
{
int a;
cout<<"Enter a number: ";
cin>>a;
if (a<0)
cout<<"Factorial of zero or less than zero is not possiable"<<endl;
else
cout<<"The factorial of "<<a<<" is "<<factorial(a)<<endl;
int factorial(int a)
{
int fact=1;
for(int i=1;i<=a;i++)
fact=fact*i;
return fact;
}
AND, OR, XOR Operations
# include <iostream.h>
int main()
{
int a[10],b[10],c[10],choice;
while (choice!=-1)
{
cout<<"\n Which of the operations do you want to perform."<<endl;
cout<<"(1) AND GATE "<<endl;
cout<<"(2) OR GATE "<<endl;
cout<<"(3) XOR GATE "<<endl;
cout<<"Select the operation or press -1 to exit: ";
cin>>choice;
switch (choice)
{
case 1:
{
break;
}
case 2:
{
break;
}
case 3:
{
}
}
}
return 0;
}