0% found this document useful (0 votes)
7 views16 pages

Student Marks Calculation in C

The document contains multiple C programs demonstrating the use of structures to manage student data, including calculating student-wise and subject-wise totals, comparing structure variables, subtracting numbers using pointers, and displaying an array of structures. Each program showcases different functionalities such as input handling, arithmetic operations, and data comparison. Overall, it serves as a practical guide to using structures in C programming.

Uploaded by

vv7731434
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)
7 views16 pages

Student Marks Calculation in C

The document contains multiple C programs demonstrating the use of structures to manage student data, including calculating student-wise and subject-wise totals, comparing structure variables, subtracting numbers using pointers, and displaying an array of structures. Each program showcases different functionalities such as input handling, arithmetic operations, and data comparison. Overall, it serves as a practical guide to using structures in C programming.

Uploaded by

vv7731434
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

//Calculate Subject-wise & Student-wise Totals Using Structure

#include <stdio.h>
struct Student
{
int roll;
int marks[3]; // marks in 3 subjects
int total; // student-wise total
};
void main()
{
struct Student s[3];
int subTotal[3] = {0, 0, 0}; // subject-wise totals

// Input marks of all students


for (int i=0; i<3; i++)
{
s[i].total = 0; // initialize student total
printf("\nEnter roll number of student %d: ", i+1);
scanf("%d",&s[i].roll);
printf("Enter marks in 3 subjects: ");
for (int j=0; j<3; j++)
{
scanf("%d", &s[i].marks[j]);
s[i].total += s[i].marks[j]; // student-wise total
subTotal[j] += s[i].marks[j]; // subject-wise total
}
}
// Display student-wise totals
printf("\n--- Student-wise Total Marks ---\n");
for (int i=0; i<3; i++)
{
printf("Roll %d -> Total Marks = %d\n", s[i].roll, s[i].total);
}
// Display subject-wise totals
printf("\n--- Subject-wise Total Marks ---\n");
for (int j = 0; j < 3; j++)
{
printf("Subject %d Total = %d\n", j + 1, subTotal[j]);
}
}

*******************************************************************************************
*********
//the comparision of structure variables
#include <stdio.h>
#include <string.h>
struct Student
{
int roll;
char name[20];
float marks;
};
int main()
{
struct Student s1 = {101, "Rahul", 85.5};
struct Student s2 = {101, "Rahul", 85.5};

// Compare structure variables manually


if ([Link] == [Link] && strcmp([Link], [Link]) == 0 && [Link] == [Link])
{
printf("Both structure variables are EQUAL.\n");
}
else
{
printf("Structure variables are NOT EQUAL.\n");
}
return 0;
}

*******************************************************************************************
*********
//substract two numbers using pointers
#include <stdio.h>
void main()
{
int first, second, *p, *q, diff;

printf("Enter two integers to add\n");


scanf("%d%d", &first, &second);

p = &first;
q = &second;

diff = *p - *q;

printf("Sum of entered numbers = %d\n",diff);


}
*******************************************************************************************
*********
//Array of Structures
#include <stdio.h>
struct Student
{
int roll;
float marks;
};

int main()
{
// Array of 3 structure variables
struct Student s[3] = {{1, 85.5},{2, 90.0},{3, 78.2}
};
// Displaying values
for (int i = 0; i < 3; i++)
{
printf("Student %d -> Roll: %d, Marks: %.1f\n",i + 1, s[i].roll, s[i].marks);
}
return 0;
}

You might also like