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