+ 9

Pattern in C

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

31st Aug 2018, 8:09 AM
Roshini Rachapalli
Roshini Rachapalli - avatar
14 ответов
+ 12
Please show us your attempt.
31st Aug 2018, 8:14 AM
A Fox
A Fox - avatar
+ 11
Ramphy 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"); }
31st Aug 2018, 11:36 AM
Fox
Fox - avatar
12th Mar 2019, 4:54 AM
Khalid Saifullah Fuad
Khalid Saifullah Fuad - avatar
+ 5
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
31st Aug 2018, 6:23 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 5
This example will help you to understand better.......... https://code.sololearn.com/c6MsRqtC7Tc9/?ref=app
26th Dec 2018, 10:00 AM
Bipin Tatkare
Bipin Tatkare - avatar
+ 4
https://code.sololearn.com/caNcieOdUXiL/?ref=app
31st Aug 2018, 2:33 PM
Käzî Mrîdùl Høssäîn
Käzî Mrîdùl Høssäîn - avatar
+ 2
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.
31st Aug 2018, 8:17 AM
Meet Mehta
Meet Mehta - avatar
+ 1
Here are some C pattern programs for you to learn https://www.techcrashcourse.com/2016/02/c-program-to-print-triangle-pyramid-star-pattern.html hope it helps.
26th Jun 2022, 8:43 AM
Arun Kumar
Arun Kumar - avatar
0
I even don't get the logic so I have posted here
31st Aug 2018, 8:15 AM
Roshini Rachapalli
Roshini Rachapalli - avatar
0
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"); }
31st Aug 2018, 8:18 AM
Ramphy Aquino Nova
Ramphy Aquino Nova - avatar
0
Meet Mehta I have used that it was restricted to use only two for loops
31st Aug 2018, 8:20 AM
Roshini Rachapalli
Roshini Rachapalli - avatar
0
Ramphy Aquino Nova no the code does not work it just print only one single column
31st Aug 2018, 8:27 AM
Roshini Rachapalli
Roshini Rachapalli - avatar
0
what do you mean? with me work
31st Aug 2018, 8:30 AM
Ramphy Aquino Nova
Ramphy Aquino Nova - avatar
- 1
Roshini Rachapalli To print following pattern you will require only two for loops (nested). Wish you good luck👍👍.
31st Aug 2018, 8:29 AM
Meet Mehta
Meet Mehta - avatar