Solução: Problema da seqüência de Fibonacci (Márcio Trindade)

From AdonaiMedrado.Pro.Br
Revision as of 16:28, 3 April 2009 by 200.17.147.2 (Talk) (New page: <code lang="c"> #include <stdio.h> int main(void) { int i,z,x=0,y=0,w=1,n; do { printf("digite um numero\n"); scanf("%d",&n); } while ((n<0)||(n>40)); if ...)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
#include <stdio.h>
 
 
 
int main(void)
 
{
 
	int i,z,x=0,y=0,w=1,n;
 
 
 
	do
 
	{
 
		printf("digite um numero\n");
 
		scanf("%d",&n);
 
 
 
	} while ((n<0)||(n>40));
 
 
 
if (n==0)
 
	{printf("0\n");
 
}
 
if (n==1)
 
{printf("0\n");
 
}
 
if (n>1)	{
 
printf("0\n");
 
for (i=0;i<n;i++)
 
	    	{
 
	    		z=x+y+w;
 
			y=x;
 
	    		w=0;
 
			x=z;
 
			printf("%d\n",z);
 
 
 
		}
 
}	    		    		    	
 
	    return 0;
 
}