Showing posts with label to. Show all posts
Showing posts with label to. Show all posts

Tuesday, 23 April 2013

Code to produce increasing and decreasing stars

Description:

This program produce increasing and decreasing stars automatically.

Code:


#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
    int i,j;
    for(i=1;i<=9;i=i+2)
     {
        for(j=0;j<i;j++)
        cout<<"*";
        cout<<endl;
        }
         if(i==11)
         {i=i-4;
         for(i=7;i>=1;i=i-2)
          {for(j=0;j<i;j++)
          {
            cout<<"*";
         
            }
            cout<<endl;}}
            getche();
 }


Output:


CODE TO DISPLAY FEBRUARY MONTH AS IN CALENDER

Description:
This program show february month as in calender automatically.
CODE:


#include<iostream>
#include<conio.h>
#include<iomanip>
using namespace std;
int main()
{int i,j,k=6;

    cout<<setw(20)<<"Feb 2012"<<endl;
    cout<<endl;
    cout<<setw(5)<<"MO"<<setw(5)<<"TU"<<setw(5)<<"W"<<setw(5);
cout<<"TH"<<setw(5)<<"Fr"<<setw(5)<<"Sa"<<setw(5)<<"Su"<<endl;
cout<<setw(5)<<"30";
cout<<setw(5)<<"31";

for(i=1;i<=5;i++)
cout<<setw(5)<<i;
cout<<endl;
for(i=0;i<3;i++)
{for(j=0;j<7;j++)
{
cout<<setw(5)<<k;
k++;
 }

 cout<<endl;
                }
 for(i=27;i<30;i++)
 cout<<setw(5)<<i;
 cout<<endl;
 cout<<endl;
cout<<"     **** Hafiz Junaid Hassan ****"<<endl;
cout<<setw(5)<<"           11-TE-14     ";


getche();
return 0;
}


Monday, 22 April 2013

Code to produce decreasing stars

Description:

This program simply produce increasing and decreasing stars automatically.

Code:


#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
    int i,j;
    for(i=5;i>=1;i--){
    for(j=0;j<i;j++)
    {cout<<"*";
    }
    cout<<endl;
}
    getche();
}

 
Output :



A programe to calculate factorial of a number

Description:

This program take a number from user as input and find its factorial automatically.

Code:


#include<iostream>
#include<conio.h>
#include<iomanip>
#include<math.h>
using namespace std;
int main()
{
       float a,b=1,c,i,f;
    cout<<"A programe to calculate factorial of a number"<<endl;
    xy:
    cout<<"Enter a number to calculate its factorial"<<endl;
    cin>>a;
    cout<<endl;
    i=a;
    while(i>=1)
    {
      b=b*i;
      i--;
      }
      cout<<"The factorial of the given number is"<<b<<endl;
      goto xy;
      getche();
      return 0;
      }


Output:


Programm to get multiplication table

Description:

This program take a number as input and make its multiplication table automatically.

Code:


#include<iostream>
#include<conio.h>
#include<iomanip>
#include<math.h>
using namespace std;
int main()
{
    int i,n=1,p;
    xy:
    cout<<"Enter the number to get its multiplication table"<<endl;
    cin>>n;
    cout<<endl;
    i=1;
    while(i<=10)
    {p=n*i;
     cout<<n<<"*"<<i<<"="<<p<<endl;
     i++;
     }
     goto xy;
     getche();
     return 0;
     }


Output:


A programe to find the roots of quadratic equation

Description:

This program take three constants of quadratic equation as input and find real and imaginary roots of that quadratic equation automatically.

Code:


#include<iostream>
#include<conio.h>
#include<iomanip>
#include<math.h>
using namespace std;
int main()
{
    float a,b,c,d,f,e,g,h,i,j,k,l;
    cout<<"A programe to find the roots of quadratic equation"<<endl;
    xy:
    cout<<"Enter the values of a,b,c"<<endl;
    cout<<"Enter value of a"<<endl;
    cin>>a;
    cout<<endl<<"Enter the value of b"<<endl;
    cin>>b;
    cout<<endl<<"Enter the value of c"<<endl;
    cin>>c;
    cout<<endl;
    d=b*b-(4*a*c);
    if(d>0||d==0)
    {
      f=(-b+sqrt(d))/(2*a);
      e=(-b-sqrt(d))/(2*a);
      cout<<"The required roots are"<<endl<<"The first root is ="<<f<<endl<<"The second root is ="<<e<<endl;
      }
    if(d<0)
    {
      g=-b/(2*a);//x1
      h= sqrt(-d)/(2*a);//x1
      j=-sqrt(-d)/(2*a);//x2
      k=g+h;
      l=g+j;
      cout<<"the required roots are"<<endl;
      cout<<"first root="<<k<<"i"<<endl;
      cout<<"second root="<<l<<"i"<<endl;
      }
      goto xy;
      getche();
      return 0;
      }


Output:


A programme to check the divisibility of a number by 3

Description:

In C++ if there is conditional logic then "if", "else" statements are used.

Code:


#include<iostream>
#include<conio.h>
#include<iomanip>
using namespace std;
int main()
{
    int a,b,c;
    cout<<"A programe to check the divisibility of a number by 3"<<endl;
    xy:
    cout<<"Enter the number to check its divisibility"<<endl;
    cin>>a;
    cout<<endl;
    if(a%3==0)
    {
              cout<<"The number is divisible by 3"<<endl;
           
              }
           
              goto xy;
              getche();
              return 0;
              }


Output: