Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.
/**Bismillahir Rahmanir Rahim.**/ #include <stdio.h> int main() { int x,y, a=0,b=1,c=0; scanf("%d", &x); for(y=1; y<x; y++) { if(y%2==1) { printf("%d ",c); c=a+b; a=c; } else if(y==2) printf("%d ",c); else if(y%2==0) { printf("%d ",c); c=a+b; b=c; } } printf("%d\n",c); return 0; }
#include
ReplyDeleteint main()
{
int a=0,b=1,c=0,n,i;
scanf("%d",&n);
for(i=1;i<n;i++)
{
printf("%d ",a);
c=a+b;
a=b;
b=c;
}
printf("%d\n",a);
}
Obrigado.
ReplyDeleteConsegui resolver com sua ajuda em C#.
using System;
namespace uri1151FibonacciFacil
{
class Program
{
static void Main(string[] args)
{
int n, i, f0 = 0, f1 = 1, f = 0;
n = int.Parse(Console.ReadLine());
for (i = 1; i < n; i++)
{
if (i % 2 == 1)
{
Console.Write(f + " ");
f = f0 + f1;
f0 = f;
}
else if (i == 2)
{
Console.Write(f + " ");
}
else if (i % 2 == 0)
{
Console.Write(f + " ");
f = f0 + f1;
f1 = f;
}
}
Console.WriteLine(f);
}
}
}
i didnt really understand the code
ReplyDelete