Sunday, November 18, 2012

Show which numbers is greater amongst 3 in C++

#include <conio.h>
#include <iostream.h>
int main()
{
        int a,b,c;
        cout<<"enter a value of a";
        cin>>a;
         cout<<"enter a value of b";
        cin>>b;
         cout<<"enter a value of c";
        cin>>c;
        if (a>b && a>c)
        cout<<"The value A is Greater than all 2";
        else if (b>c)
        cout<<"The value B is Greater than all 2";
        else
        cout<<"The value C is Greater than all 2";
getch();
return 0;
}

Convert decimal numbers to octal numbers in C++

#include<iostream.h>
#include<conio.h>
int main ()
{
    int num,i=0;
    cout<<"Enter the decimal number:";
    cin>> num;
    while(num>0)
    {
                i=num%8;
                num=num/8;  cout<<i;
                }
                cout<<"(Result in reverse order)";
                getch ();
                return 0;
}

conver decimal to Hexadecimal in C++

#include<iostream.h>
#include<conio.h>
int main ()
{
    int num,i=0;
    cout<<"Enter the decimal number:";
    cin>> num;
    while(num>0)
    {
                i=num%16;
                num=num/16;  cout<<i;
                }
               cout<<"(Result in reverse order)";
                getch ();
                return 0;
}

Convert Decimal number to binary numbers in C++

#include<iostream.h>
#include<conio.h>
int main ()
{
    int num,i=0;
    cout<<"Enter the decimal number:";
    cin>> num;
    while(num>0)
    {
                i=num%2;
                num=num/2;  cout<<i;
                }
                cout<<"(Result in reverse order)";
                getch ();
                return 0;
}

Tuesday, November 13, 2012

Displaying even numbers upto 100 in C++

#include <iostream.h>
#include <conio.h>
int main()
{
          int i;
for(int i=1;i <= 100 ;i++)
{ if(i%2==0)
cout<<i<<endl;
}
getch();
return 0;
}

Build a diamond in C++

#include <string.h>
 #include <iostream.h>
 #include <conio.h>
int main()
{
    int i, j, k;
    int n = 0;

    cout<<"Program for displaying pattern of *.\n";
    cout<<"Enter the maximum number of *: ";
    cin>>n;

  cout<<"\nHere is the Diamond of Stars\n";

    for (i = 1; i <= n; i++)
    {
          for (j = 0; j < (n - i); j++)
                cout<<" ";
          for (j = 1; j <= i; j++)
                cout<<"*";
          for (k = 1; k < i; k++)
                cout<<"*";
          cout<<"\n";
    }

    for (i = n - 1; i >= 1; i--)
    {
          for (j = 0; j < (n - i); j++)
                cout<<" ";
          for (j = 1; j <= i; j++)
                cout<<"*";
          for (k = 1; k < i; k++)
                cout<<"*";
          cout<<"\n";
    }
   
    cout<<"\n";
    getch();
    return 0;
}

comparing character and integer in C++

#include<iostream.h>
#include<conio.h>
main()
{
      int i;
      char c;
      for(i=0;i<256;i++)
      {
                        c=i;
                        cout<<i<<"\t"<<c<<endl;
                        }
                        getch();
                        return 0;

}