+ 2

Counting n numbers using C

please help me by providing code for counting n numbers (ex- like o-9 displaying these numbers one by one by replacing it) using C

18th Oct 2017, 8:49 AM
Anandhu krishna
Anandhu krishna - avatar
11 Answers
+ 2
#include <stdio.h> int main(){ unsigned n, i; unsigned long long sum = 0; while(scanf("%u",&n) < 1) puts("Bad input, try again (an unsigned integer)"); for(i = 1; i <= n; ++i, sum += i) printf("i = %u\n",i); printf("sum = %llu\n", sum); return 0; }
18th Oct 2017, 12:38 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
+ 2
#include <stdio.h> /* for the sleep function, unix dependant */ #include <unistd.h> int main(){ unsigned n, i; while(scanf("%u",&n) < 1) puts("Bad input, try again"); putchar('\n'); for(i = 0; i <= n; ++i){ printf("\r%d",i); fflush(stdout); sleep(1); } return 0; }
18th Oct 2017, 6:34 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
+ 1
tanx for ur answer
18th Oct 2017, 9:27 AM
Anandhu krishna
Anandhu krishna - avatar
+ 1
any c code ?
18th Oct 2017, 9:27 AM
Anandhu krishna
Anandhu krishna - avatar
+ 1
thank you for the code, but this is'nt the code that i want. i think you guys dont get my question.i will tell the program once more A c program to Displaying n elements (ex 0-9) by overwriting the number itself.
18th Oct 2017, 2:27 PM
Anandhu krishna
Anandhu krishna - avatar
+ 1
#baptiste sir , ex- when i input 9 the program should print 0 -9 in one line. (1 st print 0 then overwright 0 with 1 then overright 1 with 2 .... upto 9
18th Oct 2017, 3:12 PM
Anandhu krishna
Anandhu krishna - avatar
+ 1
The numbers should print like a video with 1 or 2 second delay
18th Oct 2017, 3:16 PM
Anandhu krishna
Anandhu krishna - avatar
+ 1
I think u guys got what i mean.
18th Oct 2017, 3:17 PM
Anandhu krishna
Anandhu krishna - avatar
+ 1
#swim u comes close to it but not this when i enter 4 it should print 0-4 first it should print 0, immediatly it should replaced by 1 and then replace 1 by 2 and so on upto 4 this should execute like a loop manner it should continuesly run
18th Oct 2017, 3:33 PM
Anandhu krishna
Anandhu krishna - avatar
+ 1
Obviously, my last solution (with sleep and fflush) does not work on sololearn
18th Oct 2017, 6:35 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
0
In which way, overwriting?
18th Oct 2017, 2:40 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar