Followers

Friday, December 23, 2011

CALCULATING EXPONENT USING - math.h

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

void main()
{
 clrscr();
 int x, n;
 cout<<"Enter the base ";
 cin>>x;
 cout<<"Enter the power ";
 cin>>n;
 cout<<"The result of the given exponent is : "<<pow(x,n);
 getch();
}
.................................................................
OUTPUT:(click to enlarge the image)

Thursday, December 15, 2011

PYRAMID OF ALPHABETS

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

void main()
{
 clrscr();
 int n;
 cout<<"Enter the number of lines : ";
 cin>>n;
 for( int i=1 ; i<=n ; i++ )
 {
   for ( int j=1 ; j<=n-i ; j++ )
    {
     cout<<" ";
    }
   for ( int k=1 ; k<=i ; k++ )
    {
     cout<<char (64+k);
    }


   for ( int l=i ; l>=2 ; l-- )
       cout<<char (63+l);


   cout<<"\n";
 }
 getch();
}
.................................................................
OUTPUT:(click to enlarge the image)

ASCII CODE TO CHARACTER

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

void main()
{
 clrscr();
 int num;
 cout<<"Enter the ASCII code : ";
 cin>>num;
 cout<<"The corresponding character is : "<<char(num);
 getch();
}
.................................................................
OUTPUT:(click to enlarge the image)


Sunday, December 11, 2011

CHARACTER TO ASCII CODE

#include<iostream.h>
#include<conio.h>
char ch;

char asc(char ch)
{
 cout<<"Enter a character : ";
 cin>>ch;
 cout<<"The ASCII code for the given character is : "<<int(ch);
 return 0;
}

void main()
{
  clrscr;
  asc(ch);
  getch();
}
.................................................................
OUTPUT:(click to enlarge the image)

Saturday, December 10, 2011

INTER CONVERSION OF CASES OF ALPHABET--USING LOGIC

#include<iostream.h>
#include<conio.h>
char ch;

char cse(char ch)
{

 if((97<=int(ch))&&(int(ch)<=122))
   {
    cout<<"\nThe given character is in lowercase"
      <<"\nThe corresponding uppercase is - ";
    return(char(int(ch)-32));
   }
 else if (65<=int(ch)<=90)
   {
    cout<<"\nThe given character is in uppercase"
      <<"\nThe corresponding lowercase is - ";
    return(char(int(ch)+32));
   }
}
void main()
{
  clrscr();
  cout<<"Enter a character : ";
  cin>>ch;
  cout<<cse(ch);
  getch();
}
.................................................................
OUTPUT:(click to enlarge the image)

Saturday, December 3, 2011

DOUBLE OF A MATRIX

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

void main()
{
 int x[10][10], y[10][10], n, m, i, j;
 cout<<"\nEnter the number of rows :";
 cin>>n;
 cout<<"Enter the number of columns :";
 cin>>m;
 cout<<"Enter the matrix X :\n";
 for(i=0 ; i<n ; i++)
 {
   for(j=0 ; j<m ; j++)
     cin>>x[i][j];
 }

 cout<<"The matrix X :\n";
 for(i=0 ; i<n ; i++)
 {
   cout<<"\n";
   for(j=0 ; j<m ; j++)
     cout<<" "<<x[i][j];
 }


 for(i=0 ; i<n ; i++)
 {
   for(j=0 ; j<m ; j++)
     y[i][j]= 2*x[i][j];
 }
 cout<<"\nThe double of the given matrix : ";

 for(i=0 ; i<n ; i++)
 {
   cout<<"\n";
   for(j=0 ; j<m ; j++)
     cout<<" "<<y[i][j];
 }

 getch();
}
.................................................................
OUTPUT:(click to enlarge the image)

SUM OF TWO MATRICES : SIMPLE

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

void main()
{
 clrscr();
 int x[10][10], y[10][10], z[10][10] , n, m, i, j;
 char dec;
 cout<<"The number of rows and columns shoud be equal in both the matrices for any \narithmentic operation ";
 do{
    cout<<"\nEnter the number of rows :";
    cin>>n;
    cout<<"Enter the number of columns :";
    cin>>m;
    cout<<"Enter the matrix X :\n";
    for(i=0 ; i<n ; i++)
    {
      for(j=0 ; j<m ; j++)
      cin>>x[i][j];
    }

    cout<<"The matrix X :\n";
    for(i=0 ; i<n ; i++)
    {
      cout<<"\n";
      for(j=0 ; j<m ; j++)
      cout<<" "<<x[i][j];
    }
    cout<<"\nIs the matrix correct? (Y/N) : ";
    cin>>dec;
 }while(dec=='N'|| dec=='n');
do{
   cout<<"\nEnter the matrix Y :\n";
   for(i=0 ; i<n ; i++)
   {
     for(j=0 ; j<m ; j++)
       cin>>y[i][j];
   }

   cout<<"The matrix Y :\n";
   for(i=0 ; i<n ; i++)
   {
     cout<<"\n";
     for(j=0 ; j<m ; j++)
       cout<<" "<<y[i][j];
   }
   cout<<"\nIs the matrix correct? (Y/N) : ";
      cin>>dec;

}while(dec=='N'|| dec=='n');

 for(i=0 ; i<n ; i++)
 {
   for(j=0 ; j<m ; j++)
     z[i][j]= x[i][j] + y[i][j];
 }
 cout<<"\nThe sum of the two given matrices : ";

 for(i=0 ; i<n ; i++)
 {
   cout<<"\n";
   for(j=0 ; j<m ; j++)
     cout<<" "<<z[i][j];
 }

 getch();
}
.................................................................
OUTPUT:(click to enlarge the image)


SUM OF TWO MATRICES : SPECIAL DESIGN

#include<iostream.h>
#include<conio.h>
int n, m , x[3][3], y[3][3], z[3][3], i, j, k, l;

void inpt(int a[3][3] , int n , int m)
{
  for(i=0 ; i<n ; i++)
    for(j=0 ; j<m ; j++)
      cin>>a[i][j];
  cout<<"the matrix :\n";
  for(i=0 ; i<n ; i++)
  {
    cout<<"\n";
    for(j=0 ; j<m ; j++)
      cout<<a[i][j];
  }
  cout<<"\n";
}

void sum(int x[3][3], int y[3][3] , int z[3][3], int n, int m)
{
  for(i=0 ; i<n ; i++)
    for(j=0 ; j<m ; j++)
      z[i][j]= x[i][j] + y[i][j];
}

void otpt(int x[3][3], int y[3][3] , int z[3][3], int n, int m)
{
  for(i=0 ; i<n ; i++)
  {
    if(i==1)
    {
      for(j=1 ; j<=1 ; j++)
      cout<<" "<<x[i][j]<<" +";
      for(k=1 ; k<=1 ; k++)
      cout<<" "<<y[i][k]<<" =";
      for(l=1 ; l<=1 ; l++)
      cout<<" "<<z[i][l];
    }

    else
    {
      for(j=0 ; j<3 ; j++)
      {
      if(j==1)
        continue;
      cout<<x[i][j]<<" ";
      }

      for(k=0 ; k<3 ; k++)
      {
      if(k==1)
        continue;
      cout<<y[i][k]<<" ";
      }

      for(l=0 ; l<3 ; l++)
      {
      if(l==1)
        continue;
      cout<<z[i][l]<<" ";
      }
    }
    cout<<"\n";
  }
}

void main()
{
  clrscr();
  cout<<"Enter the number of rows : ";
  cin>>n;
  cout<<"Enter the number of columns : ";
  cin>>m;
  cout<<"Enter the 1st matrix :\n";
  inpt(x,n,m);
  cout<<"Enter the 2nd matrix :\n";
  inpt(y,n,m);
  sum(x,y,z,n,m);
  cout<<"\nThe sum of the given matrices :\n";
  otpt(x,y,z,n,m);
  getch();
}
.................................................................
OUTPUT:(CLICK TO ENLARGE)


PRIME FACTORISATION

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

void main()
{
 clrscr();
 int n, x, m;
 cout<<"Enter any number : ";
 cin>>n;
 cout<<"Prime factors : \n";
 m=n;
 for(int i=2; i<=n/2;)
  {

   x=m%i;
   if(x==0)
    {
     cout<<i<<"\n";
     m=m/i;
    }
   else
    i=++i;
  }
 getch();
}
.................................................................
OUTPUT:(click on image to enlarge)

CHECK EVEN OR ODD NUMBER

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

void main()
{
 clrscr();
 int a;
 cout<<"Enter any number : ";
 cin>>a;
 (a%2==0)?cout<<"Even number":cout<<"Odd number";
 getch();
}
.................................................................
OUTPUT:(click on image to enlarge)

CHECK FOR PRIME NUMBER

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

void main()
{
 clrscr();
 int n, x;
 cout<<"Enter a number :";
 cin>>n;
 for(int i=2; i<=n/2; i++)
  {
   x=n%i;
   if(x==0)
    {
     cout<<"\nNon-prime number";
     i=n+1;
    }
  }
 if(x>0)
  cout<<"\nPrime number";
 getch();
}
.................................................................
OUTPUT:(click on image to enlarge)