Thursday, 8 December 2016

Program to find LCM of 2 nos.

#include<conio.h>
#include<iostream.h>
void main()
{ clrscr();
  int a,b,c,d,e;
  cout<<"Enter 2 nos. ";
  cin>>a>>b;
  for (int i=a;i>=1;i--)
      { c=a*i;
for (int j=b;j>=1;j--)
   { d=b*j;
     if (c==d)
 e=c;
   }
      }
  cout<<"LCM is "<<e;
  getch();
}

Program to find HCF of 2 nos. usin' Function

#include<conio.h>
#include<iostream.h>
int HCF_of(int x,int y);
void main()
{ clrscr();
  int x,y,z;
  cout<<"Enter 2 nos. ";
  cin>>x>>y;
  z=HCF_of(x,y);
  cout<<"HCF is "<<z;
  getch();
}
int HCF_of(int x,int y)
{ int a,b,c;
  a=x>y?x:y;
  b=x<y?x:y;
  for (int i=1;i<=a;i++)
      { if (a%i==0)
  { if (b%i==0)
c=i;
  }
      }
  return(c);
}

Program to find HCF of 2 nos.

#include<conio.h>
#include<iostream.h>
void main()
{ clrscr();
  int x,y,z,a,b,c;
  cout<<"Enter any 2 nos. ";
  cin>>x>>y;
  z=x<y?x:y;
  a=x>y?x:y;
  for(int i=1;i<=z;i++)
     { b=z%i;
       if (b==0)
 { if (a%i==0)
      { c=i;
      }
 }
     }
  cout<<"HCF is "<<c;
  getch();
}

Friday, 18 November 2016

Another method to print prime nos. in a given range

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

void check_prime (int x,int y);
void main()
{ clrscr();
  int x,y,z;
  cout<<"Enter the range below" ;
  cout<<"From ";
  cin>>x;
  cout<<"To ";
  cin>>y;
  check_prime(x,y);
  getch();
}

void check_prime(int x,int y)
{ int a,b,c,d;
  for(int i=x;i<=y;i++)
     { int ret=0;
       for (int j=1;j<=i;j++)
  { c=i%j;
    if (c==0)
{ ret++;
}
  }
       if (ret==2)
 { cout<<i<<" is a prime no. \n";
 }
     }
getch();
}

Tuesday, 15 November 2016

Q1. 15/11/2016

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

int check_prime(int x);
void main()

{ clrscr();
  int a,b,z;
  cout<<"Enter the range below \n";
  cout<<"From ";
  cin>>a;
  cout<<"To ";
  cin>>b;
  for (int i=a;i<=b;i++)
      { z=check_prime(i);
if (z==1)
  { cout<<i<<" is a prime no. \n ";
  }
      }
  getch();
}

int check_prime(int x)

{ int z,w=0,y=0;

  for (int i=1;i<=x;i++)
      { z=x%i;
if (z==0)
  {w++;
  }
      }
  if (w==2)
     { y=1;
     }
  return(y);
}

Q. WAP to print prime nos. in a given range

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

void main()

{ clrscr();
  float a,b,z;
  cout<<"Enter the range below \n";
  cout<<"From ";
  cin>>a;
  cout<<"To ";
  cin>>b;

  for (int i=a;i<=b;i++)
      { int ret=0;
for (int k=1;k<=i;k++)
   { z=i%k;
     if (z==0)
{ ret++;
}
   }
if (ret==2)
  { cout<<i<<" is a prime no. \n";
  }
      }
  getch();
}

Q2. 11/11/2016

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

float sum_of_series(float x);
void main()

{ clrscr();
  float x,y;
  cout<<"Enter the no. of terms ";
  cin>>x;
  y=sum_of_series(x);
  cout<<"Sum of "<<x<<" terms of series = "<<y;
  getch();
}

float sum_of_series(float x)

{ float z=1,sum=0;

  for(int i=1;i<=x;i++)
     { z=pow(i,i);
       sum=sum+z;
     }
  return(sum);
}

Q1. 11/11/2016

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

float sum_of_series(float x);
void main()

{ clrscr();
  float x,y;
  cout<<"Enter no. of terms ";
  cin>>x;
  y=sum_of_series(x);
  cout<<"Sum of "<<x<<" terms of Series = "<<y;
  getch();
}

float sum_of_series(float x)

{ float sum=0;
  for (int i=1;i<=x;i++)
      { sum=sum+i;
      }

  return(sum);
}

Friday, 4 November 2016

Q. WAF to print Factorial of any entered no.

#include<conio.h>
#include<iostream.h>
float factorial(float x);
void main()
{ clrscr();
  float x,z;
  cout<<"Enter a no. ";
  cin>>x;
  z=factorial(x);
  cout<<"Factorial of "<<x<<" is "<<z;
  getch();
}
float factorial(float x)
{ float z=1;
  for (int i=x;i>=1;i--)
    { z=z*i;
    }
  return (z);
}

Q. WAF to find sum of of digits in a given range

#include<iostream.h>
#include<conio.h>
float sum_of_digits(float a,float b);
void main()
{
clrscr();
int w,x,y;
cout<<"Enter the range below "<<"\n";
cout<<"From (included) ";
cin>>w;
cout<<"To (included) ";
cin>>x;
y=sum_of_digits(w,x);
cout<<"Sum of digits from "<<w<<" to "<<x<<" is "<<y;
getch();
}
 float sum_of_digits(float a,float b)
 {
  int sum=0;
  for (int i=a;i<=b;i++)
     { sum=sum+i;
     }
  return(sum);
  }

Q. WAF to calculate cube of any no.

#include<conio.h>
#include<iostream.h>
float cube_of(float a);
void main()
{
clrscr();
int x,y;
cout<<"Enter a no. ";
cin>>x;
y=cube_of(x);
cout<<"Cube of "<<x<<" = "<<y;
getch();
}
float cube_of(float a)
{
int c;
c=a*a*a;
return(c);
}

Q. WAF to print greatest and smallest among 3 nos.

#include<conio.h>
#include<iostream.h>
int which_is_great(int a,int b,int c);
int which_is_small(int d,int e,int f);
void main()
{
clrscr();
int w,x,y,z,s;
cout<<"Enter 3 nos. ";
cin>>w>>x>>y;
z=which_is_great(w,x,y);
s=which_is_small(w,x,y);
cout<<"Greatest no. = "<<z<<"\n";
cout<<"Smallest no. = "<<s;
getch();
}
int which_is_great(int a,int b,int c)
{
int d;
d=a>b?(a>c?a:c):(b>c?b:c);
return (d);
}
int which_is_small(int d,int e,int f)
{
int a;
a=d<e?(d<f?d:f):(e<f?e:f);
return(a);
}

Q. WAF to calculate average of 3 nos.

#include<conio.h>
#include<iostream.h>
int avg(int a,int b,int c);
void main()
{
clrscr();
int w,x,y,z;
cout<<"Enter three nos. ";
cin>>w>>x>>y;
z=avg(w,x,y);
cout<<"Average = "<<z;
getch();
}
int avg(int a,int b,int c)
{
int z;
z=(a+b+c)/3;
return(z);
}

Thursday, 3 November 2016

Program to Calculate area of a Triangle using Fuction

#include<conio.h>
#include<iostream.h>
float areaoftriangle(float b,float h);
void main()
{
clrscr();
float x,y,z;
cout<<"Enter base of the Triangle ";
cin>>x;
cout<<"Enter height of the Triangle ";
cin>>y;
z=areaoftriangle(x,y);
cout<<"Area of the Triangle = "<<z;
getch();
}
float areaoftriangle(float b,float h)
{
float ar;
ar=0.5*b*h;
return(ar);
}

Sunday, 23 October 2016

Series....5

#include<conio.h>
#include<iostream.h>
void main()
{
clrscr();
for(int i=1;i<=4;i++)
{  for(int j=1;j<=i;j++)
   { cout<<i;
   }
   cout<<"\n";
}
getch();
}

Series...4

#include<conio.h>
#include<iostream.h>
void main()
{
clrscr();
for (char a='L';a<='O';a++)
{  for(char b='L';b<=a;b++)
   { cout<<b;
   }
   cout<<"\n";
}
getch();
}

Series...3

#include<conio.h>
#include<iostream.h>
void main()
{
clrscr();
for (int i=10;i>=7;i--)
{  for (int j=10;j>=i;j--)
   { cout<<j;
   }
   cout<<"\n";
}
getch();
}

Series....2

#include<conio.h>
#include<iostream.h>
void main()
{
clrscr();
for(char ab='A';ab<='D';ab++)
{ for (char cd='A';cd<=ab;cd++)
  { cout<<cd;
  }
  cout<<"\n";
}
getch();
}

Series....1

#include<conio.h>
#include<iostream.h>
void main()
{
clrscr();
for (int i=4;i>=1;--i)
{  for (int j=1;j<=i;++j)
   {cout<<"*";
   }
   cout<<"\n";
}
getch();
}

Monday, 17 October 2016

HHW Q14. WAP to print all the factors of an entered no. and also calculate no. of factors .

#include<conio.h>
#include<iostream.h>
void main()
{
clrscr();
int a,b,c=0,d;
cout<<"Enter the no. ";
cin>>a;
for(int i=1;i<=a;i++)
{ b=a%i;
  if (b==0)
  { cout<<i<<"\n";
    c++;
  }
}
if (c==2)
{cout<<"This is a prime no. ";
}
else
{ cout<<"Nos. of factors = "<<c;
}
getch();
}

HHW Q12. WAP to enter a no. and calculate its some of digits .

#include<conio.h>
#include<iostream.h>
void main()
{
clrscr();
long int a,b,c,d,e,f,g,h,i,j;
cout<<"Enter the no. ( max 5 digits) ";
cin>>a;
b=a/10000;
c=a/1000;
d=c%10;
e=a/100;
f=e%10;
g=a/10;
h=g%10;
i=a%10;
j=b+d+f+h+i;
cout<<"Sum of the digits = "<<j;
getch();
}

HHW Q10. WAP to find the second largest no. among 3 entered nos.

#include<conio.h>
#include<iostream.h>
void main()
{
clrscr();
int a,b,c,d;
cout<<"a=";
cin>>a;
cout<<"b=";
cin>>b;
cout<<"c=";
cin>>c;
d=a>b?(a>c?c:a):(b>c?c:b);
cout<<d<<" is second largest ";
getch();
}

HHW Q6. WAP to check whether a no. is prime or not .

#include<conio.h>
#include<iostream.h>
void main()
{
clrscr();
int a,b=0,n;
cout<<"Enter the no. = ";
cin>>n;
for (int i=1;i<=n;i++)
{ a=n%i;
  if (a==0)
     { b++;
     }
}
if (b==2)
{ cout<<n<<" is a Prime no. ";
}
else
{ cout<<n<<" is not a prime no. ";
}
getch();
}

Sunday, 16 October 2016

HHW Q16. WAP to print Simple Interest.

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int p,r,t,si;
cout<<"Enter the Principal amount ";
cin>>p;
cout<<"Enter the rate ";
cin>>r;
cout<<"Enter time (in years);
cin>>t;
si=(p*r*t)/100;
cout<<"Simple interest = "<<si;
getch();
}

HHW Q23. WAP to print month name on entering month no.

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a;
cout<<"Enter month no. ";
cin>>a;
switch (a)
{case 1:
cout<<"January ";
braek;
case 2:
cout<<"February";
break;
case 3:
cout<<"March";
break;
case 4:
cout<<"April";
break;
case 5:
cout<<"May";
break;
case 6:
cout<<"June";
break;
case 7:
cout<<"July";
break;
case 8:
cout<<"August";
break;
case 9:
cout<<"September";
break;
case 10:
cout<<"October";
break;
case 11:
cout<<"November";
break;
case 12:
cout<<"December";
break;
default:
cout<<"Enter correct month no. ";
break;
}
getch();
}  

HHW Q33B. WAP to print series 1,4,27........

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a=1,b,n;
cout<<"Enter the no. of terms ";
cin>>n;
for(int i=1;i<=n;i++)
{ if (a%2==0)
     { b=a*a;
       cout<<b<<"\n";
       a=a+1;
     }
  else
     { b=a*a*a;
       cout<<b<<"\n";
       a=a+1;
     }
}
getch();
}

HHW Q33A. WAP to print series 1,-4,7,-10.....

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a=1,b,c,n;
cout<<"Enter the no. of terms ";
cin>>n;
for (int i=1;i<=n;i++)
{ if (i==1)
     { cout<<a<<"\n";
     }
  else
     { if (i%2==0)
 { a=a+3;
   a=a*(-1);
   cout<<a<<"\n";
 }
       else
 { a=a*(-1);
   a=a+3;
   cout<<a<<"\n";
 }
     }
}
getch();
}

HHW Q29. WAP to print Fibonacci series .

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int x=-1,y=1,z,n;
cout<<"Enter no. of terms ";
cin>>n;
for (int i=1;i<=n;i++)
{ z=x+y;
  cout<<z<<"\n";
  x=y;
  y=z;
}
getch();
}

HHW Q26. WAP to print roots of a Quadratic equation .

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c,d,x1,x2;
cout<<"Enter coefficient of x^2 (a) ";
cin>>a;
cout<<"Enter coefficient of x (b) ";
cin>>b;
cout<<"Enter constant term (c) ";
cin>>c;
d=b*b-(4*a*c);
if (d<0)
{ cout<<"Roots of the equation are imaginary ";
}
if (d==0)
{ x1=((-b)+d)/2;
  cout<<"Roots of the equation are real and equal "<<"\n";
  cout<<" Roots = "<<x1;
}
if (d>0)
{ x1=((-b)+d)/2;
  x2=((-b)-d)/2;
  cout<<"Root 1 = "<<x1;
  cout<<"Root 2 = "<<x2;
}
getch();
}

HHW Q25. WAP to calculate discount on entering sale amount .

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b;
cout<<"Enter the Sale Amount ";
cin>>a;
b=a>25000?25:(a>20000?20:(a>15000?15:(a>10000?10:(a>5000?5:0))));
cout<<"Discount = "<<b<<"%";
getch();
}

HHW Q24. WAP to calculate grade from the sslab given .

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
float a;
int c;
char b,A,B,C,D,E;
cout<<"Enter your CGPA ";
cin>>a;
b=a>8.0?'A':(a>6.5?'B':(a>5.0?'C':(a>3.5?'D':'E')));
cout<<"Your grade is "<<b;
getch();
}

HHW Q21. WAP to print all square of all nos. in a range entered by user .

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c,d,e;
cout<<"Enter the range below "<<"\n";
cout<<" from -- ";
cin>>a;
cout<<" to -- ";
cin>>b;
for (int i=a;i<=b;i++)
{ c=i*i;
  cout<<i<<"^2 = "<<c<<"\n";
}
getch();
}

HHW Q20. WAP to swap 2 nos. without using third variable .

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b;
cout<<"Enter first no. a = ";
cin>>a;
cout<<"Enter second no. b = ";
cin>>b;
a=a+b;
b=a-b;
a=a-b;
cout<<"a = "<<a<<"\n"<<"b = "<<b;
getch();
}

HHW Q19. WAP to calculate TSA and volume of a Cone .

#include<conio.h>
#include<iostream.h>
void main()
{
clrscr();
float r,l,h,tsa,csa,v;
cout<<"Enter radius of the Cone ";
cin>>r;
cout<<"Enter height of the Cone ";
cin>>h;
cout<<"Enter slant height of the cone ";
cin>>l;
float const pi=3.14;
v=(0.33)*pi*r*r*h;
csa=pi*r*l;
tsa=(pi*r*l)+(pi*r*r);
cout<<"Volume of Cone = "<<v<<"\n";
cout<<"CSA of Cone = "<<csa<<"\n";
cout<<"TSA of Cone = "<<tsa<<"\n";
getch();
}

Saturday, 15 October 2016

HHW Q18. WAP to calculate TSA and volume of a Cylinder .

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
long int h,r,a1,a2,v;
cout<<"Enter height of the Cylinder ";
cin>>h;
cout<<"Enter radius of the Cylinder ";
cin>>r;
float const pi=3.14;
v=pi*r*r*h;
a1=2*pi*r*h;
a2=(2*pi*r*r)+(2*pi*r*h);
cout<<"Volume of Cylinder = "<<v<<"\n";
cout<<"TSA of Cylinder = "<<a2<<"\n";
cout<<"CSA of Cylinder = "<<a1<<"\n";
getch();
}

HHW Q15. WAP to enter the no. and check its visibility by nos.

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
long int a,b,c;
cout<<"Enter the no. (divisor) ";
cin>>a;
cout<<"Enter the no. (dividend) ";
cin>>b;
c=a%b;
if (c==0)
{ cout<<a<<" is perfectly divisible by "<<b;
}
else
{ cout<<a<<" is not divisible by "<<b;
}
getch();
}

Thursday, 13 October 2016

HHW Q13. WAP to print 10 multiples of entered no.

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b;
cout<<"Enter the no.";
cin>>a;
for (int i=1;i<=10;i++)
{ b=a*i;
  cout<<b<<"\n";
}
getch();
}

HHW Q9. WAP to find smallest among 3 entered nos.

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c,d;
cout<<"Enter 3 nos.";
cin>>a>>b>>c;
d=a<b?(a<c?a:c):(b<c?b:c);
cout<<"Smallest no. is = "<<d;
getch();
}

HHW Q8. WAP to find greatest among 3 entered nos.

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c,d;
cout<<"Enter 3 nos. ";
cin>>a>>b>>c;
d=a>b?(a>c?a:c):(b>c?b:c);
cout<<"Largest no. = "<<d;
getch();
}

HHW Q1. WAP to print your name , class and section .

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout<<" Name ------ Tanuj Bhatt "<<"\n"<<" Class ----- 11 A";
getch();
}

HHW Q7. WAP to find an average of 5 nos. entered by user and print the nos. larger than avg. no.

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c,d,e,f,g;
cout<<"Enter 5 nos. ";
cin>>a>>b>>c>>d>>e;
f=(a+b+c+d+e)/5;
cout<<"Average of these nos. = "<<f<<"\n";
if (a>f){cout<<a<<" is greater than average no."<<"\n";}
if (b>f){cout<<b<<" is greater than average no."<<"\n";}
if (c>f){cout<<c<<" is greater than average no."<<"\n";}
if (d>f){cout<<d<<" is greater than average no."<<"\n";}
if (e>f){cout<<e<<" is greater than average no."<<"\n";}
getch();
}

Wednesday, 12 October 2016

HHW Q5. WAP to check whether an entered year is leap or not .

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b;
cout<<"Enter the year ";
cin>>a;
if (a%400==0)
   { cout<<"This year is not a leap year ";              /*Century years divisible by 400 are not leap year*/
   }
else
   { if (a%4==0)
{cout<<"This year is leap year ";
}
     else
{cout<<"This year is not a leap year ";
}
   }
getch();
}

HHW Q4. WAP to check whether a no. is odd or even .

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a;
cout<<"Enter the no. ";
cin>>a;
if (a%2==0)
{cout<<"No. is even ";
}
else
{cout<<"No. is odd";
}
getch();
}

HHW Q3. WAP to enter age of a person and check his eligibility to vote .

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b;
cout<<"Enter your present age ";
cin>>a;
if (a>=18)
   { cout<<"You are Eligible to vote ";
   }
else
   { b=18-a;
     cout<<"You are not eligible to vote but after "<<b<<" years you will be eligible to vote ";
   }
getch();
}

HHW Q2. WAP to print your name 10 times .

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
for (int i =1;i<=10;i++)
{
 cout<<"Tanuj Bhatt"<<"\n";
}
getch();
}

Sunday, 9 October 2016

Program to print multiples of any no. acc. to user's choice .

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b;
cout<<"Enter the no. whose multiple you want to print ";
cin>>a;
cout<<"Enter the no. of multiples ";
cin>>b;
for (int i=1;i<=b;i++)
{ cout<<i*a<<"\n";
}
getch();
}

To print series -1,4,-7,10......

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b=1;
cout<<"No. of terms = ";
cin>>a;
for(int i=1;i<=a;i++)
{  if(i==1)
   {b=b*(-1);
    cout<<b<<"\n";
   }
   else
   {
      if (i%2==0)
      { b=b*(-1);
b=b+3;
cout<<b<<"\n";
      }
      else
      { b=b+3;
b=b*(-1);
cout<<b<<"\n";
      }
   }
}
getch();
}

To print series 1,-4,7,-10..........

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int b=1,a;
cout<<"No. of terms = ";
cin>>a;
for(int i=1;i<=a;i++)
{
 if(i==1)
   { cout<<b<<"\n";
   }
 else
   { if (i%2==0)
{ b=b+3;
 b=b*(-1);
 cout<<b<<"\n";
}
     else
{ b=b*(-1);
 b=b+3;
 cout<<b<<"\n";
}
   }
}
getch();
}

Thursday, 6 October 2016

To print Fibonnaci series .

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int x=-1,y=1,i;
cout<<"Enter the no. of terms you want to print ";
cin>>i;
for (int z=0;z<=i;z++)
{
   z=x+y;
   cout<<z<<"\n";
   x=y;
   y=z;
}
getch();
}

Wednesday, 5 October 2016

Program to find cube of first 10 natural numbers .

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
for(int x=1;x<=10;x++)
{
cout<<x*x*x;
}
getch();
}

Program to find square of first 10 Natural numbers .

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
for(int x=1;x<=10;x++)
{
cout<<x*x;
}
getch();
}

Program to print print first 10 natural numbers using Loop .

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
for(int x=1;x<=10;x++)
{cout<<x<<"\n";
}
getch();
}

Tuesday, 4 October 2016

To find roots of a given Quadratic equation using Switch case .

#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
float a,b,c,d,e,x,r,t;
int D,z,f;
cout<<"Enter a= ";
cin>>a;
cout<<"enter b=";
cin>>b;
cout<<"Enter c=";
cin>>c;
D=b*b-4*a*c;
f=D>0?1:(D==0?2:(D<0?3:4));
switch (f)
{ case 1:
 x=(-b+sqrt(D))/(2*a);
 r=(-b-sqrt(D))/(2*a);
 cout<<"Roots of the Equation are Real"<<"\n";
 cout<<"Root 1 = "<<x<<"\n";
 cout<<"Root 2 = "<<r;
 break;
  case 2:
 x=(-b)/(2*a);
 cout<<"Root of the Equation are Real and Equal "<<"\n";
 cout<<"Root = "<<x;
 break;
  case 3:
 cout<<"Roots are Imaginary";
 break;
}
getch();
}

To find largest and smallest amongg given 3 nos. using Conditional Statement .

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c,d,e;
cout<<“a = “;
cin>>a;
cout<<“b = “;
cin>>b;
cout<<“c = “;
cin>>c;
d=a>b?(a>c?a:c):(b>c?b:c);
e=a<b?(a<c?a:c):(b<c?b:c);
cout<<“Largest no. is = “<<d;
cout<<“Smallest no. is = “<<e;
getch();
}

To check whether a no. is even or odd using Switch statement .

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b;
cout<<“Enter the number “;
cin>>a;
b=a%2;
switch(b)
{
case 0:
cout<<“This number is even “;
break;
case 1:
cout<<“This number is odd “;
break;
default:
cout<<“Enter correct value “;
break;
}
getch();
}

To find Area of different shapes using Menu options .

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
void main()
{
clrscr();
int a;
float b,c,d,area;
cout<<setw(50)<<"..........MENU.........."<<"\n"<<"\n";
cout<<setw(60)<<"You can select options from the following "<<"\n"<<"\n"<<"\n";
cout<<setw(49)<<"1.To find area of a Square"<<"\n";
cout<<setw(53)<<"2.To find area of a Reactangle"<<"\n";
cout<<setw(49)<<"3.To find area of a Circle"<<"\n";
cout<<setw(56)<<"4.To find area of a Parallelogram"<<"\n";
cout<<setw(49)<<"5.To find area of Triangle"<<"\n";
cout<<setw(29)<<"6.Exit"<<"\n";
cin>>a;
switch (a)
{ case 1:
clrscr();
cout<<"You have chosen To find area of a Square"<<"\n";
cout<<"Enter side of the Square "<<"\n";
cin>>b;
area=b*b;
cout<<"Area of the Square ="<<area;
break;
  case 2:
clrscr();
cout<<"You have chosen To find area of a Rectangle"<<"\n";
cout<<"Enter length ";
cin>>b;
cout<<"Enter breadth ";
cin>>c;
area=b*c;
cout<<"Area of Rectangle = "<<area;
break;
  case 3:
clrscr();
cout<<"You have chosen To find area of a Circle "<<"\n";
cout<<"Enter Radius ";
cin>>b;
area=3.14*b*b;
cout<<"Area of the Circle = "<<area;
break;
  case 4:
clrscr();
cout<<"You have chosen To find Area of a Parallelogram "<<"\n";
cout<<"Enter Base ";
cin>>b;
cout<<"Enter Height ";
cin>>c;
area=b*c;
cout<<"Area of the Prallelogram = "<<area;
break;
  case 5:
clrscr();
cout<<"You have chosen To find area of a Triangle";
cout<<"Enter Height ";
cin>>b;
cout<<"Enter Base ";
cin>>c;
area=0.5*b*c;
cout<<"Area of Triangle = "<<area;
break;
  case 6:
clrscr();
textbackground(BLACK);
break;
  default:
 clrscr();
 textbackground(BLUE);
 textcolor(RED+BLINK);
 cout<<"Enter correct values ";
 break;
}
getch();
}

To find Electricity charge if Units consumed is given .

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
float a,b,c;
cout<<“Enter Units Consumed “<<“\n”;
cin>>a;
b=a>300?60:(a>100?50:(a<=100?40:0));
c=(b*a)+50;
cout<<"Fixed charge imposed = 50 ";
cout<<“Electricity Charge imposed =”<<b<<” per Unit”<<“\n”;
cout<<“Payable Amount = Rs.”<<c;
getch();
}

To change temperature into Celcius , Fahrenheit and Kelvin using switch statement .

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
void main()
{
textbackground(GREEN+BLUE);
textcolor(BLACK);
clrscr();
int a;
float b,c;
cout<<setw(50)<<“…………Menu………..”<<“\n”<<“\n”;
cout<<setw(60)<<“You can chose from the following options”<<“\n”<<“\n”;
cout<<setw(61)<<“1. To convert Degree Celcius to Fahrenheit”<<“\n”;
cout<<setw(57)<<“2. To convert Degree Celcius to Kelvin”<<“\n”;
cout<<setw(61)<<“3. To convert Fahrenheit to Degree Celcius”<<“\n”;
cout<<setw(26)<<“4. Exit”<<“\n”;
cin>>a;
switch (a)
{ case 1:
clrscr();
cout<<setw(70)<<“You have chosen To convert Degree Celcius to Fahrenheit”<<“\n”<<“\n”;
cout<<setw(55)<<“Enter temperature (in Celcius) “<<“\n”;
cin>>b;
c=1.8*b+32;
cout<<b<<” Degree Celcius = “<<c<<” Fahrenheit”;
break;
case 2:
clrscr();
cout<<setw(65)<<“You have chosen To convert Degree Celcius to Kelvin”<<“\n”;
cout<<setw(52)<<“Enter Temperature (in Celcius)”<<“\n”;
cin>>b;
c=b+273.15;
cout<<b<<” Degree Celcius = “<<c<<” Kelvin”;
break;
case 3:
clrscr();
cout<<setw(65)<<“You have chosen To convert Fahrenheit to Degree Celcius”<<“\n”;
cout<<setw(53)<<“Enter temprature (in Fahrenheit)”<<“\n”;
cin>>b;
c=(b-32)*5/9;
cout<<b<<” Fahrenheit = “<<c<<” Degree Celcius”<<“\n”;
break;
case 4:
clrscr();
break;
default:
clrscr();
cout<<“Enter correct Values”;
break;
}
getch();
}

To find Income Tax if Monthly Salary is given .

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
float a,b,tax;
cout<<“Enter your Monthly Salary “<<“\n”;
cin>>a;
tax=a>9000?40:(a>7500?30:20);
b=(tax*0.01*a);
cout<<“Tax = “<<tax<<“%”<<“\n”<<“Payable Amount =”<<b;
getch();
}

To make a Calculator using switch statement .

#include<iostream.h>
#include<conio.h>
void main()
{
textcolor(RED);
textbackground(BLUE+GREEN);
clrscr();
float a,b,d;
char c;
cout<<“Enter first no. a = “;
cin>>a;
cout<<“Enter second no. b = “;
cin>>b;
cout<<“Enter the Operator “;
cin>>c;
switch (c)
{ case ‘+’:
d=a+b;
clrscr();
cout<<“Sum of the digits = “<<d;
break;
case ‘-‘:
d=a-b;
clrscr();
cout<<“Difference = “<<d;
break;
case ‘*’:
d=a*b;
clrscr();
cout<<“Product = “<<d;
break;
case ‘/’:
d=a/b;
clrscr();
cout<<“Quotient = “<<d;
break;
default:
cout<<“!!!!!!!!!!!!!! Error”<<“\n”<<“Enter corrrect values”;
break;
}
getch();
}

Basic Implementation of Array as a Pointer

#include<iostream.h> #include<conio.h> void main() { clrscr();   int arr[5];   cout<<"Enter 5 nos. ";   f...