Shah Imtiyaj

Untitled Document

C++ programming are given below:

C++ programming code are given below :

C++ programming code are given below

Q:Write a C++ program   to  cout :   Hello  world 

Solution:

#include <iostream>

 

using namespace std;

 

int main()

{

    cout << "Hello World!";

    cout << "\t";

    cout << 999;

    return 0;

}

Q:Write a C++ program   to  cout :Max number

Solution:

Hints:  Take three input a,b,and c if a greater than b & c cout max is a.  if b greater than a & c cout max is b  otherwise cout  max is c.

#include <iostream>

 using namespace std;

 int main()

{

    int a, b, c;

    cin >> a >> b >> c;

    if(a > b && a > c){

        cout << "Max is " << a;

    }

    if(b > a && b > c){

        cout << "Max is " << b;

    }

    if(c > a && b < c){

        cout << "Max is " << c;

    }

    return 0;

}

Q:Write a C++ program   to cout :   Age

Hints: cout , how much your year,month,day,hour,minutes,

second ? 

At first you  cin your birth year  ,birth month,birth day,birth 

hour,birth minute,birth second than you cin your current year  ,current month,current day, current hour,current minute,

current  second than  cout your total age 

Solution:

#include <iostream>


using namespace std;


int main()

{

    int cy, cm, cd,ch,cmi,cs, by, bm, bd,bh,bmi,bs, ry, rm, rd,rh,rmi,rs;

    cin>>cy>>cm>>cd>>ch>>cmi>>cs>>by>>bm>>bd>>bh>>bmi>>bs;

    if(cs > bs){

rs=cs-bs;

}

else{

cs=cs+60;

bmi=bmi+1;

rs=cs-bs;

}



    if(cmi > bmi){

        rmi=cmi-bmi;


    }

        else{

            cmi=cmi+60;

            bh=bh+1;

        rmi=cmi-bmi;

        }


    if(ch > bh){

        rh=ch-bh;


    }

        else{

            ch=ch+24;

             bd=bd+1;

        rh=ch-bh;

        }



            if(cd > bd){

        rd = cd - bd;

    }else{

        if(bm == 1 || bm == 3 || bm == 5||bm==7||bm==8||bm==10||bm==12){

            cd = cd + 31;

        }

        else if(bm == 4 || bm == 6 || bm == 9 || bm == 11){

            cd = cd + 30;

        }

        else if(bm == 2 && by % 4 == 0){

            cd = cd + 29;

        }

        else if(bm == 2 && by % 4 != 0){

            cd = cd + 28;

        }

        bm = bm + 1;

        rd = cd - bd;

    }


    if(cm > bm){

        rm = cm - bm;

    }else{

        cm = cm + 12;

        by =by + 1;

        rm = cm - bm;

    }


    ry = cy - by;


    cout << "Result is: " << ry << "-" << rm << "-" << rd<<"-"<<rh<<"-"<<rmi<<"-"<<rs;

    return 0;

}


Q:Write a C++ program   to cout :   You can apply or u can't apply

Hints: if your age is greater than equal 18 and less than equal 30.You can apply otherwise  u can't apply  .

Solution:

#include <iostream>

 

using namespace std;

 

int main()

{

    int age;

    cin >> age;

    if(age >= 18 && age <= 30){

        cout << "You can apply";

    }

    else{

        cout << "You cant't apply";

    }

    return 0;

}

Q:Write a C++ program   to cout :   Valid or invalid 

Hints: To check out your birth day ,birth month & birth year  is valid or invalid .

Solution:

#include <iostream.h>

 int main()

{

                 int d, m, y;

                 d = 41;

                 m = 14;

                 y = 2009;

 

                 if(d >= 1 && d <== 31 && m >= 1 && m <= 12 && y > 0){

                                if(m == 1 || m == 3 || m == 5){

                                                cout << "Valid";

                                }

                                else if((m == 4 || m == 6 || m == 9 || m == 11) && d <= 30){

                                                cout << "Valid";

                                }

                                else if(m == 2 && y % 4 == 0 && d <= 29){

                                                cout << "Valid";

                                }

                                else if(m == 2 && y % 4 != 0 && d <= 28){

                                                cout << "Valid";

                                }

                                else{

        cout << "Invalid";

                                }

                 }

                 else{

                                cout << "Invalid";

                 }

 

                 return 0;


}

Q:what is output?    

If Enter:5

output: 5,4,3,2,1

 Solution:

#include <iostream>


using namespace std;


int main()

{

    int n;

    cout<<" Enter the starting number =";

    cin>>n;

    while(n>0){

    cout<<n<<" ";

    --n;

    }

    cout<<"FIRE!\n";

    return 0;

}

Q:What is output?

output:    

 7

solution:

#include <iostream>


using namespace std;


int main()

{



    int a= 5;

cout<<a++<<"\n"<<++a;

return 0;


}

Q:What is output?

output:    

41

 11

12


solution:

#include <iostream>


using namespace std;


 int main()

 {

     int a = 5,b;

     b = ++a + ++a + ++a + ++a + ++a;

     cout<<b<<"\n";

       cout<<a++<<"\n"<<++a;

       return 0;

 }


Q:Write a C++ program   to cout  maximum number,minimum number,and if 21 is remain your input than cout is search found otherwise cout is search not found(using function)


Solution:

#include <iostream>


using namespace std;

int find_max(int ara[],int n);

int find_min(int ara[],int n);

void s_r (int ara[],int n);


int main()

{



int a[100],i,n;

int min;

int max;

int search;

cout<<"Enter the taken number of data= ";

cin>>n;

cout <<"Enter the data in array";

for(i=0;i<=n-1;i++)

{

cin>>a[i];

}

  min =find_min(a,n);

  max = find_max(a,n);

  s_r(a,n);

cout<<"The maximum number is="<<max<<"\n";

cout<<"The manimum number is="<<min<<"\n";

return 0;

}


int find_max(int ara[],int n)

{

int max=ara[0];

int i;

for(i=1;i<=n-1;i++)

{

if(ara[i]>max)

{

max=ara[i];

}

}


return max;


}



int find_min(int ara[],int n)

{

int min=ara[0];

int i;

for(i=1;i<=n-1;i++)

{

if(ara[i]<min)

{

min=ara[i];

}

}


return min;

}



void s_r(int ara[],int n)

{

    int f=1;

    int s_r ;

    int i;

for(i=0;i<=n-1;i++)

{

if(ara[i]==21)

{

cout<<"search found"<<"\n";

f=0;

break;

}

}

if(f==1)

{


cout<<"search not found"<<"\n";

}


}







 


Make a free website with Yola