Laboratory Assignment Sheet
Graded Lab Assignment 4 – CSF101 Programming for Problem Solving, 2023 – ODD Semester 2023
Your Name: Kesahv Rawat SAP ID:1000021236 Major: BtechCSE ‘S’
Assignment ID (as per the policy guidelines)
|
Assignment Title:
|
Submission Mode:
|
Assessment Method
|
Group/
Individual
|
Weightage:
|
Date of Release:
|
Submission Deadline (Date and time)
|
Graded Lab
|
Graded Lab-4
|
Online [In word file]
|
|
Individual
|
5
|
21/11/2023, 11AM
|
21/11/2023, 12:50PM
|
Instructions:
In this graded lab assignment, you will solve the problem(s) based on what you have learned in Unit 3-5
There are 2 questions in this assignment.
Email/paper/other modes of submission will not be accepted.
Upload a pdf version of this document.
Do not copy the code of other students.
Due Date: 21/11/2023, 12:50PM
Submitting this Assignment
You will submit (upload) this assignment in MS Teams. Name this document as CSF101_SAP-ID_John_Doe.doc in case your name is John Doe. Paste your code and snapshot of output after the question, and save and upload the document.
Grading: 5 points (out of your total 100 points in the course). Full marks will be awarded only when the correct code with a screenshot of your output as desired is submitted.
Problems:
Write a program to print Fibonacci series using recursion.
Code:
#include
int main()
{
int n1=0,n2=1,n3,i,number;
printf("Enter the number of elements:");
scanf("%d",&number);
printf("\n%d %d",n1,n2);
for(i=2;i
{
n3=n1+n2;
printf(" %d",n3);
n1=n2;
n2=n3;
}
return 0;
}
Output:
Write a program to create a structure named book and store book information such as book name, title, author, publisher, price and edition of 5 books using structure. Note: Use the concept of Structures and array of structure.
Code:
#include
struct Book {
char name[300];
char title[300];
char author[300];
char publisher[300];
float price;
int edition;
};
int main() {
struct Book books[5];
for (int i = 0; i < 5; i++) {
printf("Enter details for Book %d:\n", i + 1);
printf("Name: ");
scanf("%s", books[i].name);
printf("Title: ");
scanf("%s", books[i].title);
printf("Author: ");
scanf("%s", books[i].author);
printf("Publisher: ");
scanf("%s", books[i].publisher);
printf("Price: ");
scanf("%f", &books[i].price);
printf("Edition: ");
scanf("%d", &books[i].edition);
printf("\n");
}
printf("Details of 5 books:\n");
for (int i = 0; i < 5; i++) {
printf("Book %d:\n", i + 1);
printf("Name: %s\n", books[i].name);
printf("Title: %s\n", books[i].title);
printf("Author: %s\n", books[i].author);
printf("Publisher: %s\n", books[i].publisher);
printf("Price: %.2f\n", books[i].price);
printf("Edition: %d\n", books[i].edition);
printf("\n");
}
return 0;
}
Output:
Share with your friends: |