Write a C program to Store Information in Structure and Display it


Introduction

I have used Code::blocks 12 compiler for debugging purpose. But you can use any C programming language compiler as per your availability.


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

Write a C program to Store Information in Structure and Display it


  1. #include <stdio.h>
  2. struct student
  3. {
  4. char name[50];
  5. int roll;
  6. float marks;
  7. }
  8. stud[2];
  9.  
  10. int main()
  11. {
  12. int i;
  13.  
  14. printf("Enter information of students:\n");
  15.  
  16. // storing information
  17. for(i=0; i<2; ++i)
  18. {
  19. stud[i].roll = i+1;
  20.  
  21. printf("\nFor roll number: %d\n",stud[i].roll);
  22.  
  23. printf("Enter name: ");
  24. scanf("%s",stud[i].name);
  25.  
  26. printf("Enter marks: ");
  27. scanf("%f",&stud[i].marks);
  28.  
  29.  
  30. printf("\n");
  31. }
  32.  
  33. printf("Displaying Information:\n\n");
  34. // displaying information
  35. for(i=0; i<2; ++i)
  36. {
  37. printf("\nRoll number: %d\n",i+1);
  38. printf("Name: ");
  39. puts(stud[i].name);
  40. printf("Marks: %.1f",stud[i].marks);
  41.  
  42. printf("\n");
  43. }
  44. return 0;
  45. }
  46.  

Result

C language techstudy.org

     





Related Topics




Popular Posts