Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors

Write a c program to get table of a number

Here’s a C program that takes an input number from the user and prints its multiplication table up to 10.

#include <stdio.h>

int main() {
    int num, i;
    
    // Get input from user
    printf("Enter a number: ");
    scanf("%d", &num);
    
    // Print table up to 10
    for (i = 1; i <= 10; i++) {
        printf("%d x %d = %d\n", num, i, num * i);
    }
    
    return 0;
}

Here’s how it works:

  • The program first declares two integer variables num and i.
  • The user is prompted to enter a number using printf and scanf.
  • The for loop runs 10 times, with i starting at 1 and increasing by 1 each iteration until it reaches 10.
  • Within each iteration of the loop, the program prints the current number being multiplied (num), the current multiplier (i), and the result of the multiplication (num * i) using printf.
  • After the loop completes, the program exits with a return value of 0.

When the program is run, it will ask the user to enter a number. Once the user enters a number and presses Enter, the program will print the multiplication table for that number up to 10.

For example, if the user enters 5, the program will output:

Enter a number: 5
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50