0% found this document useful (0 votes)
35 views7 pages

Lab 7

This lab report describes experiments on writing programs to calculate Fibonacci series using multiple files and static variables in C programming. The objectives were to learn about multi-file program structure, write a multi-file program, and use static variables. Sample code is provided to calculate Fibonacci series within a range, using multiple files, and with static variables. The discussion concludes that multiple file programs are useful for large programs and easy to understand.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views7 pages

Lab 7

This lab report describes experiments on writing programs to calculate Fibonacci series using multiple files and static variables in C programming. The objectives were to learn about multi-file program structure, write a multi-file program, and use static variables. Sample code is provided to calculate Fibonacci series within a range, using multiple files, and with static variables. The discussion concludes that multiple file programs are useful for large programs and easy to understand.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

RAJSHAHI UNIVERSITY OF ENGINEERING & TECHNOLOGY

Department of Electronics & Telecommunication Engineering

LAB REPORT

Course Code : CSE-1154


Course Title : Sessional based on CSE-1153
Experiment No : 07
Experiment Name : Experimental study on multiple file using
project and usage of static and extern storage class
Date of Experiment : 11.11.2020
Date of Submission : 18.11.2020

Submitted By: Submitted To:


Roll: 190438 Hasan Sarker
Year: 1st year (ODD) Lecturer
Dept. of ETE, RUET

Page 1 of 7
Objectives: The main objectives of this experiment are
1. To learn about multi-file program structure
2. To learn how to write a multi-file program
3. To write a program for Fibonacci series
4. To write a program for Fibonacci series using multi-file program
5. To write a program for Fibonacci series using static variable

Theory:
Multiple file program is a very efficient and significant structure in C programming language.
When different functions are defined in different files and at the end all of them are linked
together and executed as a single program, is called a multi-file program. In multi-file program a
large C program can be divided into multiple files, which makes each file short enough to
conveniently edit and compile. External storage class is very useful to call a global variable in
multi-file program. So, the facility of editing and debugging of a large C program can be easily
maintained by writing multi-file program.

Extern Storage Class:

Extern storage class is used when we have global functions or variables which are shared
between two or more files. Keyword extern is used to declare a global variable in another file to
provide the reference of variable or function which have been already defined in the original file.

Static Storage Class:


The static storage class are used for both local and global variables. For static variables, memory
is defined only once at the beginning. Storage duration of a static variable remains until the
program terminates. Static variables are defined with keyword static.

Fibonacci Series:
Fibonacci series is the set of numbers in which each number is the sum of the two preceding
ones, starting from 0 and 1. If Fn is denoted as nth Fibonacci number then,
Fn = Fn-1 + Fn-2 ,where n > 1

Software used in lab: Codeblocks.

Page 2 of 7
Sample Code:

Experimental Study:
Problem 1: Write a multi-file program which shows values of two variables and a message.
main.c
#include <stdio.h>
extern int a,b;
extern void func (void);
int main()
{
printf("Value of a=%d & b=%d\n",a,b);
printf("Sum of a and b = %d\n",a+b);
func();
return 0;
}

Multifile1.c
int a = 10;

Multifile2.c
int b = 15;

Multifile3.c

void func (void)


{
printf("\nHello everyone! I am COVID-19 \nDo social distancing and wear mask properly\n");
}

Page 3 of 7
Output for problem 1:

Figure 1: Output of a multi-file program.


Problem 2: Write a program of Fibonacci series within a given range.
Sample Code:
#include<stdio.h>
int main(){
int n, t1=0, t2=1, t3;
printf("Enter the value of n: ");
scanf("%d",&n);
printf("\nFibonacci series : ");
while(t1<n){
printf("%d ",t1);
t3=t1+t2;
t1=t2;
t2=t3;
}
printf("\n");
}

Output for problem 2:

Figure 2: Output of Fibonacci series in a given range.

Page 4 of 7
Problem 3: Write a program of Fibonacci series using multi-file.
Sample Code:
main.c

#include<stdio.h>
extern int func();
int main(){
int n;
printf("Enter the value of n: ");
scanf("%d",&n);
printf("\nFibonacci series: ");
func(n);
printf("\n"); }
Fibo_1.c
int func (int n)
{
int t1=0, t2=1, t3=0 ;
printf("%d ",t3);
while(t2<n)
{
printf("%d ",t2);
t3 = t1+t2;
t2 = t1;
t1 = t3;
}
}

Output for problem 3:

Figure 3: Output of Fibonacci series using multi-file.

Page 5 of 7
Problem 4: Writing a program of Fibonacci series using static variable.
Sample Code:
#include<stdio.h>
int func (int);
int main(){
int n;
printf("Enter the value of n: ");
scanf("%d",&n);
printf("\nFibonacci series: ");
func(n);
printf("\n"); }

int func (int n)


{
static int t1=0, t2=1, t3;
printf("%d ",t3);
while(t2<n)
{
printf("%d ",t2);
t3 = t1+t2;
t2 = t1;
t1 = t3;
}
}

Output for problem 4:

Figure 3: Output of Fibonacci series using static variable.

Page 6 of 7
Discussion: In the experiment we have learnt to find Fibonacci series using multi-file program.
We have declared global variables at the beginning of the main file using extern storage class.
Function prototypes of user-defined functions referenced in each file are declared at the start of
the main file. We have carefully written the code and used semicolon after ending every
statement.

Conclusion: Multiple file program is useful when the program is very large and hard to
maintain.
We can easily edit any part of the program while the program is split into multiple files. Time
complexity can be reduced using multiple files. Multiple file program is easy to understand. So,
we should properly learn the structure of multiple file program to write an elegant and efficient
program.

Page 7 of 7

You might also like