Home › Forums › C Programming › exercise › Reply To: exercise
December 24, 2004 at 2:09 pm
#3125
starfish
Participant
hi frd,
just see if u can find this appropriate….
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #include <iostream><br /> using namespace std;<br /> <br /> main(){<br /> <br /> int a[10];<br /> int n,i,j=0,k;<br /> <br /> cout<<"Enter the value for n: ";<br /> cin>>n;<br /> k=n;<br /> <br /> for (i=0 ;i < 10; i++)<br /> a=i + 1;<br /> <br /> while(k>0){<br /> for(i=(0+j);i<n;i++)<br /> cout<<a<<" ";<br /> for(i=n-2;i>=(0+j);i--)<br /> cout<<a<<" ";<br /> cout<<endl;<br /> j++;<br /> for(i=0;i<j;i++)<br /> cout<<" ";<br /> k--;<br /> }<br /> <br /> return 0;<br /> }<br /> <br /> Output :<br /> <br /> Enter the value for n: 5<br /> 1 2 3 4 5 4 3 2 1<br /> 2 3 4 5 4 3 2<br /> 3 4 5 4 3<br /> 4 5 4<br /> 5 </iostream> |
plz let me know if you have any further queries