Write a code to determine the total number of stops an elevator would take to serve N number of people.
Answer / Sumit Yadav
```cn#include <stdio.h>nnint elevators(int people[], int floor, int num_people)n{n int count = 0;n for (int i = 0; i < num_people; ++i) {n count += abs(floor - people[i]);n }n return count * 2;n}nnint main()n{n int people[] = {1, 3, 5, 7, 9};n int num_people = sizeof(people) / sizeof(people[0]);n printf("Total number of stops: %d
", elevators(people, 5, num_people));n return 0;n}n```nThe code assumes the elevator starts at floor 5 and serves people in the order they are listed. The total number of stops is calculated as twice the sum of the absolute differences between the current floor and each person's desired floor.
| Is This Answer Correct ? | 0 Yes | 0 No |
Write c-code for 5+55+555+5555+55555+555555+5555555. Output will be it's answer...
what will be the output off the following program? #include<stdio.h> int main() { int a; a=015+0*71+5; printf("%d,a"); return0; }
int main() { Int n=20,i; For(i=0;i<=n;i--) { Printf(“-“); Return 0;
how 2 compile & execute c program with out using editor?
Average of a couple 10 years ago was 25. The average remains same after having a child and twins after 3 years. What is the present age of the first child
What is information technology.
What are the concepts introduced in OOPs?
What is the difference between void main() and void main (void) give example programme?
What is the difference between malloc() and calloc()?
Write a C Programm.. we press 'a' , it shows the albhabetical number is 1, if we press 'g' it shows the answer 7.. any can help me
What are global variables and how do you declare them?
what information does the header files contain?
6 Answers BSNL, Cisco, GDA Technologies,