0% found this document useful (0 votes)
10 views5 pages

Hacker Rank

Uploaded by

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

Hacker Rank

Uploaded by

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

//Hackerrank Solve me first

#include<stdio.h>
int main()
{
int a,b,sum;
scanf("%d%d",&a,&b);
sum=a+b;
printf("%d",sum);
}

//Grading Students- Hackerrank


#include<stdio.h>
int main()
{
int n,i,remain;
scanf("%d",&n);
int grades[n];
for(i=0;i<n;i++)
{
scanf("%d",&grades[i]);
}
for(i=0;i<n;i++)
{
remain=grades[i]%5;
if(grades[i]>=38)
{
if(remain>2)
{
grades[i]=(grades[i]+5)-remain;
}
}
}
for(i=0;i<n;i++)
{
printf("%d\n",grades[i]);
}
return 0;
}

//A very Big Sum - Hackerrank

#include<stdio.h>
int main()
{
int n,i;
scanf("%d",&n);
unsigned long long int a[n],sum=0;
for(i=0;i<n;i++)
{
scanf("%lld",&a[i]);
}
for(i=0;i<n;i++)
{
sum=sum+a[i];
}
printf("%lld",sum);
return 0;
}
//Plusminus-Hakerrank
//Given an array of integers, calculate the ratios of its elements that are
positive, negative, and zero. Print the decimal value of each fraction on a new
line with places after the decimal.

#include<stdio.h>
int main()
{
int n,i;
float pos=0,neg=0,zero=0;
scanf("%d",&n);
int a[n];
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
if(a[i]>0)
{
pos++;
}
else if(a[i]<0)
{
neg++;
}
else
{
zero++;
}
}
printf("%f\n%f\n%f",pos/n,neg/n,zero/n);
return 0;
}

//Mini max sum- Hackerrank

#include<stdio.h>
int main()
{
int i;
long long int a[5];
for(i=0;i<5;i++)
{
scanf("%lld",&a[i]);
}
long long int tot=0,max=a[0],min=a[0];
for(i=0;i<5;i++)
{
tot=tot+a[i];
if(a[i]>max)
{
max=a[i];
}
if(a[i]<min)
{
min=a[i];
}
}
printf("%lld %lld",tot-max,tot-min);
return 0;
}

//birthday cake candles-hackerrank

#include<stdio.h>
int main()
{
int n,i;
scanf("%d",&n);
int a[n];
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
int max=a[0];
for(i=0;i<n;i++)
{
if(a[i]>max)
{
max=a[i];
}
}
int count=0;
for(i=0;i<n;i++)
{
if(a[i]==max)
{
count++;
}
}
printf("%d",count);
return 0;
}

//Compare the triplets- hackerrank

#include<stdio.h>
int main()
{
int a[3],b[3],alice=0,bob=0,i;
for(i=0;i<3;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<3;i++)
{
scanf("%d",&b[i]);
}
for(i=0;i<3;i++)
{
if(a[i]>b[i])
{
alice++;
}
else if(b[i]>a[i])
{
bob++;
}
}
printf("%d %d",alice,bob);
return 0;
}

//diagonal difference- hackerrank

#include <stdio.h>
int main() {
int n, i, j;
scanf("%d", &n);
int a[n][n];
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
scanf("%d", &a[i][j]);
}
}
int ld = 0,rd = 0,dd;
for (int i = 0; i < n; i++)
{
ld=ld+a[i][i];
}
for (int i = 0; i < n; i++)
{
rd=rd+a[i][n-1-i];
}
dd=ld-rd;
if(dd<0)
{
dd=-dd;
}
else {
{
dd=dd;
}
}
printf("%d", dd);
return 0;
}

//Breaking the records - hackerrank

#include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
int ar[n];
int i;
for(i=0;i<n;i++)
{
scanf("%d",&ar[i]);
}
int small,large;
small=ar[0];
large=ar[0];
int c,c1;
c=0;
c1=0;
for(i=0;i<n;i++)
{
if(ar[i]>large)
{
c++;
large=ar[i];
}
else if(ar[i]<small)
{
c1++;
small=ar[i];
}
}
printf("%d %d",c,c1);
}

You might also like