The Site is under maintenance!..Test link

assignment1_2

C++ Programs and Answers

C++ Programs and Answers

#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 : " << a << " " << b;
    return 0;
}
                        

#include <iostream>
using namespace std;

int main() {
    int a, b, c, greatest;
    cout << "Enter three numbers : ";
    cin >> a >> b >> c;
    greatest = (a > b && a > c) ? a : (b > c) ? b : c;
    cout << "Greatest number is " << greatest;
    return 0;
}
                        

#include <iostream>
using namespace std;

int main() {
    int amt, R500, R100, R50, R20, R10, R5, R1;
    cout << "Enter amount : ";
    cin >> amt;
    R500 = amt / 500;
    amt = amt % 500;
    R100 = amt / 100;
    amt = amt % 100;
    R50 = amt / 50;
    amt = amt % 50;
    R20 = amt / 20;
    amt = amt % 20;
    R10 = amt / 10;
    amt = amt % 10;
    R5 = amt / 5;
    amt = amt % 5;
    R1 = amt;
    cout << "Rs.500 : " << R500 << "\nRs.100 : " << R100 << "\nRs.50 : " << R50 <<
        "\nRs.20 : " << R20 << "\nRs.10 : " << R10 << "\nRs.5 : " << R5 << "\nRe.1 : " << R1;
    return 0;
}
                        

#include <iostream>
using namespace std;

int main() {
    char ch;
    cout << "\nEnter any character : ";
    cin >> ch;
    ch++;
    cout << "Next character is : " << ch;
    return 0;
}
                        

#include <iostream>
using namespace std;

int main() {
    int days, y, m, d;
    cout << "Enter no. of days : ";
    cin >> days;
    y = days / 365;
    days = days % 365;
    m = days / 30;
    d = days % 30;
    cout << "Years : " << y << "\nMonths : " << m << "\nDays : " << d;
    return 0;
}
                        

Question: int result = 4 + 5 * 6 + 2;
Answer: 36

Question: int a = 5 + 7 % 2;
Answer: 6

Question: int x = 10, y; y = x++;
Answer: 10

Code:

int result = 4 + 5 * 6 + 2;
cout << result;
            

Answer: 36

Code:

int a = 5 + 7 % 2;
cout << a;
            

Answer: 6

int x = 10, y;
y = x++;
cout << y;
            

Answer: 10

int x = 10;
x++;
cout << x;
            

Answer: 11

int x = 10, y;
y = ++x;
cout << y;
            

Answer: 11

int x = 10;
cout << x++;
            

Answer: 10

int x = 10, y;
y = x + x++;
cout << y;
            

Answer: 21

int x = 10, y;
y = ++x + x++ + x;
cout << y;
            

Answer: 35

int x = 10, y;
y = x++ + x + ++x;
cout << y;
            

Answer: 33

#include <iomanip>
cout << setw(5) << 77 << endl;
cout << setw(5) << 100 << endl;
cout << setw(5) << 12312 << endl;
            

Answer:

   77
  100
12312
            

float net = 5689.2356;
cout.precision(2);
cout.setf(ios::fixed | ios::showpoint);
cout << net << endl;
            

Answer: 5689.24