Write any 2 C programs of a structure having return type int, char, float. Explain each step for both the programs.
The code should be simple as I am a beginner. Also, I need an urgent answer.
Here is the First program: Student information program:
Program screenshot:
Output:
Code to copy:
// header file
#include <stdio.h>
// structure for student
struct Stud{
char *student_name;
int stu_id;
float marks;
};
int main()
{
// create a vairable for structure
// here student is variable of structure Stud
struct Stud student;
// give them values
student.student_name = "John";
student.stu_id = 11122;
student.marks = 20;
// dislay output
printf("Student Name is: %s", student.student_name);
printf("\nStudent Id is: %d", student.stu_id);
printf("\nStudent Marks is: %f", student.marks);
return 0;
}
--------------------------------------------------------------------------------------------------------------------
Program 2:
Employee information:
Program screenshot:
Code to copy:
#include <stdio.h>
// create required structure
struct Empl{
// name of employee, return type is char
char *emp_name;
int emp_id;
float emp_salary;
};
int main()
{
// give a variable to the structure
struct Empl employee;
// give values to the variables
employee.emp_name = "Jphn";
employee.emp_id = 1220;
employee.emp_salary = 70000;
// display output
printf("Employee Name is: %s", employee.emp_name);
printf("\nEmployee Id is: %d", employee.emp_id);
printf("\nEmployee salary is: %f", employee.emp_salary);
return 0;
}
---------------------------------------------------------
PLEASE UPVOTE.
Get Answers For Free
Most questions answered within 1 hours.