This blog is about providing theory as well as simple executable codes of different programming languages such as java, C, C++, and web programming, etc. This blog will be helpful to the IT students to learn about programming.

Tuesday, March 14, 2023

Write a program to display the following output using a single cout statement. Math = 90 Physics =70 Chemistry = 69

 Here's a program in C++ that displays the required output using a single cout statement:

#include <iostream>
using namespace std;

int main() {

    cout << "Math = 90\nPhysics = 70\nChemistry = 69\n";

    return 0;
}

Output:

Math = 90
Physics = 70
Chemistry = 69

Explanation:

  • The program uses the cout statement to display the output on the screen.
  • The \n characters in the statement represent new lines, which separate each subject and its score.

Here's a program in C++ that displays the required output using a multiple cout statement:

#include <iostream>
using namespace std;

int main() {

    cout << "Math = 90\n";
    cout << "Physics = 70\n";
    cout << "Chemistry = 69\n";

    return 0;
}

Output:

Math = 90
Physics = 70
Chemistry = 69

Here's a program in C++ that displays the required output using a multiple cout statement and endl:

#include <iostream>
using namespace std;

int main() {

    cout << "Math = 90"<<endl;
    cout << "Physics = 70"<<endl;
    cout << "Chemistry = 69"<<endl;

    return 0;
}

Output:

Math = 90
Physics = 70
Chemistry = 69

No comments:

Post a Comment

If you have any doubts, please let me know

Slider Widget