Can anyone please give the code for the following pattern in C without using arrays and only one printf statement: 1 2 6 3 7 10 4 8 11 13 5 9 12 14 15 for the value of n = 5
8/31/2018 8:09:35 AM
Roshini Rachapalli13 Answers
New AnswerRamphy Aquino Nova Your algorithm is a bit off. Try this: for (int row = 0; row < 5; row++) { for (int col = 0; col <= row; col++) printf("%d ", 1 + col * 5 - (col - 1) * col / 2 + row - col); printf("\n"); }
Roshini Rachapalli Here is an easy version The code is self explanatory Using only two for loops and one printf statement as u asked for. https://code.sololearn.com/cDEd35htW3lF/?ref=app
This example will help you to understand better.......... https://code.sololearn.com/c6MsRqtC7Tc9/?ref=app
I can give you direct code but it will not enhance your skill in language. But I am providing you some hints if it helps☺️☺️. Hints : Whenever you want to print patterns use nested for loops.
i dont know how to do but if can help you i show you this: int i,j,k; for(i = 1; i <= 5; i++){ j = i; for(k = 1; k <= i; k++){ printf("%d", j++); } printf("\n"); }
Ramphy Aquino Nova no the code does not work it just print only one single column
Roshini Rachapalli To print following pattern you will require only two for loops (nested). Wish you good luck👍👍.
Learn Playing. Play Learning
SoloLearn Inc.
4 Embarcadero Center, Suite 1455Send us a message