2-) Write a program to display the following output using a single cout statement.
Subject Marks
Mathematics 90
Computer 77
Chemistry 69
#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();
}
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();
}
4 Questions:
this is rong type of code
the code is wrong.
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
}
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
}
Post a Comment