You are on page 1of 6

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: 2029190 Branch/Section: CSCE-2
Name in Capital: ALAPAN PRADHAN

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\tRoll\tName\tGender\tMobile\tnumber\tphy\tchem\tmath\n");
for(i=0; i<n; i++){

printf("%d\t%d\t%s\t%c\t%ld\t%d\t%d\t%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 int phone;
int pm;
int mm;
int cm;

}Student;

void printInfo(Student s[], int n)


{
printf("Sl_num\tRoll\tName\tGender\tMobile number\tphym\tchemm\tmathm\n");
int i;
for(i=0; i<n; i++){

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


.mm);
}
}

float calcPercentage(Student s)
{
float i;
i= ((s.pm+s.mm+s.cm)/3);
//printf("fffff%f",i);
return i;
}

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);
}
else
{
printf("no number ending with 66");
}
}
}

int main()
{
int n;
float k;
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:\n");

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


{ k=0;
k=calcPercentage(s[i]);
printf("%f\n",k);
}

printf("\n Student With Highest Mark in Math:\n ");

Student st = findHighestMarks(s,n);
printf("%s\n", st.name);
printf("%d\n", st.mm);

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


// displayMarkInMath(s, n);

printf("\nStudent with phone number ending with 66:\n");


displayWithNumber66(s,n);
printf("\n Printing In Decending Order: \n");
printInDecending(s,n);

return 0;
}

You might also like