mercredi 4 janvier 2017

C programming pattern

1
2 4 6
1 3 5 7
2 4 6 8 10
1 3 5 7 9 11 13


#include <stdio.h>
main(){
int i,j,k=1;
for(i=1;i<=5;i++){
    for(j=1;j<=i;j++){
        printf("%d",k);
        k+=2;
    }
    printf("\n");
}

}

This c pattern has 1 extra integer in the 2nd row and last row. How do make it 1 and 2 constantly.

Aucun commentaire:

Enregistrer un commentaire