Question

Declare an array of 40 student_t structures, and write a code segment that displays on separate...

Declare an array of 40 student_t structures, and write a code segment that displays on separate lines the names (last name, first name) of all the students in the list. IN C 
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi there,

The code :

#include<stdio.h>
typedef struct{
   char first[50];   //to store first name
   char last[50];   //to store last name
}student_t;
int main()
{
   student_t stud[40];
   for(int i=0;i<40;i++)
   {
       printf("\nEnter the first name for student %d : ",i+1);
       scanf("%s",stud[i].first);   //input first name
       printf("\nEnter the last name for student %d : ",i+1);
       scanf("%s",stud[i].last);   //input last name
       printf("\n");
   }  
   for(int i=0;i<40;i++)
   {
       printf("\n%s %s",stud[i].first,stud[i].last);   //print the complete name
   }
   printf("\n");
   return 0;
}      

The code(screenshot) :

1 #include<stdio.h> 2 typedef struct{ char first[50]; //to store first name, 4 char_last[50]; //to store last name 5}student

The output(screenshot) :(4 inputs only)

Enter the first name for student 1 : asd Enter the last name for student 1 : af Enter the first name for student 2 : gr Enter

Thank you.

Happy Coding :)

Add a comment
Know the answer?
Add Answer to:
Declare an array of 40 student_t structures, and write a code segment that displays on separate...
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
  • Using C Programming, Write a program that prompts for the user's first and last names. Declare a third array that will hold the user's last name and first name, separated by a comma and space....

    Using C Programming, Write a program that prompts for the user's first and last names. Declare a third array that will hold the user's last name and first name, separated by a comma and space. Use loops to inter through the names one character at a time, storing them into the full name array. Don't forget about the terminating character. Sample run: Enter your first name: john Enter your last name: matthews First name: John Last name: Matthews Full name:...

  • C# code Arrays and Linked Lists: Write C++/Java/C#/Python code to declare an array of linked lists...

    C# code Arrays and Linked Lists: Write C++/Java/C#/Python code to declare an array of linked lists of any primitive type you want. (Array of size 2020) (This could be based on MSDN libraries or the lab) – you do not need to instantiate any of the linked lists to contain any actual values. Paste your code for that here (this should only be one line) Based on your code or the lab from 4 or your doubly linked list from...

  • Hand-write code to declare a two dimensional array of 3 columns and 4 rows. The Array...

    Hand-write code to declare a two dimensional array of 3 columns and 4 rows. The Array will hold doubles. What is the array initialized to by default?

  • *C CODE* 1. Declare an array of doubles of size 75 called scoreBonus and initialize all...

    *C CODE* 1. Declare an array of doubles of size 75 called scoreBonus and initialize all the elements in the array to 10.5 2. Declare an array of integers called studentNumbers The array can hold 112 integers Prompt and get a number from the user for the third element in the array Prompt and get a number from the user for the last element in the array

  • in java.... write a segment of code that declares an array variable, create an array object...

    in java.... write a segment of code that declares an array variable, create an array object that can hold 20 integers assigns the array object to the array variable, and then uses a loop to fill the array with the following integers... 0,10,20,30,40,50,60,70,80,90,100

  • Write you code in a class named HighScores, in file named HighScores.java. Write a program that...

    Write you code in a class named HighScores, in file named HighScores.java. Write a program that records high-score data for a fictitious game. The program will ask the user to enter five names, and five scores. It will store the data in memory, and print it back out sorted by score. The output from your program should look approximately like this: Enter the name for score #1: Suzy Enter the score for score #1: 600 Enter the name for score...

  • Consider the following database and answer the questions below. a) Write the SQL statement the displays...

    Consider the following database and answer the questions below. a) Write the SQL statement the displays the names of the students who have enrolled in the Database Systems course b) Write the SQL statement that displays a list of the students whose names start with 'S' c) Write the SQL statement that displays the Student ID, Student Name, Course ID, and Grade for students that passed at least one course with a grade better than B+ (i.e. A-, A, and...

  • P3 - An Array of objects (120 points) Write a main program and declare an array...

    P3 - An Array of objects (120 points) Write a main program and declare an array of 5 RectangularCube objects [20pts). a. Use a loop to initialize an array of RectangularCube. In the body of the loop use the rand () function to generate random integers between 1 and 10 to assign to length, width and height data fields of each RectangularCube object (40pts) b. Write the function with header void printCube (RectangularCube rs) that receives an object of the...

  • C++ Programming 1. Write a function (header and body) that accepts an integer as an argument...

    C++ Programming 1. Write a function (header and body) that accepts an integer as an argument and returns that number squared. 2. Write the code that will fill an integer array named multiples with 10 integers from 5 to 50 that are multiples of five. (This should NOT be in the form of an initialization statement.) 3. Write the code that will display the contents of the integer array named multiples. Recall: the size of the array is 10. 4....

  • Write a C++ program that produces the following output: /* OUTPUT Enter your age: 21 Enter...

    Write a C++ program that produces the following output: /* OUTPUT Enter your age: 21 Enter the last name: Lee Hello Tom Lee. You are 21 years old. Press any key */   Declare an array named: firstName The array is a c_string, i.e., it is a null-terminated character array. The size of the array is 10. Assign a first name to it when it is declared.   Declare an array named: lastName The array is a c_string, The size of the...

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