+ 1

Help me to design a pattern using c or c++

1 6 2 10 7 3 13 11 8 4 15 14 12 9 5

27th Feb 2018, 11:40 AM
Rohit Jarariya
Rohit Jarariya - avatar
3 Antworten
27th Feb 2018, 12:27 PM
Ravi Chandra Enaganti
Ravi Chandra Enaganti - avatar
+ 1
Can you please give further explanation?
27th Feb 2018, 12:22 PM
Timon Paßlick
+ 1
#include<iostream> using namespace std; int getn(int fn) { int ctr=0; for(int i=1;fn!=1;i++) { ctr++; fn-=i; } return ctr; } int main() { int n=5, high; // cin>>n; // Case 1, from number of rows. // cin>>high; n=getn(high); // Case 2, from highest number. int val=1,val2,step,fstep=n; for(int i=0;i<n;i++) { step = n-i; val2=val; for(int j=0;j<=i;j++) { cout<<val2<<" "; val2-=step; step++; } cout<<endl; val += fstep; fstep--; } }
27th Feb 2018, 12:44 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar