0% found this document useful (0 votes)
28 views13 pages

Aditya 4

The document contains a lab record for the course "Programming for Problem Solving" submitted by Aditya Kumar. It includes 7 experiments conducted in the lab - 1) Finding factorial using recursion, 2) Converting decimal to binary using recursion, 3) Evaluating recursive series, 4) Defining and using a time structure, 5) Creating and using a book structure, 6) Defining and using a person structure, 7) Defining and using a cricket player structure. For each experiment, the code and output is provided.

Uploaded by

saksham arora
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views13 pages

Aditya 4

The document contains a lab record for the course "Programming for Problem Solving" submitted by Aditya Kumar. It includes 7 experiments conducted in the lab - 1) Finding factorial using recursion, 2) Converting decimal to binary using recursion, 3) Evaluating recursive series, 4) Defining and using a time structure, 5) Creating and using a book structure, 6) Defining and using a person structure, 7) Defining and using a cricket player structure. For each experiment, the code and output is provided.

Uploaded by

saksham arora
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Lab Record

of

Programming for Problem Solving


(CSF101)

BACHELOR OF TECHNOLOGY
In

COMPUTER SCIENCE AND ENGINEERING

Session 2023-24

Submitted to: - Submitted by: -

Sumita Lamba Name: Aditya Kumar


Assistant Professor Roll No.: 230102198
School of Computing Sap ID: 1000019772
DIT University, Dehradun Class/Section: S

SCHOOL OF COMPUTING
DIT UNIVERSITY, DEHRADUN
(State Private University through State Legislature Act No. 10 of 2013 of Uttarakhand and approved by UGC)
Mussoorie Diversion Road, Dehradun, Uttarakhand - 248009, India.

August-December 2023
INDEX

CONDUCTION INSTRUCTOR’s
S.NO. NAME OF THE EXPERIMENTS
DATE SIGNATURE
WAP to find factorial of a given number using
1
recursion.
WAP to convert decimal numbers into binary
2
numbers using recursion.
WAP to use recursive calls to evaluate F(x)=x-
3
x^3/3!+x^5/5!-x^7/7!+…..+x^n/n!
Define a structure data type called time_struct
containing three members’ integer hours,minutes
4 and seconds.Develop a program that assigns values
to individual members and displays time in the
following format :HH:MM:SS.
WAP to create the book’s structure with
5 title,author name,publication,and price.Read data
of n books and display them.
Define a structure person that would contain the
person’s name,date of joining,and salary using this
6
structure to read this information of 5 people and
print the same on screen.
Using cricket,declare an array player with 50
elements and WAP to read the information about
7 all the 50 players and print a team-wise list
containing players’ names with their batting
average.

Aditya Kumar 230102198 B. Tech (1st Semester, Section-I)


School of Computing
Practical-01
Objective: WAP to find factorial of a given number using recursion.
Code:

#include <stdio.h>
int fact(int x)
{
if(x==0||x==1)return 1;
else
return x*fact(x-1);
}
void main() {
int n;
printf("Enter a number ");
scanf("%i",&n);
printf("Factorial =%i",fact(n));
}
Output:

Aditya Kumar 230102198 B. Tech (1st Semester, Section-I)


School of Computing
Practical-02
Objective: WAP to convert decimal numbers into binary numbers using recursion.
Code:

#include <stdio.h>
int convert(int x)
{
if (x==0)
return 0;
else
return (x%2+10*convert(x/2));
}
void main()
{
int n;
printf("Enter a number ");
scanf("%i",&n);
printf("Binary representative: %i",convert(n));
}
Output:

Aditya Kumar 230102198 B. Tech (1st Semester, Section-I)


School of Computing
Practical-03
Objective: WAP to use recursive calls to evaluate F(x)=x-x^3/3!+x^5/5!-
x^7/7!+…..+x^n/n!
Code:

#include<stdio.h>
int fact(int x)
{
if(x==0||x==1)return 1;
else
return x*fact(x-1);
}
double power(double x, int n) {
if (n == 0) {
return 1.0;
} else {
return x * power(x, n - 1);
}
}
double series(int n, double x) {
if (n == 0)
return 0;
else {
double term=power(-1,n-1)*power(x,2*n-1)/fact(2*n-1);
return term+series(n-1,x);
}
}
double sum(int x, int n)

Aditya Kumar 230102198 B. Tech (1st Semester, Section-I)


School of Computing
{
if(n==0)
return 0;
else
return series(x,n)+ series(x,n-1);
}
void main() {
int n,x;
printf("Enter the value of x: ");
scanf("%i", &x);
printf("Enter the number of terms (n): ");
scanf("%i", &n);
printf("The sum of the series up to %i terms is: %f\n",n,sum(x,n));
}
Output:

Aditya Kumar 230102198 B. Tech (1st Semester, Section-I)


School of Computing
Practical-04
Objective: Define a structure data type called time_struct containing three members’
integer hours,minutes and seconds.Develop a program that assigns values to individual
members and displays time in the following format :HH:MM:SS.
Code:

#include <stdio.h>
struct time_struct {
int hours;
int minutes;
int seconds;
};
void main() {
struct time_struct my_time = {12, 34, 56};
printf("Time: %02d:%02d:%02d\n", my_time.hours, my_time.minutes,
my_time.seconds);
}
Output:

Aditya Kumar 230102198 B. Tech (1st Semester, Section-I)


School of Computing
Practical-05
Objective: WAP to create the book’s structure with title,author name,publication,and
price.Read data of n books and display them.
Code:

#include <stdio.h>
struct book {
char title[100];
char author[100];
char publication[100];
float price;};
void main() {
int n;
printf("Enter the number of books: ");
scanf("%d", &n);
struct book library[n];
for (int i = 0; i < n; i++) {
printf("\nEnter details for Book %d:\n", i + 1);
printf("Title: ");
scanf("%s", library[i].title);
printf("Author: ");
scanf("%s", library[i].author);
printf("Publication: ");
scanf("%s", library[i].publication);
printf("Price: ");
scanf("%f", &library[i].price);
}
printf("\nDisplaying Information for %d Books:\n", n);

Aditya Kumar 230102198 B. Tech (1st Semester, Section-I)


School of Computing
for (int i = 0; i < n; i++) {
printf("\nBook %d:\n", i + 1);
printf("Title: %s\n", library[i].title);
printf("Author: %s\n", library[i].author);
printf("Publication: %s\n", library[i].publication);
printf("Price: %.2f\n", library[i].price);}
}
Output:

Aditya Kumar 230102198 B. Tech (1st Semester, Section-I)


School of Computing
Practical-06
Objective: Define a structure person that would contain the person’s name,date of
joining,and salary using this structure to read this information of 5 people and print the
same on screen.
Code:

#include <stdio.h>
struct person {
char name[50];
char date_of_joining[20];
float salary;
};
void main() {
int num_persons = 5;
struct person employees[num_persons];
for (int i = 0; i < num_persons; i++) {
printf("\nEnter details for Person %d:\n", i + 1);
printf("Name: ");
scanf("%s", employees[i].name);
printf("Date of Joining: ");
scanf("%s", employees[i].date_of_joining);
printf("Salary: ");
scanf("%f", &employees[i].salary);
}
printf("\nDisplaying Information for %d Persons:\n", num_persons);
for (int i = 0; i < num_persons; i++) {
printf("\nPerson %d:\n", i + 1);
printf("Name: %s\n", employees[i].name);

Aditya Kumar 230102198 B. Tech (1st Semester, Section-I)


School of Computing
printf("Date of Joining: %s\n", employees[i].date_of_joining);
printf("Salary: %.2f\n", employees[i].salary);
}
}
Output:

Aditya Kumar 230102198 B. Tech (1st Semester, Section-I)


School of Computing
Practical-07
Objective: Using cricket,declare an array player with 50 elements and WAP to read the
information about all the 50 players and print a team-wise list containing players’
names with their batting average.
Code:

#include <stdio.h>
struct cricket_player {
char name[50];
float batting_average;
};
void main() {
int num_players = 5;
struct cricket_player players[num_players];
for (int i = 0; i < num_players; i++) {
printf("\nEnter details for Player %d:\n", i + 1);
printf("Name: ");
scanf("%s", players[i].name);
printf("Batting Average: ");
scanf("%f", &players[i].batting_average);
}
printf("\nDisplaying Information for %d Cricket Players:\n", num_players);
for (int i = 0; i < num_players; i++) {
printf("\nPlayer %d:\n", i + 1);
printf("Name: %s\n", players[i].name);
printf("Batting Average: %.2f\n", players[i].batting_average);}
}

Aditya Kumar 230102198 B. Tech (1st Semester, Section-I)


School of Computing
Output:

Aditya Kumar 230102198 B. Tech (1st Semester, Section-I)


School of Computing

You might also like