218, exercises, 21-1-99

What do these three programs do? How do they do it?


program a
#include 

void g(int a)
{ int x,y;
  x=a/2;
  y=a%2;
  if (a==0) return;
  g(x);
  printf("%d", y);
  return; }

void main(void)
{ int m;
  scanf("%d",&m);
  g(m);
  printf("\n"); }



program b
#include 

int h(int a)
{ int x,y,z;
  x=a/2;
  y=a%2;
  if (a==0) return (0);
  z=h(x)*10+y;
  return (z); }

void main(void)
{ int m,n;
  scanf("%d",&n);
  m=h(n);
  printf("%d -> %d\n", n, m); }



program c
#include 

int k(int a, int b)
{ int m, x, y, z;
  if (b<=a) return (a);
  m=(a+b)/2;
  x=k(a,m);
  y=k(m+1,b);
  z=x*y;
  return (z); }

void main(void)
{ int m,n;
  scanf("%d",&n);
  m=k(1,n);
  printf("%d -> %d\n", n, m); }