Skip to content

Instantly share code, notes, and snippets.

@winhtut
Last active December 26, 2019 18:04
Show Gist options
  • Save winhtut/0f16abf9689acda1e9832621bd142b9f to your computer and use it in GitHub Desktop.
Save winhtut/0f16abf9689acda1e9832621bd142b9f to your computer and use it in GitHub Desktop.
Structure
#include<stdio.h>
struct student{
int age;
int roll;
float marks;
};
struct student stu={18,20,100};
int main(){
printf(" printing data from Structure %d\n",stu.age);
printf(" printing data from Structure %d\n",stu.roll);
printf(" printing data from Structure %f\n",stu.marks);
return 0;
}
#include<stdio.h>
#include<conio.h>
struct collect {
char *student_name;
int student_id;
int student_age;
}student_data;
int main() {
char string[20];
char *name=string;
printf("Please enter your name...");
scanf("%s",name);
printf("Please enter your id...");
scanf("%d",&student_data.student_id);
printf("Please enter your age...");
scanf("%d",&student_data.student_age);
student_data.student_name=name;
printf("Student name is %s\n",student_data.student_name);
printf("Student id is %d\n",student_data.student_id);
printf("Student age is %d",student_data.student_age);
return 0;
}
#include <stdio.h>
struct student
{
char name[50];
int roll;
float marks;
} s[10];
int main()
{
int i;
printf("Enter information of students:\n");
// storing information
for(i=0; i<5; ++i)
{
s[i].roll = i+1;
printf("\nFor roll number%d,\n",s[i].roll);
printf("Enter name: ");
scanf("%s",s[i].name);
printf("Enter marks: ");
scanf("%f",&s[i].marks);
printf("\n");
}
printf("Displaying Information:\n\n");
// displaying information
for(i=0; i<5; ++i)
{
printf("\nRoll number: %d\n",i+1);
printf("Name: ");
puts(s[i].name);
printf("Marks: %.1f",s[i].marks);
printf("\n");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment