Question

Given details (like roll number, name and marks) of 5 students as an input, read all...

Given details (like roll number, name and marks) of 5 students as an input, read all the details into Student structure and display the content.

Input:

1 Jack 72.12

2 Tom 42.42

3 Robert 72.12

4 Michael 72.12

5 James 72.12    

    where:

  • All lines represent Roll number, Name and Marks respectively.

Output:

1 Jack 72.12

2 Tom 42.42

3 Robert 72.12

4 Michael 72.12

5 James 72.12

not sure why my output is off.

#include <stdio.h>
struct student
{
char name[30];
int roll;
float marks;
} s[10];
int main()
{
int i;
for(i=0; i<5; i++)
{
s[i].roll = i;
scanf("%s",s[i].name);
scanf("%f",&s[i].marks);
  
}
  
for(i=0; i<5; i++)
{
  
puts(s[i].name);
printf(" %.2f",s[i].marks);
}
return 0;
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

correct code is:

#include <stdio.h>
struct student
{
char name[30];
int roll;
float marks;
} s[10];
int main()
{
int i;
for(i=0; i<5; i++)
{
s[i].roll = i;
scanf("%s",&s[i].name); //added refrence sighn before s
scanf("%f",&s[i].marks);
  
}
  
for(i=0; i<5; i++)
{
printf("%d",i+1); //added a line to print roll no
//puts(s[i].name); //instead using puts used printf statement to print name
printf(" %s ",s[i].name);
printf(" %.2f ",s[i].marks);
printf("\n");
}return 0;}

____________________________________________________________________________________________________

input:

output:

another compiler solution:

Add a comment
Know the answer?
Add Answer to:
Given details (like roll number, name and marks) of 5 students as an input, read all...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Store information of 5 students using Structure Given details (like roll number, name and marks) of...

    Store information of 5 students using Structure Given details (like roll number, name and marks) of 5 students as an input, read all the details into Student structure and display the content. Input: 1 Jack 72.12 2 Tom 42.42 3 Robert 72.12 4 Michael 72.12 5 James 72.12         where: All lines represent Roll number, Name and Marks respectively. Output: 1 Jack 72.12 2 Tom 42.42 3 Robert 72.12 4 Michael 72.12 5 James 72.12 not sure what to do...

  • I am trying to write C programming code and output will be as below but I...

    I am trying to write C programming code and output will be as below but I donno how to get the result analysis part. help me to add the 2nd part with my code: here is my code below: #include <stdio.h> #define MAX 100 struct studentMarkVariable{ int id; float marks; }; void getData(struct studentMarkVariable arrs[]); void show(struct studentMarkVariable arrs[]); int main() { printf ("####### Marks Analyzer V3.0 ####### \n");       struct studentMarkVariable arrs[MAX];     getData(arrs);     show(arrs); return 0; }...

  • Hello, I am having trouble with a problem in my C language class. I am trying...

    Hello, I am having trouble with a problem in my C language class. I am trying to make a program with the following requirements: 1. Use #define to define MAX_SIZE1 as 20, and MAX_SIZE2 as 10 2. Use typedef to define the following struct type: struct {     char name[MAX_SIZE1];     int scores[MAX_SIZE2]; } 3. The program accepts from the command line an integer n (<= 30) as the number of students in the class. You may assume that the...

  • ****Using C and only C**** I have some C code that has the function addRecord, to...

    ****Using C and only C**** I have some C code that has the function addRecord, to add a record to a linked list of records. However, when I run it, the program exits after asking the user to input the address. See picture below: Here is my code: #include<stdio.h> #include<stdlib.h> struct record { int accountno; char name[25]; char address[80]; struct record* next; }; void addRecord(struct record* newRecord) //Function For Adding Record at last in a SinglyLinkedList { struct record *current,*start,*temp;...

  • // READ BEFORE YOU START: // You are given a partially completed program that creates a...

    // READ BEFORE YOU START: // You are given a partially completed program that creates a list of students for a school. // Each student has the corresponding information: name, gender, class, standard, and roll_number. // To begin, you should trace through the given code and understand how it works. // Please read the instructions above each required function and follow the directions carefully. // If you modify any of the given code, the return types, or the parameters, you...

  • Hardware Inventory – Write a database to keep track of tools, their cost and number. Your...

    Hardware Inventory – Write a database to keep track of tools, their cost and number. Your program should initialize hardware.dat to 100 empty records, let the user input a record number, tool name, cost and number of that tool. Your program should let you delete and edit records in the database. The next run of the program must start with the data from the last session. This is my program so far, when I run the program I keep getting...

  • Here is a serial program in C and parallel program in OpenMP that takes in a string as input and counts the number of occurrences of a character you choose. Why is the runtime for the output for the O...

    Here is a serial program in C and parallel program in OpenMP that takes in a string as input and counts the number of occurrences of a character you choose. Why is the runtime for the output for the OpenMP parallel program much longer? Serial Program #include <stdio.h> #include <string.h> #include <time.h> int main(){    char str[1000], ch;    int i, frequency = 0;    clock_t t; struct timespec ts, ts2;       printf("Enter a string: ");    gets(str);    int len = strlen(str);    printf("Enter a character...

  • Within this C program change the input to a file instead of individual input from the...

    Within this C program change the input to a file instead of individual input from the user. You must take the input file name on the command line. Be sure to have simple error checking to be sure the file exists and was successfully opened. The input file will have the following format: First line: Number of students Second Line: Number of grades Third Line: Student Names, space delimited Fourth+ Line(s): Grades for all students for one assignment, space delimited....

  • Identify and list all the User defined Functions to be used in the system #include <stdio.h>...

    Identify and list all the User defined Functions to be used in the system #include <stdio.h> ///for input output functions like printf, scanf #include <stdlib.h> #include <conio.h> #include <windows.h> ///for windows related functions (not important) #include <string.h> ///string operations /** List of Global Variable */ COORD coord = {0,0}; /// top-left corner of window /** function : gotoxy @param input: x and y coordinates @param output: moves the cursor in specified position of console */ void gotoxy(int x,int y) {...

  • ASSIGNMENT DUE DATE GOT PUSHED BACK TO LATE THIS WEEK. PLEASE READ COMMENTS AND CODE BEFORE...

    ASSIGNMENT DUE DATE GOT PUSHED BACK TO LATE THIS WEEK. PLEASE READ COMMENTS AND CODE BEFORE ANSWERING CODING SECTIONS HW07 #Q1-Q5 HW08 #Q1-Q2 // READ BEFORE YOU START: // Please read the given Word document for the project description with an illustrartive diagram. // You are given a partially completed program that creates a list of students for a school. // Each student has the corresponding information: name, standard, and a linked list of absents. // Please read the instructions...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT