Home > OS >  Please help me for the correct My Code looping (C Language)
Please help me for the correct My Code looping (C Language)

Time:11-11

#include <stdio.h>
#include <stdlib.h>

int main()
{ 
    int i;

    for(i=1; i<5; i  )
    {
        printf(" %d Perulangan %d \n ", i);
    }

    return 0;
}

Please help me for the correct My Code looping (C Language) , i want print this output :

    1 perulangan 1
    2 perulangan 2
    3 perulangan 3
    4 perulangan 4 

CodePudding user response:

Super easy to do. Just add in an additional i parameter for the 2nd %d like so:

#include <stdio.h>
#include <stdlib.h>

int main()
{ 
    int i;

    for(i=1; i<5; i  )
    {
        printf(" %d Perulangan %d \n ", i, i);
    }

return 0;
}

CodePudding user response:

One would normally just repeat the argument.

printf("%d Perulangan %d\n", i, i);

Alternatively, a POSIX-compliant compiler will accept references to arguments by position:

printf("%1$d Perulangan %1$d\n", i);
  • Related