C - Program For Exam
C - Program For Exam
write a program to create marksheet for students using self referential structure
#include <stdio.h>
struct student {
char firstName[50];
int roll;
float marks;
} s[5];
int main() {
int i;
// storing information
s[i].roll = i + 1;
scanf("%s", s[i].firstName);
scanf("%f", &s[i].marks);
printf("Displaying Information:\n\n");
// displaying information
printf("\n");
return 0;
Roll number: 1
Name: Tom
Marks: 98
.
.
.
We can Program the main() in such a way that it can essentially accept two arguments where
the first argument denotes the number of command line arguments and the second denotes the
complete list of every command line argument. It is how you can code your command line
argument within the parenthesis of main():
In the above statement, the command line arguments have been handled via
the main() function, and you have set the arguments where
Example:
#include <stdio.h>
if( argc == 2 )
{
else
Output:
3.write a c program to get the name and mark the n number of students from user and
store them in a file.
#include <stdio.h>
#include <stdlib.h>
int main()
{
char name[50];
int marks, i, n;
printf("Enter number of students: ");
scanf("%d", &n);
FILE *fptr;
fptr = (fopen("student.txt", "w"));
if (fptr == NULL)
{
printf("Error!");
exit(1);
}
for (i = 0; i < n; ++i)
{
printf("For student%d\nEnter name: ", i + 1);
scanf("%s", name);
printf("Enter marks: ");
scanf("%d", &marks);
fprintf(fptr, "\nName: %s \nMarks=%d \n", name, marks);
Output: