CodeChef Solution CHN08 - Crazy Malvika discovers Crazy Fibonacci function in C | Beginner - Online Judge Solution

Latest

It is a free Online judges problems solution list. Here you can find UVA online Judge Solution, URI Online Judge Solution, Code Marshal Online Judge Solution, Spoz Online Judge Problems Solution

Sunday, May 7, 2017

CodeChef Solution CHN08 - Crazy Malvika discovers Crazy Fibonacci function in C | Beginner

CodeChef Solution  CHN08 - Crazy Malvika discovers Crazy Fibonacci function in C | Beginner


CodeChef Online Judge Solution  CHN08 - Crazy Malvika discovers Crazy Fibonacci function| Beginner
CodeChef Main Problem Link -

Problem Name: CodeChef Problem CHN08 - Crazy Malvika discovers Crazy Fibonacci function
Problem Number : CodeChef Problem CHN08 - Crazy Malvika discovers Crazy Fibonacci function Solution
Online Judge : CodeChef Online Judge Solution
Level: Beginner


Code: CHN08
Solution Language : C

CodeChef Solution  CHN08 - Crazy Malvika discovers Crazy Fibonacci function in C | Beginner

Learn Basic Of Fibonacci Algorithm:



CodeChef Solution CHN08 Code in C:



#include <stdio.h>

int make_mod(int a, int b)
{
 int r = a % b;
 return r < 0 ? r + b : r;
}

int fib(int a, int b, int x)
{
 switch(x%6)
 {
  case 1:
      return a;
  case 2:
      return b;
  case 3:
      return b - a;
  case 4:
      return -a;
  case 5:
      return -b;
  case 0:
      return -b + a;
 }
}

int main()
{
    int a,b,n,r,t,i;
    scanf("%d",&t);

    for(i=0; i < t; i++)
    {
     scanf("%d %d %d", &a, &b, &n);
     r = fib(a,b,n);
     printf("%d\n",make_mod(r, 1000000000+7));
    }

 return 0;
}

1 comment:

  1. Learn More at devsenv - https://devsenv.com/codes/code-example-with-fibanoacci-numbers

    ReplyDelete