Simple structure program in c programming | My CS Tutorial - My CS Tutorial

Breaking

Programming languages full tutorial and programs, exam papers, visual basic( Vb.net ), information of new technologies and more....

Wednesday, February 26, 2020

Simple structure program in c programming | My CS Tutorial

Structure example in c pprogramming. Struct in C. This is a simple example of structure in C language.

In this tutorial we will learn how to write a c program code to defined the structure.
Here we will create a C language program to defined structure(struct). In which we will use struct keyword.

Object of this program:

Write a simple C structure program to print information of two books as BOOK ID, BOOK NAME AND BOOK PRICE.




C PROGRAM CODE




#include<stdio.h>
#include<string.h>
 struct Book{
  int id,price;
  char name[100];
 }
 b1,b2;
main()
{

  printf("\n ENTER FIRST BOOK ID:\n ");
  scanf("%d",&b1.id);

  printf("\n ENTER FIRST BOOK NAME:\n ");
  scanf("%s",&b1.name);

    printf("\n ENTER FIRST BOOK PRICE:\n ");
  scanf("%d",&b1.price);

  printf("\n ENTER SECOND BOOK ID:\n ");
  scanf("%d",&b2.id);

  printf("\n ENTER SECOND BOOK NAME:\n ");
  scanf("%s",&b2.name);

    printf("\n ENTER SECOND BOOK PRICE:\n ");
  scanf("%d",&b2.price);

   printf("\n FIRST BOOK ID = %d\n ",b1.id);
 
   printf("\n FIRST BOOK NAME = %s\n ",b1.name);
 
   printf("\n FIRST BOOK PRICE = %d\n ",b1.price);

   printf("\n SECOND BOOK ID = %d\n ",b2.id);
 
   printf("\n SECOND BOOK NAME = %s\n ",b2.name);
 
   printf("\n SECOND BOOK PRICE  = %d\n ",b2.price);

}


OUTPUT:


ENTER FIRST BOOK ID:
 1

 ENTER FIRST BOOK NAME:
 Biography

 ENTER FIRST BOOK PRICE:
 550

 ENTER SECOND BOOK ID:
 2

 ENTER SECOND BOOK NAME:
 Comics

 ENTER SECOND BOOK PRICE:
 325

 FIRST BOOK ID = 1

 FIRST BOOK NAME = Biography

 FIRST BOOK PRICE = 550

 SECOND BOOK ID = 2

 SECOND BOOK NAME = Comics

 SECOND BOOK PRICE  = 325


output of simple structure program



Please share this post and blog link with your friends.For more programs use this blog.
If you have any problem, please comment in comment box, subscribe this blog for notifications of new post on your email and follow this blog.If you have any method of this program or want to give any suggestion send email on hc78326@gmail.com

Created by-- HARSH CHAUHAN

No comments:

Post a Comment