Structures Union Programs
Structures Union Programs
int main() {
struct Student students[5]; // Array to hold details of 5 students
int i;
return 0;
}
2. Write a program in C to store [n] students’
details (id, name,roll_number) and print them.
#include <stdio.h>
struct Student {
int id;
char name[50];
int roll_number;
};
int main() {
int n;
return 0;
}
3. Write a program in C to store students’
details(id, name,roll_number) until the user wants
to continue and print them.
#include <stdio.h>
struct Stu {
int id;
char name[50];
int roll;
};
int main() {
struct Stu s[100]; // Array to hold student details
int cnt = 0; // Count of students
char ch;
do {
// Input student details in a single line
printf("Enter ID, Name, Roll Number: ");
scanf("%d %s %d", &s[cnt].id, s[cnt].name, &s[cnt].roll);
cnt++;
return 0;
}
4. Write a program in C to store [5] students’ details(id,
name, roll_number, computer marks) and print only those
data whose computer marks is above 50.
#include <stdio.h>
struct Stu {
int id;
char name[50];
int roll;
int comp_marks;
};
int main() {
struct Stu s[5]; // Array to hold 5 student details
return 0;
}
5. Write a programming C to store [n] students’ details(id,
name, roll_number, computer marks) and display student
details in descending order of computer marks.
#include <stdio.h>
#include <string.h>
struct Stu {
int id;
char name[50];
int roll;
int comp_marks;
};
return 0;
}
6. Write a program in C to store [5] students’
details(name,roll_number, computer marks) and print only those
data whose computer marks is above 50 and name starts with ‘a’ or
‘m’.
#include <stdio.h>
#include <string.h>
struct Stu {
char name[50];
int roll;
int comp_marks;
};
int main() {
struct Stu s[5]; // Array to hold 5 student details
return 0;
}
7. Write a program in C to store [n] students’ details(id,name,
roll_number, computer marks) and arrange them in ascending
order of marks and display those data whose marks is above 40 and
name starts with ‘a’ or ‘m’.
#include <stdio.h>
#include <string.h>
struct Student {
int id;
char name[50];
int roll_number;
int computer_marks;
};
// Display students with marks above 40 and name starting with 'a' or 'm'
printf("\nStudents with marks above 40 and name starting with 'a' or 'm':\n");
printf("ID\tName\t\tRoll Number\tComputer Marks\n");
printf("---------------------------------------------------\n");
return 0;
}
8.Develop a program in C using structure to ask the information of any 12 students with
roll_number,name and marks scored in sub1, sub2, and sub3. Also, display them in proper
format along with the calculation of total and percentage . [Note: the full marks of each
subject is 100].
#include <stdio.h>
int main() {
struct Student students[12]; // Array to hold details of 12 students
int i;
printf("%d\t%s\t\t%d\t%d\t%d\t%d\t%.2f%%\n",
students[i].roll, students[i].name,
students[i].marks1, students[i].marks2,
students[i].marks3, total, percentage);
}
return 0;
}