You are on page 1of 9

CN Lab.

(IT-3095), Autumn 2022

Networks Laboratory (CN


Lab.)
[IT-3095]
Individual Work
Lab. No:1 Topic:STRUCTURES Date:19/07/2022
Roll Number: 2029090 Branch/Section: CSCE-2
Name in Capital: ARYAN PRASAD

Program No: 1.1

Program Title:
Write a program to store student details such as roll no, name, gender, phone number, marks in physics,
chemistry, and mathematics
Input/Output
Screenshots:
RUN-1:

RUN-2
Source code

#include <stdio.h>

struct student{
int s;
char name[50];
int roll;
char gender[1];
long phone;
int phy;
int math;
int chem;

};

int main()
{
int n;
printf("Enter the number of students- ");
scanf("%d",&n);
struct student s[n];
int i;
for(i=0; i<n; i++){
printf("Enter the serial number - ");
scanf("%d",&s[i].s);
printf("Enter students roll number - ");
scanf("%d",&s[i].roll);
printf("Enter students name - ");
scanf("%s",s[i].name);
printf("Enter the gender - ");
scanf("%s",s[i].gender);
printf("enter the students phone number - ");
scanf("%ld",&s[i].phone);
printf("enter phy marks - ");
scanf("%d",&s[i].phy);
printf("enter chem marks - ");
scanf("%d",&s[i].chem);
printf("enter math marks - ");
scanf("%d",&s[i].math);
}

printf("SLnum Roll Name Gender Mobile number phy chem math\n");


for(i=0; i<n; i++){
printf("%d %d %s %c %ld %d %d %d\
n",s[i].s ,s[i].roll ,s[i].name ,s[i].gender[0] ,s[i].phone ,s[i].phy,s[i].chem,s[i].math);
}

return 0;
}

Conclusion/Observation
We observe the structure formation and methods used to store data in the structures.
Program no. : 1.2

Program Title:
Write a program to make changes in 1.1 so as to obtain:
1. Percentage of marks of each student.
2. Highest marks in maths.
3. Display the number of male and female students.
4. Display the students in descending order of their percentage.
5. Display student names having mobile no. Ending with 66.
Input/Output Screenshots:
RUN-1:

RUN 2 :
SOURCE CODE :

#include <stdio.h>

typedef struct{

char name[50];

int roll;

char gender;

long phone;

int pm;

int mm;

int cm;
}Student;

void printInfo(Student s[], int n) {

printf("Sl num Roll Name Gender Mobile number phym chemm mathm\n");

int i;

for(i=0; i<n; i++){

printf("%d %s %c %ld %d %d %d\n",s[i].roll ,s[i].name ,s[i].gender ,s[i].phone ,s[i].pm,s[i].cm,s[i].mm);

float calcPercentage(Student st) {

return ((st.pm+st.mm+st.cm)/30.0)*100;

Student findHighestMarks(Student sts[], int n) {

int maxMarks=sts[0].mm;

int idx=0;

int i;

for(i=1; i<n; i++) {

if(sts[i].mm > maxMarks) {

maxMarks=sts[i].mm;

idx=i;

return sts[idx];

void displayMarkInMath(Student sts[], int n) {

int countM=0;

int countF=0;

printf("Marks in math of male\n");

int i;
for(i=0; i<n; i++) {

if(sts[i].gender=='M') {

printf("%d\n", sts[i].mm);

countM++;

printf("Marks in math of female\n");

for(i=0; i<n; i++) {

if(sts[i].gender!='M') {

printf("%d\n", sts[i].mm);

countF++;

printf("no. of males: %d\n",countM);

printf("no. of females: %d",countF);

void printInDecending(Student s[], int n) {

Student temp[n];

int i,j;

for(i=0; i<n; i++) {

temp[i]=s[i];

for(i=0; i<n-1; i++) {

for(j=i+1; j<n; j++) {

float curr=calcPercentage(temp[i]);

if(curr < calcPercentage(temp[j])) {

Student t = temp[i];

temp[i] = temp[j];
temp[j] = t;

for(i=0; i<n; i++) {

printf("%s %f\n ", temp[i].name, calcPercentage(temp[i]));

void displayWithNumber66(Student s[], int n) {

int
i;

for(i=0; i<n; i++){

if(s[i].phone%100 == 66) {

printf("%s\n",s[i].name);

int main()

int n;

printf("Enter the number of students- ");

scanf("%d",&n);

Student s[n];

int i;

for(i=0; i<n; i++){

printf("Enter students roll number - ");

scanf("%d",&s[i].roll);

printf("Enter students name - ");


scanf("%s",&s[i].name);

printf("Enter the gender(M or F) - ");

scanf("%s",&s[i].gender);

printf("enter the students phone number - ");

scanf("%ld",&s[i].phone);

printf("enter the phy chem and math marks - ");

scanf("%d %d %d",&s[i].pm,&s[i].cm,&s[i].mm);

printInfo(s, n);

printf("\nPERCENTAGE OF STUDENTS: ");

printf("\n");

for(i=0; i<n; i++) {

printf("%f\n", calcPercentage(s[i]));

printf("\n STUDENT WITH HIGHEST MARKS:\n ");

Student st = findHighestMarks(s, n);

printf("%s\n", st.name);

printf("%d\n", st.pm+st.mm+st.cm);

printf("\n MARKS IN MATHS: ");

displayMarkInMath(s, n);

printf("\nSTUDENT WITH PHONE NUMBER ENDING WITH 66: ");

displayWithNumber66(s, n);
printf("\nPRINTING IN DESCENDING ORDER: \n");

printInDecending(s, n);

return 0;

You might also like