c - Prints numbers in a certain sequence or series -
i trying write code in c print @ given range (0 - 100).
x print 0 3, , 8 11, , 16 19 , on. y print rest, example 4 7, , 12 15, , 20 23 , on.
the output should this:
x = 0 1 2 3 8 9 10 11 ... 93 94 95 96 y = 4 5 6 7 12 13 14 15 ... 97 98 99 100
progress far:
#include <stdio.h> main () { int i, limit, k, divisor; limit = 100; divisor = 4; (i = 0; < limit; i++) { k = i; k = % divisor; printf ("%d \n ", k); } }
but prints 0 3, , keeps repeating. what's wrong?
using %
won't far... k = % divisor;
make sure k
somewhere between [0,4] (since divisor = 4
) not want.
what using 2 loops?
int main(){ int i,j; for(i = 0; < 100; i+=8){ // increment 8 make 0 -> 8 -> 16 jumps for(j = 0; j < 4; j++){ // print 4 values x , y, starting initial value i, , i+4 printf("x = %d\ty = %d\n", i+j, i+j+4); } } return 0; }
Comments
Post a Comment