Thursday 8 May 2014

Write a program to display the following output using a single cout statement. Subject Marks Mathematics 90 Computer 77 Chemistry 69

4 comments
2-) Write a program to display the following output using a single cout statement.  
   Subject            Marks
   Mathematics     90
   Computer         77
   Chemistry        69

Solution:-


#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
    int sub1,sub2,sub3;
    cout<<"Enter Mathematics marks = ";
    cin>>sub1;
    cout<<"Enter Computer marks = ";
    cin>>sub2;
    cout<<"Enter Chemistry marks = ";
    cin>>sub3;
    cout<<"\nSubject\t\t\tMarks\n";
    cout<<"\nMathematics\t\t"<<sub1;
    cout<<"\nComputer\t\t"<<sub2;
    cout<<"\nChemistry\t\t"<<sub3;
    getch();
}
If You Enjoyed This, Take 5 Seconds To Share It

4 Questions:

Ahmad said...

this is rong type of code

Best of collection said...

the code is wrong.

Unknown said...

We have to use only one cout statement but you are using multiple, correct is:

#include
#include
int main()
{
char *sub[]={"Maths","Physics","Chemestry"};
int mark[]={90,77,69};
for(int i=0;i<3;i++)
{
cout<<setw(10)<<sub[i]<<setw(3)<<"="<<setw(4)<<mark[i]<<endl;
}
return 0
}

Unknown said...

We have to use only one cout statement but you are using multiple, correct is:

#include
#include
int main()
{
char *sub[]={"Maths","Physics","Chemestry"};
int mark[]={90,77,69};
for(int i=0;i<3;i++)
{
cout<<setw(10)<<sub[i]<<setw(3)<<"="<<setw(4)<<mark[i]<<endl;
}
return 0
}