Define and declare a structure variable, read and print its members |
#include <stdio.h> // New structure by name student is defined struct student { char name[50]; int roll; float marks; }; int main() { struct student s; // Declaring a variable s of type 'student' // Reading values into each element and printing them printf("Enter information of students: \n\n"); printf("Enter name: "); scanf("%s", s.name); printf("Enter roll number: "); scanf("%d", &s.roll); printf("Enter marks: "); scanf("%f', &s.marks); printf("\n Displaying Information\n"); printf("Name: %s\n", s.name); printf("Roll: %d\n", s.roll); printf("Marks: %.2f\n", s.marks); return 0; |
Output: Enter information of students: Enter name: sairam Enter marks: 456 Displaying Information Name: sairam Roll number: 1 Marks: 456.00 |
Define and declare a structure variable, read and print its members
0
Post a Comment
0 Comments