+ 1

Shortcuting Many If else in one for loop...

if(i==1||j==1||i==2*n-1||j==2*n-1) printf("%d",n); else if(i==2||j==2||i==2*n-2||j==2*n-2) printf("%d",n-1); else if (i==3||j==3||i==2*n-3||j==2*n-3) printf("%d",n-2); else if(i==4||j==4||i==2*n-4||j==2*n-4) printf("%d",n-3); . . . . . . else if(i==k||j==k||i==2*n-k||j==2*n-k) printf ("%d",n-k+1); If k is very big number like 1000 How can I use for loop in it ?

29th May 2019, 6:54 AM
Shakti Vishwakarma
Shakti Vishwakarma - avatar
7 Antworten
+ 3
When checking a <number> printf("%d", n - <number>); But when checking for <k> printf("%d", n - k + 1); Why is this difference? Are you checking from 1 to <k>? What is this big loop program about?
29th May 2019, 7:10 AM
Ipang
+ 2
Yes I want to check 1 to 1000.
29th May 2019, 9:13 AM
Shakti Vishwakarma
Shakti Vishwakarma - avatar
+ 1
Actually I don't know anything about minimum function. So I can't implement in terms of minimum function and hence I used if else to try to implement it... By the way when I used this if else pattern If we write if else statement till k = 3 And I entered the value of N =3 It was working so I thought that If we make a loop for it and The loop depends on the variable k which is dependent on N than we can make the pattern without using any built in function....So I asked
29th May 2019, 11:37 AM
Shakti Vishwakarma
Shakti Vishwakarma - avatar
0
Actually I want the program to implement who will take input as N If N=3 The pattern will look like 33333 32223 32123 32223 33333 If Value of N is 5 Then the pattern shown will be 555555555 544444445 543333345 543222345 543212345 543222345 543333345 544444445 555555555 Where 1 < N <1000
29th May 2019, 11:10 AM
Shakti Vishwakarma
Shakti Vishwakarma - avatar
0
Ohk It worked
29th May 2019, 11:54 AM
Shakti Vishwakarma
Shakti Vishwakarma - avatar
0
Actually I forgot to write break statement that's why it was not working
29th May 2019, 11:54 AM
Shakti Vishwakarma
Shakti Vishwakarma - avatar
0
Thank You So much for your valuable answer 😊
29th May 2019, 11:54 AM
Shakti Vishwakarma
Shakti Vishwakarma - avatar