Lab 8: For and While: CS-114 Fundamentals of Programming Loop
Lab 8: For and While: CS-114 Fundamentals of Programming Loop
7 Marks 8 Marks
Objectives
The main aim of performing this lab is to understand the concept of (for/while) loops in C.
Lab Instructions
The students should perform and demonstrate each lab task separately for step-wise evaluation
Each group shall submit one lab report on LMS within 6 days after lab is conducted. Lab report
submitted via email will not be graded.
Students are however encouraged to practice on their own in spare time for enhancing their
skills.
Complete as many problems as you can within the allotted time.
Talk to your classmates for help
Lab Report Instructions
All questions should be answered precisely to get maximum credit. Lab report must ensure following
items:
Lab objectives
C codes with proper indentation
Above each line of Code, use two slashes // to write a comment to yourself explaining
what the line does.
Results (screen shots) duly commented and discussed
Conclusion
Task 1
Code:
#define _CRT_SECURE_NO_WARNINGS //macro definition
#include<stdio.h> //standard I/O library
Task 2
Code:
#define _CRT_SECURE_NO_WARNINGS //macro definition
#include <stdio.h> //standard I/O library
printf("The sum of fibonacci series upto %d terms is:%d", n, sum);//print sum of fibonacci series
printf("\n"); //space sequence
return 0; //returning an integer
} //curly braces closed
Comments:
In this lab task we simply enter the number of terms and found the sum of Fibonacci series.
Adding the previous number of terms in the coming number of terms.
Task 3
Code:
#define _CRT_SECURE_NO_WARNINGS //macro definition
#include<stdio.h> //standard I/O library
Conclusion:
In the whole lab tasks we used the while and for loop and in some cases we needed the if-else
statement as well. We also learnt how to find the even number between two number and find
their sum and learnt to print the Fibonacci series as well.