C++ Assignment First : Question 1 to Question 10

/* WAP to calculate the area of the circle, Triangle, and square.

[Area of circle = 3.14*rad*rad, Area of triangle = 0.5*base*height, Area of square = side*side]

*/


// 10.000000


#include <iostream>


using namespace std;


float circle(int radius); // Function Declaration

float triangle(int base, int height);


int main()

{

int radius, base, height;

/*

// Area of circle

cout << "Enter Radius of circle : ";

cin >> radius;


float x =  circle(radius); // function Call


cout << "Area of circle is " << x ;

*/


// Area of triangle


cout << "Enter value of base : ";

cin >> base;


cout << "Enter value of height : ";

cin >> height;


float ans2 = triangle(base, height);


cout << "\n Area of Triangle is " << ans2;

}


// Function Define

float circle(int radius)

{


return 3.14 * radius * radius;

}


float triangle(int base, int height)

{


return 05 * base * height;

}


// WAP to input any number and display the reverse.


#include <iostream>


using namespace std;



int main(){

int num, rem,rev=0;

cout << "Enter Any Three Digit Number: ";

cin>> num;//123

rem=num%10;//3

rev=rev*10+rem;//3

num=num/10;//12

rem=num%10;//2

rev=rev*10+rem;//32

num=num/10;//1

rem=num%10;// 1

rev=rev*10+rem;//321

num=num/10;//0

cout << "Rev of 123 is " << rev;

}



// WAP to find the maximum number among three numbers

#include <iostream>
using namespace std;


int main(){
int num1,num2,num3,max=0;
cout << "Enter Any Number : ";
cin >> num1;
cout << "Enter Any Number : ";
cin >> num2;
cout << "Enter Any Number : ";
cin >> num3;
if(num1>num2){
max=num1;
} else if(num2>num3){
max=num2;
}else{
max=num3;
}
}

// WAP to find the maximum number among three numbers

#include <iostream>
using namespace std;


int main(){
int num1,num2,num3,max=0;
cout << "Enter Any Number : ";
cin >> num1;
cout << "Enter Any Number : ";
cin >> num2;
cout << "Enter Any Number : ";
cin >> num3;
if(num1>num2){
max=num1;
} else if(num2>num3){
max=num2;
}else{
max=num3;
}
}


// WAP to find the addition of numbers between the given range.


#include <iostream>
using namespace std;
int main(){
int i,max=0;
for(i=0;i<=100;i++){
max+=i;
}
cout << max;
}



6 WAP to display prime numbers between the user-specified range 
#include <iostream>

bool isPrime(int num) {
   
    for (int i = 2; i * i <= num; ++i) {
        if (num % i == 0) {
            return false;
        }
    }
    return true;
}

int main() {
    int start, end;

    // Get user input for the range
    std::cout << "Enter the starting number: ";
    std::cin >> start;

    std::cout << "Enter the ending number: ";
    std::cin >> end;

    std::cout << "Prime numbers between " << start << " and " << end << " are:\n";

    // Display prime numbers in the specified range
    for (int i = start; i <= end; ++i) {
        if (isPrime(i)) {
            std::cout << i << " ";
        }
    }

    return 0;
}


Post a Comment

Previous Post Next Post