store a table in dynamic array and then change the size of array dynamically to store more numbers
#include <stdio.h>
#include <stdlib.h>
int main()
{
int *ptr;
ptr = (int *)malloc(10 * sizeof(int));
printf("The multiplication table of 7 is:\n");
for (int i = 0; i < 10; i++)
{
ptr[i]=7*i;
printf("7 X %d = %d\n",i+1,ptr[i]);
}
ptr = realloc(ptr, 15 * sizeof(int));
printf("\nThe multiplication table of 7 till 15 is:\n");
for (int i = 0; i < 15; i++)
{
ptr[i]=7*i;
printf("7 X %d = %d\n",i+1,ptr[i]);
}
free(ptr);
return 0;
}
Comments
Post a Comment