View Code of Problem 108

#include <stdio.h>
#include <string.h>
#include <math.h>
int main()
{
	 long int a,i,sum,j;
	  long int x[100];
	  char c;
	  char b[50];
	  x[0]=1;
	  x[1]=2;
	  scanf("%d",&a);
	  c=getchar();
	  for(i=0;i<a;i++)
	  {
		  scanf("%s",&b);
          sum=strlen(b);
		  if(sum==1)
		  {
			  printf("1\n");
		  }
		  else if(sum==2)
		  {
			  printf("2\n");
		  }
		  else
		  {
			  for(j=2;j<sum;j++)
			  {
				  x[j]=x[j-1]+x[j-2];
			  }
			  printf("%ld\n",x[j-1]);
		  }
        
	  }
}

Double click to view unformatted code.


Back to problem 108