Show all ur work Write a C program using that uses a for loop which loops three
ID: 3546337 • Letter: S
Question
Show all ur work
Write a C program using that uses a for loop which loops three times and calls function int isleap (int) to return whether or not a year is a leap year. The result should be output in the main program. Next the main program should use a do while loop to call function void Fibonacci (int) to produce the first n Fibonacci numbers. The function receives as an argument integer n and outputs all results within this function. Note that the set of Fibonacci numbers is a sequence of numbers that increase rapidly. They were originally intended to model the growth of a rabbit colony.Explanation / Answer
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
int isLeap(int year)
{
if(year % 100 == 0)
{
if(year % 400 == 0)
return 1;
return 0;
}
if(year % 4 == 0)
return 1;
return 0;
}
void Fibonacci(int i)
{
int s1 = 1, s2 = 0, s3;
printf("The first %d fibanacci numbers are: ",i);
while(i>0)
{
s3 = s1 + s2;
printf("%d ",s3);
s1 = s2;
s2 = s3;
}
}
int main()
{
printf("Enter Three Year: ");
int i,num,ret;
for(i=0;i<3;i++)
{
scanf("%d",&num);
ret = isLeap(num);
if(ret == 0)
printf("%d is not a leap year ",num);
else
printf("%d is a leap year ",num);
}
printf("Enter n: ");
scanf("%d",num);
Fibonacci(num);
}