A function can receive a value as a parameter and use it to perform a specific task. In this program, the user-defined function table() accepts a number and prints its multiplication table using a for loop. The same function is called multiple times with different numbers to display different tables.
How It Works?
stdio.h and conio.h.table(int no) that accepts a number as a parameter.k inside the function.for loop to print the multiplication table from 0 to 10.main() function, call table(4) and table(6).getch().#include <stdio.h> #include <conio.h> void table(int no) { int k; for(k = 0; k <= 10; k++) { printf("\n %d x %d = %d", no, k, k * no); } } int main() { clrscr(); table(4); table(6); getch(); }
function named table() to print the multiplication table of a given number from 1 to 10. Call the function for the numbers 5 and 8.for loop to print multiplication tables.table(int no). Use a for loop from 1 to 10 and call the function twice from the main() function.
#include <stdio.h> #include <conio.h> void table(int no) { int k; for(k = 1; k <= 10; k++) { printf("\n %d x %d = %d", no, k, no * k); } } int main() { clrscr(); table(5); table(8); getch(); }
table() that accepts a number as a parameter. Inside the function, a for loop prints the multiplication table from 1 to 10. The function is called twice from the main() function to print the tables of 5 and 8, demonstrating how one function can be reused with different arguments.