PK SOLVED

  • Home
  • Request solution
  • About

13 Jan 2017

C program to implement structure

 C     No comments   


Structure is a user-defined data type in C which allows you to combine different data types to store a particular type of record. Structure helps to construct a complex data type in more meaningful way. It is somewhat similar to an Array. The only difference is that array is used to store collection of similar datatypes while structure can store collection of any type of data.
Struct keyword is used create structure in C programming.

Structure is used to represent a record. Suppose you want to store record of Student which consists of student name, address, roll number and age. You can define a structure to hold this information.

Refer following example to understand working and use of structure.

#Example:

  #include <stdio.h>
  struct student
  {
     char name[50];
     char add[50];
     int roll;
     int age;
  } s;

  void main()
  {
     printf("Enter information:\n\n");

     printf("Enter name: ");
     scanf("%s", s.name);

     printf("Enter address: ");
     scanf("%s", s.add);

     printf("Enter roll number: ");
     scanf("%d", &s.roll);

     printf("Enter age: ");
     scanf("%d", &s.age);


     printf("\n\nDisplaying Information:\n\n");

     printf("Name: ");
     puts(s.name);

     printf("Address: ");
     puts(s.add);

     printf("Roll number: %d\n",s.roll);

    printf("Age: %d\n", s.age);

  }

Output

  Enter information:
  Enter name: Pankaj
  Enter address: Nanded
  Enter roll number: 22
  Enter age: 22
  Displaying Information:
  Name: Pankaj
  Address: Nanded
  Roll number: 22
  Age: 22
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 comments:

Post a Comment

Contact Form

Name

Email *

Message *

About me

Hi, this is Pankaj Takale, a programming lover. This blog created to help programmers who are getting stuffs while doing their best.

Follow me here to be in touch

Popular Posts

  • C program to find whether it is prime number or not
    C program to find whether it is prime number or not: Prime number is the number which can only divided by one (1) and itself. ...
  • C program to implement structure
    Structure is a user-defined data type in C which allows you to combine different data types to store a particular type of record. Stru...
  • C program to change case of string
    In this post, you learn how to change the case of string. If you entered "A", the program will change it's case to ...
  • C program to check leap year
    C program to check leap year: A leap year is exactly divisible by 4 except for century years (years ending with 00). The century yea...
  • C program to print Fibonacci series
    C program to print fibonacci series: The Fibonacci sequence is a series where the next term is the sum of pervious two terms. The fir...

Blog Archive

  • ▼  2017 (13)
    • ▼  January (13)
      • C program to change case of string
      • C program to implement structure
      • C program to check whether it is positive number o...
      • C program to check leap year
      • C program to find whether it is prime number or not
      • C program to print Fibonacci series
      • C program to check whether it is armstrong number ...
      • C program to swap two number without temporary var...
      • C program to swap two numbers using temporary vari...
      • C program to check whether entered character is Vo...
      • C program to print ASCII value of character
      • C program to print palindrome number
      • C program to print even & odd number

Copyright © PK SOLVED