If you have any query feel free to chat us!
Happy Coding! Happy Learning!
In C language, you can use a for loop to generate the multiplication table of a given number. The basic idea is to iterate from 1 to a given limit and multiply the number by the current iteration number, and print the result.
Here's an example of C code that generates the multiplication table of a given number:
Copy code
#include <stdio.h>
int main() {
int n, limit;
printf("Enter a number: ");
scanf("%d", &n);
printf("Enter the limit of the table: ");
scanf("%d", &limit);
for(int i = 1; i <= limit; i++){
printf("%d x %d = %d\n", n, i, n*i);
}
return 0;
}
This code prompts the user to enter a number and limit of the table. Then it uses a for loop to iterate from 1 to the limit. Within the loop, it multiplies the number by the current iteration number, and prints the result, which is the multiplication table of the given number. It also possible to use while loop instead of for loop to generate the table of a number.
Comments: 0