Powered By Blogger

07 March 2017

PROGRAM TO PRINT FOLLOWING OUTPUT..

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5 


INPUT--

#include <iostream>
using namespace std;
int main()
{
    int i,j,rows;
    cout<<"Enter the number of rows: ";
    cin>>rows;
    for(i=1;i<=rows;++i)
    {
        for(j=1;j<=i;++j)
        {
           cout<<j<<" ";
        }
        cout<<"\n";
    }
    return 0;
}

OUTPUT--

Enter the number of rows: 5
1
1 2 
1 2 3
1 2 3 4
1 2 3 4 5

PROGRAM TO GENERATE FIBONACCI SERIES..

INPUT--

#include <iostream>
using namespace std;

int main()
{
    int t1 = 0, t2 = 1, nextTerm = 0, n;

    cout << "Enter a positive number: ";
    cin >> n;

    // displays the first two terms which is always 0 and 1
    cout << "Fibonacci Series: " << t1 << ", " << t2 << ", ";

    nextTerm = t1 + t2;

    while(nextTerm <= n)
    {
        cout << nextTerm << ", ";
        t1 = t2;
        t2 = nextTerm;
        nextTerm = t1 + t2;
    }
    return 0;
}                        

OUTPUT--

Enter a positive integer: 100
Fibonacci Series: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89,

PROGRAM TO FIND FACTORIAL OF GIVEN NUM.

INPUT--



#include <iostream>
using namespace std;

int main()
{
    unsigned int n;
    unsigned long long factorial = 1;

    cout << "Enter a positive integer: ";
    cin >> n;

    for(int i = 1; i <=n; ++i)
    {
        factorial *= i;
    }

    cout << "Factorial of " << n << " = " << factorial;    
    return 0;
}


OUTPUT--

Enter a positive integer: 12
Factorial of 12 = 479001600

PROGRAM TO FIND ODD OR EVEN NUMB. USING IF....ELSE

INPUT--


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

void main()
{
       int no;
       clrscr();
       cout<<"Enter any num: ";
       cin>>no;
       if(no%2==0)
      { 
               cout<<"Even num";
      }
      else
     {
              cout<<"Odd num";
     }
     getch();
}


OUTPUT--

Enter any num : 5
Odd num

WRITE A PROGRAM TO CHECK NUMBER IS +VE & -VE

INPUT--


#include<iostream>
using namespace std;

int main()
{
int a;
cout<<"Enter any non-zero Number : ";
cin>>a;
(a>0)?cout<<"Number is positive":cout<<"Number is negative";
return 0;
}


OUTPUT--

EXAMPLE--1-->
Enter any non-zero Number : 56
Number is positive

EXAMPLE--2-->
Enter any non-zero Number : -14
Number is negative

PROGRAM TO PRINT FOLLOWING OUTPUT..

A
B B
C C C
D D D D
E E E E E


INPUT--

 #include <iostream>
using namespace std;
int main()
{
    int i,j;
    char input,temp='A';
    cout<<"Enter uppercase character you want in triange at last row: ";
    cin>>input;
    for(i=1;i<=(input-'A'+1);++i)
    {
        for(j=1;j<=i;++j)
           cout<<temp<<" ";
        ++temp;
        cout<<endl;
    }
    return 0;

}

OUTPUT--

Enter uppercase character you want in triange at last row:
A
B B
C C C
D D D D
E E E E E

PROGRAM TO PRINT GET FOLLOWING OUTPUT..

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

INPUT--

#include <iostream>
using namespace std;
int main()
{
    int i,j,rows;
    cout<<"Enter the number of rows: ";
    cin>>rows;
    for(i=1;i<=rows;++i)
    {
        for(j=1;j<=i;++j)
        {
           cout<<j<<" ";
        }
        cout<<"\n";
    }
    return 0;
}

OUTPUT--

Enter the number of rows:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

21 February 2017

PROGRAM TO PRINT SUM OF 10 NUMBERS

INPUT=


 #include<iostream>
using namespace std;
int main()
{
int a[10],i,sum;
        sum=0;
        cout<<"Enter 10 elements";
        for(i=0;i<10;i++)
        {
              cin>>a[i];
              sum=sum+a[i];
        }
        cout<<"The sum is ="<<sum;
        return 0;
}

OUTPUT=

Enter 10 elements
0
2
3
4
5
6
7
8
9
10

The sum is = 54

PROGRAM TO FIND OUT MIN NUMBER FROM 10 NUMBERS

INPUT=


#include<iostream>
using namespace std;
int main()
{
       int i,a[20],min;
       min = a[0];
       cout<<"Enter 10 numbers =";
       for (i=0;i<10;i++)
       {
              cout<<"The min is = "<<a[i];
       }
       else
       {
              cout<<"The min is = "<<min;
       }
       return 0;
}

OUTPUT=


Enter 10 numbers =
3
12
13
19
0
16
34
22
57
2

The min is = 0

18 February 2017

PROGRAM TO READ ALPHABET & DISPLAY IT'S NEXT CHARACTER IN ASCII

INPUT=

#include<iostream>
using namespace std;
int main()
{
        char x;
        int i;
        cout<<"Enter the alphabet =";
        cin>>x;
        i=x+1;
        cout<<"The ASCII of next character is ="<<i;
        return 0;
}


OUTPUT=

Enter the alphabet = A

The ASCII of next character is = 65

PROGRAM TO CALCULATE VOLUME OF CYLINDER.

INPUT=



#include<iosteram>
using namespace std;
int main()
{
      float v,r,h;
      cout<<"Enter radius and height=";
      cin>>r>>h;
      v=(3.14)*r*r*h;
      cout<<"The volume of cylinder is="<<v;
      return 0;
}

OUTPUT=


Enter radius and height = 2    4

The volume of cylinder is = 50.24

PROGRAM TO PRINT NAME USING ARRAY

INPUT=

#include<iosteram>
using namespace std;
int main()
{
       char a[40]
       cout<<"Enter the no of alphabets =";
       cin>>n;
       cout<<"Enter your name =";
       for(i=0;i<n;i++)
       {
              cin>>a[i];
       }
       for(i=0;i<n;i++)
       {
              cout<<a[i];
       }
       return 0;
}


OUTPUT=

Enter the no of alphabets = 5
Enter your name = Harsh

Harsh

PROGRAM TO FIND MAXIMUM FROM 2 NUMBERS

INPUT=


#include<iostream>
using namespace std;
int main()
{
      int a,b;
      cout<<"enter 2 numbers"<<a;
      if(a>b)
      cout<<"max="<<a;
      else
      cout<<"max="<<b;
      return 0;
}

 OUTPUT=

Enter 2 numbers= 6 8

max= 8

15 February 2017

PROGRAM TO CONVERTTEMPERATURE FAHRENHEIT TO CELCUS...

INPUT=



#include<iostream.h>
using namespace std;
int main()
{
float fah, cel;
cout<<"Enter temperature in Fahrenheit : ";
cin>>fah;
cel=((fah-32*5) / 9);
cout<<"Temperature in Celsius = "<<cel;
return 0;
}


OUTPUT=

Enter temperature in Fahrenheit : 98.6


Temperature in Celsius =37.00000

11 February 2017

Program to swipe 2 number using 3rd number...

INPUT=

#include <iostream>
using namespace std;

int main()
{
    int a = 5, b = 10, temp;

    cout << "Before swapping." << endl;
    cout << "a = " << a << ", b = " << b << endl;

    temp = a;
    a = b;
    b = temp;

    cout << "\nAfter swapping." << endl;
    cout << "a = " << a << ", b = " << b << endl;

    return 0;
}


OUTPUT=


Before swapping.

a = 5, b = 10


After swapping.
a = 10, b = 5

program to exchange 2 variables without using 3rd variables...


INPUT=

#include<iostream>
using namespace std;

int main()
{
int a,b;
cout<<"\nEnter two numbers : ";
cin>>a>>b;
a=a+b;
b=a-b;
a=a-b;
cout<<"\nAfter swapping numbers are : ";
cout<<a<<" "<<b;


return 0;
}


OUTPUT=
Enter two numbers : 78 12
After swapping numbers are : 12 78

Program to find sum and average of 2 variables...

INPUT=

#include <iostream>
using namespace std; 

int main(){
    int x,y,sum;
    float average;

    cout << "Enter 2 integers : " << endl;
    cin>>x>>y;
    sum=x+y;
    average=sum/2;
    cout << "SUM=" << x << " and " << y << " is " << sum <<             
    "." << endl;
    cout << "AVERAGE= " << x << " and " << y << " is " <<       
    average << "." << endl;
}

OUTPUT=

  Enter 2 integers :
   5 10
   SUM=15
   AVERAGE=7.5

10 February 2017

C++ program to print "HELLO WORLD"...



INPUT->
 #include<iostream>
 using namespace std;

 int main()
 {
  cout << "Hello World";
  return 0;
 }



OUTPUT->
       Hello World