0% found this document useful (0 votes)
4 views10 pages

PPS_Practical File Format

The document contains practical programming assignments for the subject 'Programming for Problem Solving' with the enrollment number ET23BTCO111. It includes C programs for calculating factorial using recursion, defining structures for time and personal information, sorting player data, swapping values using pointers, and sorting an array using pointers. Each practical includes the aim, C program code, and output sections.

Uploaded by

jhnbsomers7cnbb
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)
4 views10 pages

PPS_Practical File Format

The document contains practical programming assignments for the subject 'Programming for Problem Solving' with the enrollment number ET23BTCO111. It includes C programs for calculating factorial using recursion, defining structures for time and personal information, sorting player data, swapping values using pointers, and sorting an array using pointers. Each practical includes the aim, C program code, and output sections.

Uploaded by

jhnbsomers7cnbb
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/ 10

Subject Code: BTCO12107 Subject Name: Programming for Problem Solving

Enrollment No:ET23BTCO111 Name:Patel Kakshkumar Mukeshbhai

Practical No:45

AIM:Write a program to find factorial of a number using recursion.

C Program:
#include <stdio.h>
int factorial(int n);
int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);
printf("Factorial of %d is %d\n", num, factorial(num));
return 0;
}
int factorial(int n) {
if (n == 0 || n == 1)
return 1;
else
return n * factorial(n - 1);
}

Output:

SCET/CO/2023-24/EVEN/B.Tech/SEM2/Div-F Page No.93


Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Enrollment No:ET23BTCO111 Name:Patel Kakshkumar Mukeshbhai

Practical No:46
AIM:Define a structure data type called time_struct containing three
members’ - integer hour, integer minute and integer second. Develop
a program that would assign values to the individual number and
display the time in the format: (16: 40: 51).
C Program:
#include <stdio.h>
struct time_struct
{
int hour;
int minute;
int second;
}t;
int main()
{
struct time_struct time;
printf("\n enter hour :");
scanf("%d",&t.hour);
printf("\n enter minute :");
scanf("%d",&t.minute);
printf("\n enter second :");
scanf("%d",&t.second);
printf("\n time %d:%d:%d",t.hour%12, t.minute%60,
t.second%60);
return 0;
}
Output:

SCET/CO/2023-24/EVEN/B.Tech/SEM2/Div-F Page No.94


Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Enrollment No:ET23BTCO111 Name:Patel Kakshkumar Mukeshbhai

Practical No:47

AIM:Define a structure called ‘personal’ that contains person name,


date of joining and salary. Using this structure, write a program to
read personal information of 5 people and print the same on
screen.

C Program:
#include <stdio.h>
struct personal
{
char name[50];
char date_of_joining[20];
float salary;
}info[5];
int main()
{
printf("Enter personal information for 5 people:\n");
for(int i = 0; i < 5; i++)
{
printf("\nPerson %d:\n", i+1);
printf("Name: ");
scanf("%s", info[i].name);
printf("Date of Joining: ");
scanf("%s", info[i].date_of_joining);
printf("Salary: ");
scanf("%f", &info[i].salary);
}
printf("\n\nPersonal Information of 5 People:\n");
for(int i = 0; i < 5; i++)
{
printf("\nPerson %d:\n", i+1);
printf("Name: %s\n", info[i].name);
printf("Date of Joining: %s\n", info[i].date_of_joining);
printf("Salary: %.2f\n", info[i].salary);
}
SCET/CO/2023-24/EVEN/B.Tech/SEM2/Div-F Page No.95
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Enrollment No:ET23BTCO111 Name:Patel Kakshkumar Mukeshbhai

return 0;
}

Output:

SCET/CO/2023-24/EVEN/B.Tech/SEM2/Div-F Page No.96


Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Enrollment No:ET23BTCO111 Name:Patel Kakshkumar Mukeshbhai

SCET/CO/2023-24/EVEN/B.Tech/SEM2/Div-F Page No.97


Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Enrollment No:ET23BTCO111 Name:Patel Kakshkumar Mukeshbhai

Practical No:48

AIM:Define a structure called ‘cricket’ that will describe the


following information:
Player name, Team name, Batting average Using cricket, declare an
array ‘player’ with 5 elements and write a C program to read the
information about all the 5 players and print team wise list containing
names of players with their batting average.

C Program:
#include<stdio.h>
#include<string.h>
struct cricket
{
char player_name[20];
char team_name[20];
float bat_avg;
}p[5],t;
int main (){
int i=0,j=0,n=5;
for (i=0;i<n;i++)
{
printf("\n enter player name :");
scanf("%s",&p[i].player_name);
printf("\n enter team name :");
scanf("%s",&p[i].team_name);
printf("\n enter batting average :");
scanf("%f",&p[i].bat_avg);
}
for(i=0;i<n-1;i++)
{
for(j=1;j<n;j++)
{
if(strcmp(p[i].team_name,p[j].team_name)>0)
{
t=p[i];
SCET/CO/2023-24/EVEN/B.Tech/SEM2/Div-F Page No.98
Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Enrollment No:ET23BTCO111 Name:Patel Kakshkumar Mukeshbhai

p[i]=p[j];
p[j]=t;

}
}
j=0;
for(i=0;i<n;i++)
{
if(strcmp(p[i].team_name,p[j].team_name)!=0||i==0)
{
printf("In team name=%s",p[i].team_name);
j=1;
}
printf("\n Player Name = %s",p[i].player_name);
printf("\n Batting Avg = %f",p[i].bat_avg);
}
}
return 0;
}

SCET/CO/2023-24/EVEN/B.Tech/SEM2/Div-F Page No.99


Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Enrollment No:ET23BTCO111 Name:Patel Kakshkumar Mukeshbhai

Output:

SCET/CO/2023-24/EVEN/B.Tech/SEM2/Div-F Page No.100


Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Enrollment No:ET23BTCO111 Name:Patel Kakshkumar Mukeshbhai

Practical No:49

AIM:Write a program to swap two values using pointers.

C Program:
#include <stdio.h>
void swap(int *p1, int *p2) {
int temp = *p1;
*p1 = *p2;
*p2 = temp;
}
int main()
{
int x, y;
printf("Enter Value of x ");
scanf("%d", &x);
printf("\nEnter Value of y ");
scanf("%d", &y);
swap(&x, &y);
printf("\nAfter Swapping: x = %d, y = %d", x, y);
return 0;
}

Output:

SCET/CO/2023-24/EVEN/B.Tech/SEM2/Div-F Page No.101


Subject Code: BTCO12107 Subject Name: Programming for Problem Solving
Enrollment No:ET23BTCO111 Name:Patel Kakshkumar Mukeshbhai

Practical No:50

AIM:Write a program for sorting using pointer.

C Program:
#include <stdio.h>
void sort(int n, int* ptr)
{int i, j, t;
for (i = 0; i < n; i++) {
for (j = i + 1; j < n; j++) {
if (*(ptr + j) < *(ptr + i)){
t = *(ptr + i);
*(ptr + i) = *(ptr + j);
*(ptr + j) = t;}}}
for (i = 0; i < n; i++){
printf("%d ", *(ptr + i));}}
int main(){
int n = 5;
int arr[] = { 0, 23, 14, 12, 9 };
sort(n, arr);
return 0;}

Output:

SCET/CO/2023-24/EVEN/B.Tech/SEM2/Div-F Page No.102

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy