PROGRAMMING FOR PROBLEM SOLVING(C LANGUAGE)
BPTS101-18
Software Used : Programiz online compiler
PROGRAM 39: DEFINE A STRUCTURE DATA TYPE CALLED TIME_STRUCT WITH
MEMBERS HOURS,MINUTES,SECONDS.WAP TO ASSIGN VALUE AND DISPLAY TIME
IN FORMAT HH:MM:SS
#include <stdio.h>
struct time_struct{
int hours;
int minutes;
int seconds;};
int main()
{
struct time_struct t;
printf("Enter hours:");
scanf("%d",&t.hours);
printf("Enter minutes:");
scanf("%d",&t.minutes);
printf("Enter seconds:");
scanf("%d",&t.seconds);
printf("Time is= %d:%d:%d",t.hours,t.minutes,t.seconds);
return 0;
}
OUTPUT
Enter hours:7
Enter minutes:2
Enter seconds:160
Time is= 7:2:160
=== Code Execution Successful ===
Name: Mehak Sharma Class: Cse 1-B
Roll no. : 237 Semester : 2nd
PROGRAMMING FOR PROBLEM SOLVING(C LANGUAGE)
BPTS101-18
Software Used : Programiz online compiler
PROGRAM 40: DESIGN A STRUCTURE STUDENT_RECORD WITH FIELD NAMES
NAME,DOB,TOTAL MARKS.DEVELOP A PROGRAM TO READ 5 STUDENTS AND LIST
THEM RANK WISE
#include <stdio.h>
#include<string.h>
struct student_record
{
char name[15];
char DOB[20];
int total_marks;
};
int main() {
struct student_record s[10],temp;
for(int i=0;i<5;i++)
{
printf("enter details of student %d\n",i+1);
printf("Enter student name:");
scanf(" %[^\n]",s[i].name);
printf("Enter student date of birth:");
scanf("%s",s[i].DOB);
printf("Enter student total marks:");
scanf("%d",&s[i].total_marks);
}
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4 - i; j++)
{
Name: Mehak Sharma Class: Cse 1-B
Roll no. : 237 Semester : 2nd
PROGRAMMING FOR PROBLEM SOLVING(C LANGUAGE)
BPTS101-18
Software Used : Programiz online compiler
if (s[j].total_marks < s[j + 1].total_marks) {
temp = s[j];
s[j] = s[j + 1];
s[j + 1] = temp;}
}
}
printf("\nRanked Student List:\n"); // Display rank-wise sorted list
for (int i = 0; i < 5; i++)
printf("%d %s %s %d\n", i + 1, s[i].name, s[i].DOB, s[i].total_marks)
return 0;
}
OUTPUT
enter details of student 1
Enter student name:riya
Enter student date of birth:2/2/2006
Enter student total marks:76
enter details of student 2
Enter student name:tiya
Enter student date of birth:1/3/2005
Enter student total marks:10
enter details of student 3
Enter student name:siya
Enter student date of birth:5/6/2007
Enter student total marks:37
enter details of student 4
Enter student name:himansh
Name: Mehak Sharma Class: Cse 1-B
Roll no. : 237 Semester : 2nd
PROGRAMMING FOR PROBLEM SOLVING(C LANGUAGE)
BPTS101-18
Software Used : Programiz online compiler
Enter student date of birth:9/3/2005
Enter student total marks:54
enter details of student 5
Enter student name:arun
Enter student date of birth:9/8/2010
Enter student total marks:87
Ranked Student List:
Ranked Student List:
1 arun 9/8/2010 87
2 riya 2/2/2006 76
3 himansh 9/3/2005 54
4 siya 5/6/2007 37
5 tiya 1/3/2005 10
=== Code Execution Successful ===
Name: Mehak Sharma Class: Cse 1-B
Roll no. : 237 Semester : 2nd