//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;
}