Question

Write any 2 C programs of a structure having return type int, char, float. Explain each...

Write any 2 C programs of a structure having return type int, char, float. Explain each step for both the programs.

The code should be simple as I am a beginner. Also, I need an urgent answer.

Homework Answers

Answer #1

Here is the First program: Student information program:

Program screenshot:

Output:

Code to copy:

// header file

#include <stdio.h>

// structure for student

struct Stud{

char *student_name;

int stu_id;

float marks;

};

int main()

{

// create a vairable for structure

// here student is variable of structure Stud

struct Stud student;

// give them values

student.student_name = "John";

student.stu_id = 11122;

student.marks = 20;

// dislay output

printf("Student Name is: %s", student.student_name);

printf("\nStudent Id is: %d", student.stu_id);

printf("\nStudent Marks is: %f", student.marks);

return 0;

}

--------------------------------------------------------------------------------------------------------------------

Program 2:

Employee information:

Program screenshot:

Code to copy:

#include <stdio.h>

// create required structure

struct Empl{

// name of employee, return type is char

char *emp_name;

int emp_id;

float emp_salary;

};

int main()

{

// give a variable to the structure

struct Empl employee;

// give values to the variables

employee.emp_name = "Jphn";

employee.emp_id = 1220;

employee.emp_salary = 70000;

// display output

printf("Employee Name is: %s", employee.emp_name);

printf("\nEmployee Id is: %d", employee.emp_id);

printf("\nEmployee salary is: %f", employee.emp_salary);

return 0;

}

---------------------------------------------------------

PLEASE UPVOTE.

Know the answer?
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
Similar Questions
q : explain the code for a beginner in c what each line do Question 2....
q : explain the code for a beginner in c what each line do Question 2. The following code defines an array size that sums elements of the defined array through the loop. Analyze the following code, and demonstrate the type of error if found? What we can do to make this code function correctly ? #include <stdio.h> #define A 10 int main(int argc, char** argv) { int Total = 0; int numbers[A]; for (int i=0; i < A; i++)...
In C language make a structure called funds funds should have variable fields of type int...
In C language make a structure called funds funds should have variable fields of type int id; char bank[10]; float balance; The program would have a function called sum which returns a float. To sum pass structure funds and a pointer called record. initialize record to equal {1, "BOA", 10023.43} call sum passing the pointer record , the function returns a float value into variable result. initialize record to equal {2, "Chase", 4239.87} call sum passing the pointer record ,...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g,...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g, char wordlist[][MAX_WORD_LENGTH], int numwords)] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) What int setup_game needs to do setup_game() does exactly what the name suggests. It sets up a new game of hangman. This means that it picks a random word from the supplied wordlist array and...
In the following C code, Which variable if NOT of primitive data type? A. a B....
In the following C code, Which variable if NOT of primitive data type? A. a B. b C. c D. d int a = 10; double b = 20.0; float c = false; char d[5] = "Hello"; // here we define a string In programming language C, the implementation of a string data type is limited dynamic length, which means the length of a string variable is fixed once it has been defined. A. True B. False In C# programming...
I am trying to solve the following C++ problem over structures. I am having trouble with...
I am trying to solve the following C++ problem over structures. I am having trouble with the very last structure and I made a comment next to where I am confused. I included the assignment instructions and my current code. I would appreciate if anyone can help me explain what I need to do for the last structure. Thank you. Assignment Instructions Create a program that will prompt me for each of the following items: 1. Date of Birth 2....
1. Please write the following in C++ also please show all output code and comment on...
1. Please write the following in C++ also please show all output code and comment on code. 2. Also, use CPPUnitLite to write all test and show outputs for each test. Write CppUnitLite tests to verify correct behavior for all the exercises. The modifications are aimed at making the exercises more conducive to unit tests. Write a function that swaps (exchanges the values of two integers). Use int* as the argument type. Write a second swap function using a reference...
PLEASE ANSWER I WILL RATE YOUR ANSWER AND THUMBS UP For the following C functions: int...
PLEASE ANSWER I WILL RATE YOUR ANSWER AND THUMBS UP For the following C functions: int q3(int x) {     return ((~x)>>31) & 0x1; } int q4(int x) {     int mask = x>>31;     int y= (x ^ mask);     int z = (~mask + 1);     return (y+z); } int q5(int x){     int y = !x;     int z = x >> 31;     z = z | y;     return !z; } int q6(int x) {...
Note: Do not use classes or any variables of type string to complete this assignment Write...
Note: Do not use classes or any variables of type string to complete this assignment Write a program that reads in a sequence of characters entered by the user and terminated by a period ('.'). Your program should allow the user to enter multiple lines of input by pressing the enter key at the end of each line. The program should print out a frequency table, sorted in decreasing order by number of occurences, listing each letter that ocurred along...
I am trying to write a program in C language but keep running into errors. Any...
I am trying to write a program in C language but keep running into errors. Any help would be awesome. here is my code I have so far. #include <stdio.h> #include <conio.h> #include <string.h> int main(){    int lenght, i = 0, state = 0;    char line[100];    printf("enter the string for checking of comment line: \n");    gets(line);    while(i < strline(line)){        switch(state){            case 0: if (line[i] == '/'){               ...
VERILOG Design an Arithmetic Logic Unit (ALU) that can perform four-bit 1. Four-bit addition; 2. Four-bit...
VERILOG Design an Arithmetic Logic Unit (ALU) that can perform four-bit 1. Four-bit addition; 2. Four-bit subtraction; 3. Four-bit multiplication; 4. Four-bit comparator (that compares two binary numbers to check whether two numbers are equal, or one is less/greater than other). Write test benches and simulate each module/submodule. Hint: First make individual modules of the four-bit adder, four-bit subtractor, four-bit multiplier, four-bit comparator modules (make all these in same/one project) and then use a multiplexer to combine these modules to...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT