Posts

Showing posts from November, 2021

Area of rectangles using structures

Image

Write a program to store the roll no. (starting from 1), name and age of 5 students and then print the details of the student with roll no. 2.

 #include<iostream> using namespace std; struct student { long long roll; char name[10]; int age; int marks; }; int main() { struct student p[5]; for (int i=0;i<5;i++) { cout << "Student Roll No: " << i + 1 << endl; p[i].roll = i + 1; cout<<"Enter the Name of the student:"<<endl; cin >> p[i].name; cout<<"Enter the Age of the student:" << endl;  cin >> p[i].age; } for (int i = 0; i < 5; i++) { if (p[i].roll == 2) { cout << "Roll No : " << p[i].roll<<endl; cout << "Name : " << p[i].name << endl; cout << "Age: " << p[i].age << endl; } } return 0; }

Isalpa() function of header file

 #include<iostream> #include<ctype.h> using namespace std; int main() { int ch; cout << "enter a character\n"; ch=getchar(); if (isalpha(ch)) { cout << "alphanumeric character"; } else cout << "not an alphanumeric character"; return 0; }

Pogram to illustrate the use of isalnum(ch) function.

  #include<iostream> #include<ctype.h> using namespace std; int main() { int ch; cout << "enter a character\n"; ch=getchar(); if (isalnum(ch)) { cout << "alphanumeric character"; } else cout << "not an alphanumeric character"; return 0; }