Program for declaration and initialization of structure in C C++

 

Coding in C

#include<stdio.h>

struct student
{
char grade;
int marks;
float percent;
};

int main()
{
struct student s;
printf(“Enter Grade : “);
scanf(“%c”,&s.grade);
printf(“Enter Marks : “);
scanf(“%d”,&s.marks);
printf(“Enter Percent : “);
scanf(“%f”,&s.percent);
printf(“The Grade is : %c”,s.grade);
printf(“\nThe Marks is : %d”,s.marks);
printf(“\nThe Percent is: %f”,s.percent);
return 0;
}

 

Coding in C++

#include<iostream>
using namespace std;

struct student
{
char grade;
int marks;
float percent;
};

int main()
{
student s;
cout<<“Enter Grade : “;
cin>>s.grade;
cout<<“Enter Marks : “;
cin>>s.marks;
cout<<“Enter Percent : “;
cin>>s.percent;
cout<<“The Grade is : “<<s.grade<<endl;
cout<<“The Marks is : “<<s.marks<<endl;
cout<<“The Percent is : “<<s.percent<<endl;
return 0;
}

 

Output

Program for declaration and initialization of structure in C C++

 

Published by

admin

I am a computer teacher, programmer and web developer