0

how to use nested for loop for getting following output: 5,4,3,2,1 5,4,3,2 5,4,3 5,4 5

30th Oct 2018, 10:28 AM
Ahmad Asif
Ahmad Asif - avatar
3 Antworten
+ 3
At least indicate the language you refer to in "Relevant Tags" section. In C or C++ the following main function will work. int main() { int size = 5; for(int row = size; row; row--) for(int col = 0; col < row; col++) printf("%d%c", size - col, (col < row - 1 ? ',' : '\n')); return 0; }
30th Oct 2018, 11:00 AM
Ipang
+ 2
in C would do this: #include <stdio.h> int main(){ int cont = 1; for(int i = 0; i < 5; i++){ for(int a = 5; a >= cont; a--){ printf("%d", a); } printf("\n"); cont++; } }
30th Oct 2018, 10:47 AM
Ramphy Aquino Nova
Ramphy Aquino Nova - avatar
+ 1
Which language do you want it in? In c++ I would do this: int num = 5; for (int i=num; i>0; i--) { for (int j=num; j>num-i; j--) { cout << j; } cout << endl; }
30th Oct 2018, 10:45 AM
jtrh
jtrh - avatar