Tuesday, April 4, 2017

Structure using Array(students Information)

#include<stdio.h>

struct anything ///44 B
{
    int age;    ///4 B
    char name[20]; ///20 B           ///member definition
    char dept[10];///20 B

};

typedef struct anything newType ;



main()
{
    printf("Enter student number ");
    int num;
    scanf("%d",&num);
    newType student[num];
    int i;
    for(i=0 ; i<num ; i++)
    {
        printf("         Info of student %d : \n",i+1);

        printf("Name = ");
        getchar();
        gets(student[i].name);
        printf("Age = ");
        scanf("%d",&student[i].age);
        printf("Dept = ");
        getchar();
        gets(student[i].dept);
    }



    for(i=0 ; i<num ; i++)
    {
        printf("         Info of student %d : \n",i+1);

        printf("Name = ");
        puts(student[i].name);
        printf("Age  = %d\n",student[i].age);
        printf("Dept = ");
        puts(student[i].dept);
    }



}

Structure using function (students management system)

#include<stdio.h>

struct anything ///44 B
{
    int age;    ///4 B
    char name[20]; ///20 B           ///member definition
    char dept[10];///20 B

};

typedef struct anything newType ;


void display(int num,int i,newType student[])
{
        printf("         Info of student %d : \n",i+1);

        printf("Name = ");
        puts(student[i].name);
        printf("Age  = %d\n",student[i].age);
        printf("Dept = ");
        puts(student[i].dept);
}
main()
{
    printf("Enter student number ");
    int num;
    scanf("%d",&num);
    newType student[num];
    int i;
    for(i=0 ; i<num ; i++)
    {
        printf("         Info of student %d : \n",i+1);

        printf("Name = ");
        getchar();
        gets(student[i].name);
        printf("Age = ");
        scanf("%d",&student[i].age);
        printf("Dept = ");
        getchar();
        gets(student[i].dept);
    }



    for(i=0 ; i<num ; i++)
    {
       display(num,i,student);
    }



}

Structure with example of typedef

#include<stdio.h>

 struct anything ///44 B
{
    int age;    ///4 B
    char name[20]; ///20 B           ///member definition
    char dept[10];///20 B

};

 typedef struct anything newType ;

  newType student1,student2 ;

main()
{
    printf("         Info of student 1 : \n");

    printf("Name = ");
    gets(student1.name);
    printf("Age = ");
    scanf("%d",&student1.age);
    printf("Dept = ");
    getchar();
    gets(student1.dept);




    printf("Name = ");
    puts(student1.name);
    printf("Age  = %d\n",student1.age);
    printf("Dept = ");
    puts(student1.dept);





    printf("         Info of student 2 : \n");

    printf("Name = ");
    gets(student2.name);
    printf("Age = ");
    scanf("%d",&student2.age);
    printf("Dept = ");
    getchar();
    gets(student2.dept);




    printf("Name = ");
    puts(student2.name);
    printf("Age  = %d\n",student2.age);
    printf("Dept = ");
    puts(student2.dept);

}

Structure basic input output system (Structural data type example)

#include<stdio.h>

struct anything ///44 B
{
    int age;    ///4 B
    char name[20]; ///20 B           ///member definition
    char dept[10];///20 B

};
struct anything student1,student2 ;

Structure declaration and input output

#include<stdio.h>

struct anything ///44 B
{
    int age;    ///4 B
    char name[10]; ///20 B           ///member definition
    char dept[10];///20 B

};
struct anything student1 ;