+ 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
14 ответов
+ 12
Please show us your attempt.
+ 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");
}
+ 9
Here's my try
https://code.sololearn.com/cl1ztXq3KlPb/?ref=app
+ 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
+ 5
This example will help you to understand better..........
https://code.sololearn.com/c6MsRqtC7Tc9/?ref=app
+ 4
https://code.sololearn.com/caNcieOdUXiL/?ref=app
+ 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.
+ 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.
0
I even don't get the logic so I have posted here
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");
}
0
Meet Mehta I have used that it was restricted to use only two for loops
0
Ramphy Aquino Nova no the code does not work it just print only one single column
0
what do you mean? with me work
- 1
Roshini Rachapalli To print following pattern you will require only two for loops (nested).
Wish you good luck👍👍.