C++ Online Compiler
Example: C++ Program to Store Information of 10 Students using Structure
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// C++ Program to Store Information of 10 Students using Structure #include <bits/stdc++.h> using namespace std; struct Student { char first_name[50]; char last_name[50]; int roll_number; float marks; }; int main() { int x, i; // x - To store number of students cout << "Enter the number of students: "; cin >> x; struct Student s[x + 1]; // It will store the student's information cout << "\nEnter the students' information:\n"; for (i = 0; i < x; i++) { s[i].roll_number = i + 1; cout << "\nInformation for Roll Number:\t" << s[i].roll_number << "\n"; cout << "Enter the first name: "; cin >> s[i].first_name; cout << "Enter the last name: "; cin >> s[i].last_name; cout << "Enter the marks: "; cin >> s[i].marks; } // It will display the student's information cout << "\n\nDisplay the student's information:\n"; for (i = 0; i < x; i++) { cout << "\nThe Roll Number:\t" << (i + 1) << "\n"; cout << "The First Name: "; puts(s[i].first_name); cout << "The Last Name: "; puts(s[i].last_name); cout << "The Marks: " << s[i].marks << "\n"; cout << endl; } return 0; }
10 Student-1 Test-1 50 Student-2 Test-2 55 Student-3 Test-3 60 Student-4 Test-4 65 Student-5 Test-5 70 Student-6 Test-6 75 Student-7 Test-7 80 Student-8 Test-8 85 Student-9 Test-9 90 Student-10 Test-10 95
Output
Clear
ADVERTISEMENTS