Programming for Problem Solving

GTU Practical 49

49. Write a program to read structure elements from the keyboard.
#include<stdio.h>  ( this applies in the given code )

#include

struct Student {
char name[50];
int age;
float marks;
};

int main() {
struct Student s;

printf(“Enter Name: “);
scanf(” %[^\n]”, s.name); // Reads a full line including spaces

printf(“Enter Age: “);
scanf(“%d”, &s.age);

printf(“Enter Marks: “);
scanf(“%f”, &s.marks);

printf(“\nStudent Details:\n”);
printf(“Name: %s\n”, s.name);
printf(“Age: %d\n”, s.age);
printf(“Marks: %.2f\n”, s.marks);

return 0;
}

OUTPUT

Enter Name: king
Enter Age: 20
Enter Marks: 55

Student Details:
Name: king
Age: 20
Marks: 55.00

GTU STUDY