0% found this document useful (0 votes)
12 views4 pages

Pps 123

The document contains programming assignments for C language focusing on structures. The first program defines a structure for time and displays it in HH:MM:SS format, while the second program creates a student record structure to read and rank students based on their total marks. Both programs include user input and output examples.

Uploaded by

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

Pps 123

The document contains programming assignments for C language focusing on structures. The first program defines a structure for time and displays it in HH:MM:SS format, while the second program creates a student record structure to read and rank students based on their total marks. Both programs include user input and output examples.

Uploaded by

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

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

You might also like