0% found this document useful (0 votes)
31 views6 pages

Hacker Rank

Uploaded by

susheelreddy8142
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views6 pages

Hacker Rank

Uploaded by

susheelreddy8142
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

A VERY BIG SUM

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
int n;
long long int sum=0;
scanf("%d",&n);

long long int arr[n];


for(int i=0; i<n; i++){
scanf("%lld",&arr[i]);

sum += arr[i];

}
printf("%lld",sum);
}
BIRTHDAY CANDLES
#include <stdio.h>
int main() {
int n, i, max, count; // Get the size of the array
scanf("%d", &n);
int arr[n]; // Get the candle heights
for (i = 0; i < n; i++)
{
scanf("%d", &arr[i]);
}
max=arr[0];
count =1;
for (i = 1; i < n; i++)
{
if(arr[i] > max)
{
max = arr[i];
//count = 1;
}
else if(arr[i]==max){
count ++;
}
}
printf("%d", count);
}
GRADING STUDENTS
#include <stdio.h>
int main() {
int n, i;
scanf("%d", &n);
int grades[n];
for (i = 0; i < n; i++) {
scanf("%d", &grades[i]);
}
for (i = 0; i < n; i++) {
if (grades[i] >= 38) {
int next_multiple_of_5 = ((grades[i] / 5) + 1) * 5;
if (next_multiple_of_5 - grades[i] < 3) {
grades[i] = next_multiple_of_5;
}
}
}
for (i = 0; i < n; i++) {
printf("%d\n", grades[i]);
}
return 0;
}
PLUS MINUS
#include <stdio.h>
int main() {
int n;
scanf("%d", &n);
int arr[n];
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
int pos = 0, neg = 0, zero = 0;
for (int i = 0; i < n; i++) {
if (arr[i] > 0) {
pos++;
} else if (arr[i] < 0) {
neg++;
} else {
zero++;
}
}
double pos_ratio = (double)pos / n;
double neg_ratio = (double)neg / n;
double zero_ratio = (double)zero / n;
printf("%.6f\n", pos_ratio);printf("%.6f\n", neg_ratio);
printf("%.6f\n", zero_ratio);
return 0;
}
COMPARING THE TRIPLETS
#include <stdio.h>
int main()
{
int a[3], b[3];
int max=0, min = 0;
for(int i = 0; i < 3; i++)
{
scanf("%d", &a[i]);
}
for(int i = 0; i < 3; i++)
{
scanf("%d", &b[i]);
}
for(int i = 0; i < 3; i++)
{
if(a[i]>b[i]){
max++;
}
else if(a[i]<b[i]){
min++;
}
}
printf("%d\t%d", max, min);
return 0;
}
MINI-MAX SUM
#include <stdio.h>
int main() {
int arr[5];
long long total_sum = 0;
int min_value = 1000000000, max_value = -1000000000;
for (int i = 0; i < 5; i++) {
scanf("%d", &arr[i]);
total_sum += arr[i]; // Calculate the total sum
if (arr[i] < min_value) {
min_value = arr[i]; // Find the minimum value
}
if (arr[i] > max_value) {
max_value = arr[i]; // Find the maximum value
}
}
long long min_sum = total_sum - max_value;
long long max_sum = total_sum - min_value;
printf("%lld %lld\n", min_sum, max_sum);
return 0;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy