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...
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.
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-*
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)
Programming language: C++   suggested software: Code::Blocks Develop an algorithm and write a C++ program that computes...
Programming language: C++   suggested software: Code::Blocks Develop an algorithm and write a C++ program that computes the final score of a baseball game. Use a loop to read the number of runs scored by both teams during each of nine innings. Display the final score afterward. Submit your design, code, and execution result via file, if possible
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.
Build a Dynamic Programming algorithm in Python for the following problem. Given two sequences of vowels,...
Build a Dynamic Programming algorithm in Python for the following problem. Given two sequences of vowels, find the length of longest subsequence present in both of them. NOTE: A subsequence is a sequence that appears in the same order, but not necessarily contiguous. For example, “aei”, “aeo”, “eio”, “aiu”, ... are subsequences of “aeiou”. Sample Input 1: aeiou aiu Sample Output 1: 3 Sample Input 2: aeaiueoiuaeeoeooaauoi aeuioauuuoaeieeaueuiouaiieuiuuuaoueueauaeiauuo Sample Output 2: 16 Sample Input 3: iioioieiaiauaoeoiioiiue iuuueauiaieooaoaaouaaaae Sample Output 3:...
Lab 1 Write a program in the C/C++ programming language to input and add two fractions...
Lab 1 Write a program in the C/C++ programming language to input and add two fractions each represented as a numerator and denominator. Do not use classes or structures. Print your result (which is also represented as a numerator/denominator) to standard out. If you get done early, try to simplify your result with the least common denominator. The following equation can be used to add fractions: a/b + c/d = (a*d + b*c)/(b*d) Example: 1/2 + 1/4 = ( 1(4)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT