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
3 Réponses
+ 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;
}
+ 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++;
    }
}
+ 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;
    }






