0

what is the mistake in this code?

#include <iostream> using namespace std; int main() { int rows; cout<<"enter no. of rows required to print pyramid"; cin>>rows; for(int a=1; a<=rows; a++) { for(int b=a; b<rows; b++) { cout<<" "; } for(int c=1; c<=(2a-1); c++) { cout<<"*"; } cout<<endl; } return 0; }

7th Jun 2018, 8:34 AM
Nishant Goyal
Nishant Goyal - avatar
2 Réponses
+ 6
"2a" doesn't mean 2 multiplied by a. To the compiler, it's simply a bad identifier. Write "2*a" instead.
7th Jun 2018, 8:37 AM
Hatsy Rei
Hatsy Rei - avatar
0
thanks Hatsy Rei
7th Jun 2018, 9:32 AM
Nishant Goyal
Nishant Goyal - avatar