You are on page 1of 4

National University of Sciences and Technology (NUST)

SMME

LAB REPORT
LAB REPORT # 8

COURSE : Fundamentals of Programming

SUBMITTED BY : Altaf Ahmad (250282)

SUBMITTED TO: Ahmad Subhani

SECTION : ME-10 A

DATE : November 22,2018


Program#1:
(a): Print the Fibonacci sequence to Nth number (Take N from user):
Code:

Description:
Fibonacci Sequence is a special sequence of numbers in which after first 2 digits, each
number is a sum of the previous two numbers. The purpose of this program is to take 4 digits
from user and check if they belong to the Fibonacci sequence or not.
Explanation:
After loading the preprocessor directives and the standard libraries, four integer
variable named a,b,c and d are declared, then three double variables k, j and m are declared
with initial values of 1. The program then asks the user to enter four numbers, these four
numbers are saved in a, b, c and d respectively. A while loop is used to execute for Fibonacci
series and as long as the last digit entered by the user does not become equal to m which
shows the Fibonacci numbers in series, the loop has to repeat. When the first digit becomes
equal to Fibonacci number, then the program checks for the next condition, whether the
second digit entered by the user is the next Fibonacci number from the first, then, it checks the
third condition. But if not, then the program tells that the numbers are not in Fibonacci
sequence by the use of if and else. Similarly, if the third digit comes to be a Fibonacci number
which is the consecutive next number of first digit (sum of first two digits), then it checks for
the fourth condition which checks if the fourth digit is the sum of third and fourth digits. If it is
true, the program states that the given sequence of numbers belong to Fibonacci. If any of the
condition is false, then the program tells the user that the given sequence of numbers do not
belong to Fibonacci sequence.

Output:

Explanation:
In the output, the program at first asks the user to enter four numbers. The program
then checks the conditions as if they are consecutive numbers of a Fibonacci sequence, if yes, it
prints that they belong to Fibonacci Sequence. If not, then it prints that they do not belong to
Fibonacci Sequence.
Flowchart:

You might also like