+ 2
Write nested loops to produce the pattern below
9 989 98789 9876789 987656789
9 odpowiedzi
+ 1
int b;
for (int i=0;i<length;++i) //here length = 5
{
int b=9;
for (int j=0;j<(length/2)-i;++j) //for blank spaces
cout<<" ";
for(j=0;j<2*i+1;++j)
{
if(j<(2*i+1)/2) cout<<b--;
else cout<<b++;
}
}
//i have written this code without a compile. but i believe it would run.
+ 1
kindly post it here
+ 1
not possible... its running in this solo learn compiler...
i have checked it.
come and check the running of code in the code posts area. search for most recent category in C++ "to print a pattern A numb. pyramid" and try to run My code.
0
thanks let me try#CodeRunner
0
well so sorry Dominic...
I made a little mistake here in the code...
i have corrected it and you may check the code on my profile... or let me give you the corrected one...
#include <iostream>
using namespace std;
int main() {
int b; int length=5; int j;
for (int i=0;i<length;++i) //here length = 5
{
int b=9;
for (j=0;j<length-i;++j) //for blank spaces
cout<<" ";
for(j=0;j<2*i+1;++j)
{
if(j<(2*i+1)/2) cout<<b--;
else cout<<b++;
}
cout<<"\n";
}
return 0;
}
it is working!
0
posted... : )
0
aint working
0
wow..kudoos