Brijesh 1
Brijesh 1
CONDUCTION INSTRUCTOR’s
S.NO. NAME OF THE EXPERIMENTS
DATE SIGNATURE
Write a program to find the factorial of a given
1
number using recursion.
WAP to convert decimal numbers into binary using
2
recursion.
WAP to use recursive calls to evaluate F(x) = x –
3
x3/3! + x5/5! – x7/7! + … + xn/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 the time in the
following format : HH:MM:SS.
WAP to create the book's structure with title,
5 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
6
this 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.
Practical-01
Objective: Write a program to find the factorial of a given number using recursion.
Code:
#include <stdio.h>
factorial(int n) {
if (n == 0 || n == 1) {
return 1; // Base case: 0! and 1! are both 1
} else {
return n * factorial(n - 1); // Recursive case
}
}
int
mai
n() {
int
num
;
return 0;
}
Output:
Code:
#include <stdio.h>
int main() {
int decimalNumber;
printf("\n");
return 0;
}
Code:
#include <stdio.h>
recursion double factorial(int n) { if (n == 0
|| n == 1) {
return 1;
} else {
return n * factorial(n - 1); // Recursive case
}
}
series(double x, int n) {
if (n == 0) {
return x; // Base case: F(x) = x when n = 0
} else {
double term = (n % 2 == 0) ? -1 : 1; // Alternating signs
return term * (pow(x, 2 * n + 1) / factorial(2 * n + 1)) + series(x, n - 1);
}
}n printf("Enter the value of x: "); scanf("%lf", &x); printf("Enter the value of n: ");
scanf("%d", &n);
F(x) printf("F(x) = %.4f\n", series(x,
n));
return 0;
}
Output:
Code:
#include <stdio.h>
int main() {
variable struct time_struct myTime;
scanf("%d", &myTime.hours);
return 0;
}
Output:
Code:
#include <stdio.h>
data type struct book {
char
title[100]; char
author[100]; char
publication[100];
float price;
};
int main (){
int n
// Input the number of books
printf("Enter the number of books:
"); scanf("%d", &n);
// Input title
printf("Title: ");
scanf(" %[^\n]s", books[i].title);
// Input publication
printf("Publication: ");
scanf(" %[^\n]s", books[i].publication);
scanf("%f", &books[i].price);
printf("\n");
}
printf("Details of the books:\n");
for (int i = 0; i < n; i++)
Brijesh prasad Roll No: 230105093 B. TechIT (1st Semester, Section-K)
School of Computing
{
printf("Book#%d\n",i+1);
printf("Title:%s\n", books[i].title);
printf("Author: %s\n", books[i].author);
printf("Publication:%s\n",books[i].public);
printf("Price: $%.2f\n", books[i].price);
printf("\n");
}
return 0;
}
Output:
Code:
#include <stdio.h>
int main() {
// Declare an array of person
structures struct person people[5];
// Input name
printf("Name: ");
scanf(" %[^\n]s", people[i].name);
// Input date of
joining printf("Date of
Joining: ");
scanf(" %[^\n]s", people[i].dateOfJoining);
// Input salary
printf("Salary: $");
scanf("%f", &people[i].salary);
printf("\n");
}
Output:
Code:
#include <stdio.h>
type struct
cricket_player { char
name[100]; float battingAverage; char team[50];
};
int main() {
// Declare an array of cricket_player
structures struct cricket_player players[50];
// Input name
printf("Name: ");
scanf(" %[^\n]s", players[i].name);
// Input batting
average
printf("Batting
Average: ");
scanf("%f", &players[i].battingAverage);
// Input team
printf("Team: ");
scanf(" %[^\n]s", players[i].team);
printf("\n");
Brijesh prasad Roll No: 230105093 B. TechIT (1st Semester, Section-K)
School of Computing
}