Hi,

I would like to print the table of a number entered by the user like

2 *1=2
2*2=4
2*3=6

The code is

#include<stdio.h>
#include<conio.h>

main()

{

int i,num;

printf("Enter any number");
scanf("%d",&num);

for(i=1;i<=num;i++)

printf("%d*%d=%d",num,i,num*i);

getch();

}

But this code is generating errors.

Dani AI

Generated

A few practical notes before the replies below: the original snippet from will often trip modern compilers because of nonstandard bits (for example, <conio.h>/getch()). As advised, prefer a standard signature like int main(void). 's fix shows a correct simple table up to 10; to support a user-chosen upper bound (the question asked) a small, portable program and a couple of checks make the behavior clear and robust.

#include <stdio.h>

int main(void)
{
    int num, range, i;
    printf("Enter number and range (e.g. 5 10): ");
    if (scanf("%d %d", &num, &range) != 2 || range < 1) {
        fprintf(stderr, "Invalid input — expected two integers, range >= 1.\n");
        return 1;
    }
    for (i = 1; i <= range; ++i)
        printf("%d * %d = %d\n", num, i, num * i);
    return 0;
}

Notes and quick tips:

  • Remove <conio.h> and getch() unless you are using an old DOS/Windows-only compiler; they are not portable. Use getchar() or just let the terminal close itself.
  • Always check scanf's return value (shown above). For production code prefer fgets() + strtol() to handle malformed input gracefully.
  • Watch integer overflow: if num and range can be large, compute the product in 64-bit (long long prod = (long long)num * i; and print with %lld).

If you still see compile errors, note the exact text (for example: "fatal: conio.h: No such file or directory" or "implicit declaration of function 'getch'") and mention your compiler (GCC, Clang, MSVC, etc.) so the fixes can be targeted.

Recommended Answers

All 4 Replies

1> 28 posts and still no code tag

2> Try to practice int main(){} not just main() or void main()

3> Post the exact error that u are getting.
The code seems to be ok I think.

The code is perfect and no errors execpt few things that shuold be avoided.
may be you want to print from

5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
:
:
5 * 10 = 50

here is your code with slight modifications and proper posting:
follow this next time

#include<stdio.h>

int main()
{
        int i, num;
        printf( " Enter any number " );
        scanf( "%d", &num );
        for( i=1 ;i <=10; i++ )
            printf( "  \t %d * %d = %d \n ", num, i, num*i ) ;
        return 0;
}

This link was helpful for those looking for C in Unix

i want to make a multiplication table of any number the user input and upto the range the user input

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.