Birthday Cake Candles Hackerrank Solution in C Programming
Birthday cake candles hackerrank solution in C programming.
In this article, you will make the birthday cake candles hackerrank solution in C programming.
Example
Enter the size of the array::
6
Enter the 6 elements of the array::
3 5 1 3 5 7
TALLEST CANDLES:: 1
You should have knowledge of the following topics in c programming to understand this program:
- C
main()
function - C
printf()
function - C Data Type
Source Code
// Birthday Cake Candles Hackerrank Solution in C Programming
#include <stdio.h>
#include <math.h>
int main() {
int s=0;
printf("Enter the size of the array::\n");
scanf("%d", &s);
int candles[s];
printf("\nEnter the %d elements of the array::\n", s);
int i=0;
while (i<s) {
scanf("%d", &candles[i]);
i++;
}
// It will calculate the tallest candles from the given array
double max=-INFINITY;
int l=s, counter=0;
while (l--) {
if (candles[l] > max) {
max=candles[l];
}
}
l=s;
while (l--) {
if (candles[l] == max) {
counter++;
}
}
// It will print the final output of the program
printf("\nTALLEST CANDLES:: %d", counter);
return 0;
}
Output
Enter the size of the array::
6
Enter the 6 elements of the array::
3 5 1 3 5 7
TALLEST CANDLES:: 1
Explanation
In this given program, we have taken the input size of the array 6
and elements of the array 3 5 1 3 5 7
. After that, we made iterations on each element of the array to count the highest value from the array and set a counter variable counter to count the highest values.
Then It will return the counting of the tallest candles of the given array is 1
.