#include <stdio.h> // Declare the variables struct student { char name [50]; int rollno;…
- User
#include <stdio.h>
// Declare the variables struct student { char name [50]; int rollno; float m1; float phy; float graph; float beee; float bcme; }
int main () { struct student s; printf("Enter student name :\n"); fgets(s.name,sizeof(s.name),stdin); printf("Enter roll number :\n"); scanf("%d",&s.rollno); printf("Enter Marks in m1 :\n"); scanf("%d",&s.m1); printf("Enter marks in phy :\n"); scanf("%d",&s.phy); printf("Enter marks in graphhics :\n"); scanf("%d",&s.graph); printf("Enter marks in bcme :\n"); scanf("%d",&s.bcme); printf("Enter marks in beee :\n"); scanf("%d",&s.beee); //display the results printf("\n ---- Student Details---\n"); printf("Name : %s",s.name); printf("Roll No : %d\n",s.rollno); printf("M1 : %2.f\n",s.m1); printf("Physics : %2.f\n",s.phy); printf("Graphics: %2.f\n",s.graph); printf("bcme : %2.f\n",s.bcme); printf("beee : %2.f\n",s.beee); return 0;}
Assistant
I can see several issues in your C program that need to be fixed:
- Missing semicolon after the struct definition
- Wrong format specifiers in scanf - you're using
%dfor float variables - Incorrect printf format - should be
%.2finstead of%2.f
Here's the corrected version:
#include <stdio.h> // Declare the variables struct student { char name[50]; int rollno; float m1; float phy; float graph; float beee; float bcme; }; // Added missing semicolon int main() { struct student s; printf("Enter student name :\n"); fgets(s.name, sizeof(s.name), stdin); printf("Enter roll number :\n"); scanf("%d", &s.rollno); printf("Enter Marks in m1 :\n"); scanf("%f", &s.m1); // Changed from %d to %f printf("Enter marks in phy :\n"); scanf("%f", &s.phy); // Changed from %d to %f printf("Enter marks in graphics :\n"); scanf("%f", &s.graph); // Changed from %d to %f printf("Enter marks in bcme :\n"); scanf("%f", &s.bcme); // Changed from %d to %f printf("Enter marks in beee :\n"); scanf("%f", &s.beee); // Changed from %d to %f // Display the results printf("\n ---- Student Details---\n"); printf("Name : %s", s.name); printf("Roll No : %d\n", s.rollno); printf("M1 : %.2f\n", s.m1); // Changed from %2.f to %.2f printf("Physics : %.2f\n", s.phy); // Changed from %2.f to %.2f printf("Graphics: %.2f\n", s.graph); // Changed from %2.f to %.2f printf("bcme : %.2f\n", s.bcme); // Changed from %2.f to %.2f printf("beee : %.2f\n", s.beee); // Changed from %2.f to %.2f return 0; }Key fixes:
- Added semicolon after struct definition
- Changed
scanf("%d", ...)toscanf("%f", ...)for float variables - Changed
printf("%2.f", ...)toprintf("%.2f", ...)to properly display 2 decimal places
The program should now compile and run correctly!
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.