Question

In: Computer Science

How to make this problem? in C language Build an algorithm that, upon receiving as input...

How to make this problem? in C language

Build an algorithm that, upon receiving as input the ID and salary of the professors of a university, determines the following:
-Total payroll of teachers.
-The average salaries of teachers.
-ID of the employee with the highest salary as well as what's his salary

thanks

Solutions

Expert Solution

Here is the answer for your question in C Programming Language.

Kindly upvote if you find the answer helpful.

######################################################################

CODE :

#include<stdio.h>

//Structure that defines a professor with Id and salary
struct Professor{
   int ID;
   double salary;
};
void main(){
  
   //Required variables
   int n,i,id;
   double total = 0,average,maxSalary = 0;
   //Read number of professors
   printf("Enter the number of professors : ");
   scanf("%d",&n);
  
   //Create array of structures with number of professors
   struct Professor professors[n];
  
   //Loop number of professors times
   for(i = 0;i<n;i++){
       //Read id of ith professor
       printf("Enter the ID of the professor #%d : ",(i+1));
       scanf("%d",&professors[i].ID);
       //Read salary of ith professor
       printf("Enter the salary of the professor #%d : $",(i+1));
       scanf("%lf",&professors[i].salary);
       //Check if it is the highest salary,if yes set id, and maxSalary values
       if(maxSalary < professors[i].salary){
           maxSalary = professors[i].salary;
           id = professors[i].ID;
       }
       //Cummulate salaries to 'total'
       total += professors[i].salary;
   }
   //Calculate average
   average = total/n;
  
   //Display output
   printf("\n=================PAYROLL=================\n");
   printf("\nTotal payroll of teachers : $%.2lf\n",total);
   printf("The average salaries of teachers : $%.2lf\n",average);
   printf("The highest salary is : $%.2lf\n",maxSalary);
   printf("The ID of the employee with highest salary is : %d\n",id);
}

#############################################################

SCREENSHOTS :

Please see the screenshots of the code below for the indentations of the code.

##################################################################

OUTPUT :

Any doubts regarding this can be explained with pleasure :)


Related Solutions

in the c programming language input is given in the form The input will be of...
in the c programming language input is given in the form The input will be of the form [number of terms] [coefficient k] [exponent k] … [coefficient 1] [exponent 1] eg. 5 ─3 7 824 5 ─7 3 1 2 9 0 in this there are 5 terms with -3x^7 being the highest /* Initialize all coefficients and exponents of the polynomial to zero. */ void init_polynom( int coeff[ ], int exp[ ] ) { /* ADD YOUR CODE HERE...
LargestTwo problem: Based upon the pseudocode code below, implement in C++ a divide-and-conquer algorithm that finds...
LargestTwo problem: Based upon the pseudocode code below, implement in C++ a divide-and-conquer algorithm that finds the largest and second largest value from a vector of ints. void LargestTwo (vector l, int left, int right, int & largest, int & secondLargest) • Please write comment for your functions, similar to the one in the pseudocode, to include both pre- and post-conditions. • Comment on the logic of your code, e.g., what is true after the two recursive calls? • Answer...
Problem: Make linkedList.h and linkList.c in Programming C language Project description This project will require students...
Problem: Make linkedList.h and linkList.c in Programming C language Project description This project will require students to generate a linked list of playing card based on data read from a file and to write out the end result to a file. linkedList.h Create a header file name linkedList Include the following C header files: stdio.h stdlib.h string.h Create the following macros: TRUE 1 FACES 13 SUITS 4 Add the following function prototypes: addCard displayCards readDataFile writeDataFile Add a typedef struct...
create a genetic algorithm for knapsack problem in c++
create a genetic algorithm for knapsack problem in c++
Program Language C++ How do I take lines of string from an input file, and implement...
Program Language C++ How do I take lines of string from an input file, and implement them into a stack using a double linked list? Example input, command.txt, and output file. Ex: Input.txt postfix: BAC-* prefix:+A*B/C-EF postfix:FE-C/B*A+ postfix:AB-C-D/ postfix:AB-CF*-D / E+ Command.txt printList printListBackwards Output.txt List: postfix:BAC-* prefix:+A*B/C-EF postfix:FE-C/B*A+ postfix:AB-C-D/ postfix:AB-CF*-D/E+ Reversed List: postfix:AB-CF*-D/E+ postfix:AB-C-D/ postfix:FE-C/B*A+ prefix:+A*B/C-EF postfix:BAC-*
Write a program in C language that uses a binary search algorithm to guess a number...
Write a program in C language that uses a binary search algorithm to guess a number from 1 to 100. The computer will keep guessing until they get the users number correct.
In C language Please display results The Euclidean algorithm is a way to find the greatest...
In C language Please display results The Euclidean algorithm is a way to find the greatest common divisor of two positive integers, a and b. First let me show the computations for a=210 and b=45. Divide 210 by 45, and get the result 4 with remainder 30, so 210=4·45+30. Divide 45 by 30, and get the result 1 with remainder 15, so 45=1·30+15. Divide 30 by 15, and get the result 2 with remainder 0, so 30=2·15+0. The greatest common...
please i want solution for this question with algorithm and step by step with c++ language...
please i want solution for this question with algorithm and step by step with c++ language write a program using for loop that calculates the total grade for N classroom exercises as a percentage. The user should input the value for N followed by each of the N scores and totals. Calculate the overall percentage (sum of the total points earned divided by the total points possible) and output it as a percentage. Sample input and output is shown below.How...
C++ How do you make a 2d array with a user input. For example, the row...
C++ How do you make a 2d array with a user input. For example, the row and columns of the 2d array will be the same so the program can create a square matrix.
using C language Create a bitwise calculator that ask user for input two input, first int,...
using C language Create a bitwise calculator that ask user for input two input, first int, bitwise operation, second int (i.e 5 & 9) only those bitwise operation are allowed: & ~ ^ | << >>. If user uses wrong operators stop program and ask again. Convert the first int and second int into 8 BITS binary (00000000) and use bitwise operator given by user to either AND, OR, XOR, etc (ie 1001 & 1111)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT