Write a C program to calculate percentage of student using structure


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 calculate percentage of student using structure


  1. #include <stdio.h>
  2.  
  3. struct student
  4. {
  5. char name [30];
  6. int marks[ 5];
  7. int total;
  8. float percentage;
  9. };
  10.  
  11. int main()
  12. {
  13. struct student std;
  14. int i;
  15.  
  16. printf("Enter name: ");
  17. gets(std.name);
  18.  
  19. printf("Enter marks:\n");
  20. std.total=0;
  21. for(i=0;i< 5;i++){
  22. printf("Marks in subject %d: ",i+1);
  23. scanf("%d",&std.marks[i]);
  24. std.total+=std.marks[i];
  25. }
  26. std.percentage=(float)((float)std.total/(float)500)*100;
  27.  
  28. printf("\nName: %s \nTotal Marks: %d \nPercentage: %.2f",std.name,std.total,std.percentage);
  29.  
  30. return 0;
  31. }
  32.  

Result

C language techstudy.org

     





Related Topics




Popular Posts