Class 11 , Computer science all c++ programs, Maharashtra board

AYUSH KUSHWAHA
0

Class 11 Computer Science - C++ Programs Maharashtra board


Q1 -> Write a c++ program to calculate sum and average of 3 numbers.



// Write a c++ program to calculate sum and average of 3 numbers.

#include <iostream>

using namespace std;

int main(){

    float a,b,c,sum,avg;

    cout << "enter three numbers " << endl;

    cin >> a >> b >> c;

    sum = a + b + c;

    avg = sum / 3;

    cout << "The sum of three numbers is " << sum << endl;

    cout << "Average of three numbers is " << avg;

}


Q -> Write a c++ program to check weather the number is divisible by 5 or not.


    

 // Write a c++ program to check weather the number is divisible by 5 or not.

#include<iostream>

using namespace std;

int main(){

    cout<<"enter a number ";

    int n;

    cin>>n;

    if(n%5 == 0){

        cout<<"the number is divisible by 5";

    }

    else{

        cout<<"the number is not divisible by 5";

    }

}

    

Q -> Write a program in c++ to find the greater number among 3 numbers .


    

//Write a program in c++ to find the greater number among 3 numbers .

#include<iostream>

using namespace std;

int main(){

 int a,b,c,max;

 cout<<"enter 3 numbers ";

 cin>>a>>b>>c;

 if(a>b){

   max = a;

}

else{

max = b;

}

if(c>max){

max = c;

}

cout<<"the greater num among the three numbers is "<<max;

}

    

Q-> Write a c++ program to accept number and check it is prime or not .


    

        

 // Write a c++ program to accept  number and check it is prime or not .

#include<iostream>

using namespace std;

int main(){

    int n,c = 0;

    cout<<"enter a number ";

    cin>>n;

    for(int i = 2;i<n;i++){

        if(n%i == 0){

            c = 1;

        }

    }

    if(c == 0){

        cout<<n<<" is a prime number ";

    }

    else{

        cout<<n<<" is not a prime number ";

    }

}

        

    

Q-> write a program in c++ to find the greatest common divisor(GCD) of two numbers .


    

        

// write a program in c++ to find the greatest common divisor(GCD) of two numbers .

#include<iostream>

    using namespace std;

    int main(){

    int n1,n2;

    cout<<"enter two numbers "<<endl;

    cin>>n1>>n2;

    while(n1 != n2){

        if(n1>n2){

            n1 = n1-n2;

        }

        if(n2 > n1){

            n2 = n2-n1;

        }

    }

    cout<<" the gcd is "<<n1;

}

        

    

Q-> Write a c++ program to find the sum of first 100 numbers using while loop.


    

   

  // Write a c++ program to find the sum of first 100 numbers using while loop.

#include<iostream>

using namespace std;

int main(){

    int d = 1,sum = 0;

    while(d<=100){

        sum = sum+d;

        d = d+1;

    }

    cout<<"sum of 100 no. is "<<sum;

}

        

    

Q-> Write a c++ program to calculate and print factorial of a given number.


    

        

 // Write a c++ program to calculate and print factorial of a given number.

#include<iostream>

using namespace std;

main(){

    int a,b =1;

    cout<<"enter a number ";

    cin>>a;

    for(int i =1;i<=a;i++){

        b = b*i;

    }

    cout<<"factorial of "<<a<<" is "<<b;

}

        

    

Q-> Write a c++ program to display fibonnocci series of a 15 terms.


    

        

   // Write a c++ program to display fibonnocci series of a 15 terms.

#include<iostream>

    using namespace std;

    int main(){

    int f0=0,f1=1,f;

    cout<<"fibonnacci series is "<<endl;

    cout<<f0<<endl<<f1<<endl;

    for(int i = 2;i<=15;i++){

        f = f0+f1;

        cout<<f<<endl;

        f0=f1;

        f1 = f;

    }

}

        

    

Q-> Write a program in c++ to describe the use of scope resolution operator.


    

        

// Write a program in c++ to describe the use of scope resolution operator.

#include<iostream>

using namespace std;

int a = 50;

int main(){

    int a = 20;

    cout<<"local variable value "<<a<<endl;

    cout<<"global variable value "<<::a<<endl;

}

    

Q-> Write a program in c++ to display the number which are divisile by 5 and 7.


    

        

            // Write a program in c++ to display the number which are divisile by 5 and 7.

#include<iostream>

using namespace std;

int main(){

    int i;

    cout<<"The numbers between 1 to 50 which are divisible by 5 & 7 "<<endl;

    for(i = 1;i<=50;i++){

        if(i%5 == 0 && i%7 == 0){

            cout<<i;

        }

    }

}

        

    

Q-> Write a c++ program to find area of a circle using funtion.


    

        

 // Write a c++ program to find area of  a circle using funtion.

#include<iostream>

using namespace std;

int main(){

    float area(float);

    float r;

    cout<<"enter radius"<<endl;

    cin>>r;

    area(r);

}

float area(float r){

    float a;

    a = 3.14*r*r;

    cout<<"area is = "<<a;

}

        

    

Q-> Write a c++ program to find area of rectangle using function.


    

        

  // Write a c++ program to find area of rectangle using function.

#include<iostream>

using namespace std;

int main(){

    int area(int l,int b);

    int l,b;

    cout<<"enter length and breadth";

    cin>>l>>b;

    area(l,b);

}

int area(int x,int y){

  int a;

   a=x*y;

   cout<<"area of rectangle is "<<a;

  }

        

    

Q-> Write a c++ program to calculate and print factorial of a given number by using function.


    

        

  // Write a c++ program to calculate and print factorial of a given number by using function.

#include<iostream>

using namespace std;

main(){

    int fact(int);

    int n;

    cout<<"enter a number ";

    cin>>n;

    fact(n);

}

int fact(int n){

    int f = 1;

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

        f = f*i;

    }

    cout<<"factorial of is "<<f;

}

        

    

Q->write c++ program to swap two numbers using call by reference in function


    

        

     // write c++ program to swap two numbers using call by reference in function.

#include<iostream>

using namespace std;

int main(){

    int x,y;

    void swap(int *x , int *y);

    x = 100;

    y = 50;

    cout<<"values before swap "<<endl;

    cout<<"x = "<<x<<endl<<"y = "<<y<<endl;

    swap(&x,&y);

    cout<<"values after swap "<<endl;

    cout<<"x = "<<x<<endl<<"y = "<<y<<endl;

}

void swap(int *x,int *y){

    int temp;

    temp = *y;

    *x = *y;

    *y = temp;

}

        

    

Q-> check weather the given year is leap year or not by using function.


    

        

 // check weather the given year is leap year or not by using function.

#include<iostream>

using namespace std;

int main(){

    int leap(int);

    int n;

    cout<<"enter a year "<<endl;

    cin>>n;

    leap(n);

}

int leap(int n){

    if (n%4 ==0){

        cout<<"year "<<n<<" is leap year "<<endl;

    }

    else{

        cout<<"year "<<n<<" is not a leap year "<<endl;

    }

}

        

         

Q-> Write a c++ program with function min() to returns the smallest number among the four given integers.


    

        

 // Write a c++ program with function min() to returns the smallest number among the four given integers.

#include<iostream>

using namespace std;

int main(){

    int min(int,int,int,int);

    int a,b,c,d;

    cout<<"enter 4 integer numbers "<<endl;

    cin>>a>>b>>c>>d;

    cout<<"the smallest number is = "<<min(a,b,c,d);

}

int min(int n1,int n2,int n3,int n4){

    int small;

    small = n1;

    if(n2<small){

        small = n2;

    }

    if(n3<small){

        small = n3;

    }

    if(n4<small){

        small = n4;

    }

    return small;

}

        

    

Q-> Write c++ program to find the area of circle and area of rectangle by concept of function overloding.


    

  // Write c++ program to find the area of circle and area of rectangle by concept of function overloding.

#include<iostream>

using namespace std;

int main(){

    float area(float);

    float area(float , float);

    float r;

    float l,b;

    cout<<"enter radius"<<endl;

    cin>>r;

    cout<<"enter length and breadth"<<endl;

    cin>>l>>b;

    area(r);

    area(l,b);

}

float area(float r){

    float c = 3.14*r*r;

    cout<<"area of circle is "<<c<<endl;

}

float area(float l,float b){

    float x = l*b;

    cout<<"area of retangle is "<<x<<endl;

}

        

    

Q-> Write a c++ program to perform arthematic calculation such as addition subtraction etc. depending on user choice using switch statement.


    

        

   // Write a c++ program to perform arthematic calculation such as addition subtraction etc. depending on user choice using switch statement.

#include<iostream>

using namespace std;

int main(){

    float a,b,result;

    cout<<"enter 2 numbers "<<endl;

    cin>>a>>b;

    cout<<"1 Addition \n 2 subtraction \n 3 multipliction \n 4 division"<<endl;

    int ch;

    cin>>ch;

    switch(ch){

        case 1:

          result = a+b;

          cout<<"sum is "<<result;

          break;

        case 2:

          result = a-b;

          cout<<"difference is "<<result;

          break;

        case 3:

          result = a*b;

          cout<<"product is "<<result;

          break;

        case 4:

          result = a/b;

          cout<<"division is "<<result;

          break;

        default:

          cout<<"invalid choice";

    }

}

        

    

Post a Comment

0Comments

Post a Comment (0)