Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
1.6k views
in Control Statements by (29.8k points)
closed by

Write C++ program forgetting the following output. 

1 2 

1 2 3 

1 2 3 4 

OR 

Consider the following C++ program and answer the following questions. 

#include<iostream.h>

int main() 

int a, p = 1; 

for(a=1;a<=5;a+=2) 

p = p × a;

cout<<p;

}

(a) Predict the output of the above code. 

(b) Rewrite the above program using while loop

1 Answer

+1 vote
by (29.6k points)
selected by
 
Best answer

#include<iostream>

using namespace std; 

int main() 

int i,j

for(i=1;i<=4;i++)

{

for(j=1;j<=i;j++)

cout<<j<<''\t";

cout<<"\n";

}

}

OR

(a) The output is 15

(b) 

#include<iostream>

using namespace std; 

int main() 

int a=1,p=1;

while(a<=5)

{

p=p*a;

a+=2;

}

cout<<p;

}

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

...