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

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...
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
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)...
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.
C Programming Language (Code With C Programming Language) Problem Title : Which Pawn? Jojo is playing...
C Programming Language (Code With C Programming Language) Problem Title : Which Pawn? Jojo is playing chess himself to practice his abilities. The chess that Jojo played was N × N. When Jojo was practicing, Jojo suddenly saw a position on his chessboard that was so interesting that Jojo tried to put the pieces of Rook, Bishop and Knight in that position. Every time he put a piece, Jojo counts how many other pieces on the chessboard can be captured...
c++ is the language Code an O(nlog(n)) algorithm to count the number of inversions DO NOT...
c++ is the language Code an O(nlog(n)) algorithm to count the number of inversions DO NOT ADD OR EDIT FUNCTIONS USE THESE ONLY DO NOT EDIT THE TEST FILE EITHER countInv.cpp #include <vector> #include <algorithm> using namespace std; int mergeInv(vector<int>& nums, vector<int>& left, vector<int>& right) { // You will need this helper function that calculates the inversion while merging // Your code here } int countInv(vector<int>&nums) { // Your code here } countInv_test.cpp #include <iostream> #include <vector> using namespace std;...
5. Design a dynamic programming algorithm to solve the following problem. Input: An array A[1, ....
5. Design a dynamic programming algorithm to solve the following problem. Input: An array A[1, . . . , n] of positive integers, an integer K. Decide: Are there integers in A such that their sum is K. (Return T RUE or F ALSE) Example: The answer is TRUE for the array A = [1, 2, 3] and 5, since 2 + 3 = 5. The answer is FALSE for A = [2, 3, 4] and 8. Note that you...
Write an algorithm (flowchart OR Pseudocode) for the following problem Take input character from the user...
Write an algorithm (flowchart OR Pseudocode) for the following problem Take input character from the user unless he enters '$'. Thereafter display how may vowels were entered by the user. Also display the number of each vowel ('a', 'e', 'i', 'o' and 'u') separately. For example if the user enters B a b e c o o d i u g o a l $ Then we have the output below: #A=2 #E=1 #I=1 #O=3 #U=2
(a) Implement the following algorithm, which is given a duplicate-free array array as input, in C++....
(a) Implement the following algorithm, which is given a duplicate-free array array as input, in C++. whatDoIDo (array): 1) Build a heap from array (using buildHeap as explained in class), where the heap starts at position array[0]. 2) Starting from j = size of array - 1, as long as j>0: i. Swap the entries array[0] and array[j]. ii. Percolate down array[0], but only within the subarray array[0..j-1]. iii. Decrement j by 1. Provide three input/output examples for duplicate-free arrays...
make a calculator in C++ or C language that can take up to 5 values at...
make a calculator in C++ or C language that can take up to 5 values at same time
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT