Hacker Rank
Hacker Rank
Hacker Rank
#include<stdio.h>
int main()
{
int a,b,sum;
scanf("%d%d",&a,&b);
sum=a+b;
printf("%d",sum);
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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);
}