Question: Trace the following program, showing the values of the variables and the output generated by the program. The input file to the program is: 1375

Trace the following program, showing the values of the variables and the output generated by the program. The input file to the program is:

1375 3

8472 2

(SHOW YOUR WORK)

#include

#define BASE 10

int find( int, int);

int extract( int, int);

main()

{

int a, b; int c, d;

while( scanf("%d", &a) != EOF)

{ scanf("%d", &b);

c = find(a, b);

if(c >= 0)

d = extract(a, c);

else d = c;

printf("its %d ", d);

}

}

int find(int a, int b)

{ int i = 0;

while( a % BASE != b)

{ a = a / BASE;

if(a == 0) return -1;

i = i + 1;

}

return i;

}

int extract(int a, int b)

{

while(b)

{

a = a / BASE;

b = b - 1;

}

return a % BASE;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!