The easiest way is to add additional printf
for the ", " string under the condition that it is not the last for
loop iteration
#include<stdio.h> int main() { int x, y = 0, z = 1, r, i; scanf("%d",&x); for ( i = 0 ; i < x ; i++ ) { if ( i <= 1 ) z = i; else { z = x + y; x = y; y = z; } printf("%d",z); if (i < x - 1) { printf(", "); } } return 0; }