Quantcast
Channel: User Alex Lop. - Stack Overflow
Viewing all articles
Browse latest Browse all 39

Answer by Alex Lop. for Output ',' between number fibonaci in c program

$
0
0

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;    }

Viewing all articles
Browse latest Browse all 39

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>