I am a beginner and need help in adding scanf feature in my code
Here is the code :
// Create an array of size 3 x 10 containing multiplication tables of the numbers 2,7 and 9 respectively.
#include <stdio.h>
int t[3][10], n[] = {2, 7, 9}; // t is a 3 x 10 array and n is an array of size 3
void fill(int i, int j) {
if (i == 3) return; // Index out of bounds
t[i][j] = n[i] * (j + 1);
fill(i + (j == 9), (j + 1) % 10);
}
void print(int i, int j) {
if (i == 3) return;
if (j == 0) printf("Table of %d:\n", n[i]);
printf("%d x %d = %d\n", n[i], j + 1, t[i][j]);
print(i + (j == 9), (j + 1) % 10);
}
int main() {
fill(0, 0);
print(0, 0);
return 0;
}
I wanted to make the code as shortest as possible therefore i have used recursion, and now i want to advance it by using scanf function to take input from the user.
I’d really appreciate help on how to:
- Replace the hardcoded n[] with user input using scanf.
- Make sure the recursion still works with that change.