Friday, April 8, 2016

C program to calculate square of a number using recursive function

#include<stdio.h>
int square(int f)
 {
  static int count=0;
  count++;
  printf("%d ",count);
  if(f==1||(count==f))
   return f;
  else
   return (f+square(f));
 }
void main()
{
 int n=4;
 int j=square(n);
 printf("square=%d",j);
}

output
square=16

No comments:

Post a Comment