What's wrong in the below code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What's wrong in the below code?

#include<stdio.h> #include<math.h> void main() { int n, t, i; printf("Enter the value of n: "); scanf("%d ", &n); for(i=1;i<=10;i++) { t=n*i; printf("Table is: %d",t); } }

28th Jan 2019, 12:24 PM
Vivek Sharma
Vivek Sharma - avatar
3 Answers
+ 1
You don't need math.h and it will output "Table is:" for every number which is probably not what you want. Other than that, I don't see any errors. Note that you have to enter all input as soon as you run the program, with one line per input: 77 8 45 3 ... etc.
28th Jan 2019, 12:39 PM
Anna
Anna - avatar
+ 1
I got it, the blank space after %d was causing the error [scanf("%d ", &n);], Anyway thanks for the help.
28th Jan 2019, 12:53 PM
Vivek Sharma
Vivek Sharma - avatar
0
okay, so I modified the code but still I can not get any output #include<stdio.h> void main() { int n, t, i; printf("Enter the value of n: "); scanf("%d ", &n); printf("The table is: "); for(i=1;i<=10;i++) { t=n*i; printf("%d",t); } }
28th Jan 2019, 12:45 PM
Vivek Sharma
Vivek Sharma - avatar