Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 22

1.

Add two numbers

#include <stdio.h>

#include <string.h>

#include <math.h>

#include <stdlib.h>

int main() {

/* Enter your code here. Read input from STDIN. Print output to STDOUT */

double a,b;

long c,d;

scanf("%lf%lf",&a,&b);

c=a;

d=b;

if(c==a & d==b)

printf("%ld",c+d);

else{

printf("%.2lf",a+b);

return 0;

}
Floting point integers

#include <stdio.h>

int main()

double var;

//input the variable var and print it upto 2, 4 and 6 decimal places here.

//note that every output must be on a new line

//you can use the '\n' token to go to a new line

scanf("%lf",&var);

printf("%.2lf\n",var);

printf("%.4lf\n",var);

printf("%.6lf\n",var);

return 0;

Magic or logic

#include <stdio.h>

#include <string.h>

#include <math.h>

#include <stdlib.h>

int main() {

/* Enter your code here. Read input from STDIN. Print output to STDOUT */

long long a,b,c;


scanf("%lld%lld%lld",&a,&b,&c);

printf("%lld",a+b+c);

return 0;

Cut the fruit

#include <stdio.h>

#include <string.h>

#include <math.h>

#include <stdlib.h>

int main() {

int w;

scanf("%d",&w);

if(w==2)

printf("NO");

return 0;

if(w%2==0)

printf("YES");

else{

printf("NO");

}
/* Enter your code here. Read input from STDIN. Print output to STDOUT */

return 0;

Trouble the number system

#include <stdio.h>

#include <string.h>

#include <math.h>

#include <stdlib.h>

int main() {

long long i,n,p=1;

long long count=0;

scanf("%lld",&n);

long long a[n];

for(i=0;i<n;i++)

scanf("%lld",&a[i]);

while(a[i]%10==0)

count++;

a[i]=a[i]/10;

p=p*a[i];
}

printf("%lld",p);

for(i=0;i<count;i++)

printf("0");

/* Enter your code here. Read input from STDIN. Print output to STDOUT */

return 0;

Equal bases

#include <stdio.h>

#include <string.h>

#include <math.h>

#include <stdlib.h>

int main() {

/* Enter your code here. Read input from STDIN. Print output to STDOUT */

int n,count=0;

scanf("%d",&n);

for(int i=2;i<=n;i++)

if(n%i==0)

{
count++;

printf("%d",count);

return 0;

Residuo arithematic

#include <stdio.h>

#include <string.h>

#include <math.h>

#include <stdlib.h>

int main() {

int n,m;

scanf("%d %d",&n,&m);

int x,y;

scanf("%d %d",&x,&y);

while(x!=y)

if(x<y)x+=n;

else y+=m;

}
int a=x;

scanf("%d %d",&x,&y);

while(x!=y)

if(x<y)x+=n;

else y+=m;

int b=x;

scanf("%d %d",&x,&y);

while(x!=y)

if(x<y)x+=n;

else y+=m;

int c=x;

printf("%d",2*a+b-c);

return 0;

MULTIPLE'S OF 4

#include <bits/stdc++.h>

using namespace std;


string isAMultipleOf4(int n)

if ((n & 3) == 0)

return "yes";

return "no";

// Driver program to test above

int main()

int n;

scanf("%d",&n);

cout << isAMultipleOf4(n);

return 0;

Make Palindrome By Reversing


 PRACTICE
 COMPETE
 JOBS
 LEADERBOARD



 33
 161FA04390
1. All Contests
2. May-June 19 : CCC Vignan University : Coding Camp 2
3. Make Palindrome By Reversing

Make Palindrome By Reversing


by keyurjain

 Problem

 Submissions

 Discussions

Submitted 6 hours ago • Score: 1.00


Status: Accepted

Test Case #0

Test Case #1

Test Case #2

Test Case #3

Test Case #4

Submitted Code
Language: C
Open in editor

#include <stdio.h>
2
#include <string.h>
3

#include <math.h>
4

#include <stdlib.h>
5

int main() {
7

long int num,i=0,res=0,p,s;


8

/* Enter your code here. Read input from STDIN. Print output to STDOUT */
9

scanf("%ld",&num);
10

11

for(int j=0;j<5;j++)
12

{
13

p=num;
14

res=0;
15

while (num!=0){
16

res=res*10+num%10;
17

num=num/10;
18

}
19

20

num=p+res;
21

s=num;
22

res=0;
23

while (num!=0){
24

res=res*10+num%10;
25

num=num/10;
26

}
27

if (s==res) {
28

printf("%ld\n",s);
29

printf ("YES");
30

return 0;
31

}
32

num=s;
33
}
34

printf("NO");
35

return 0;
36

INTO water
#include <stdio.h>

#include <string.h>

#include <math.h>

#include <stdlib.h>

int main() {

int n,i,c=0;

scanf("%d",&n);

int x[n],y[n];

for(i=0;i<n;i++)

scanf("%d%d",&x[i],&y[i]);

for(i=1;i<n-1;i++)

if(x[i-1]<x[i]&&y[i-1]==y[i])

if(x[i]==x[i+1]&&y[i]<y[i+1])

c++;
if(x[i-1]>x[i]&&y[i-1]==y[i])

if(x[i]==x[i+1]&&y[i]>y[i+1])

c++;

if(x[i-1]==x[i]&&y[i-1]>y[i])

if(x[i]<x[i+1]&&y[i]==y[i+1])

c++;

if(x[i-1]==x[i]&&y[i-1]<y[i])

if(x[i]>x[i+1]&&y[i]==y[i+1])

c++;

printf("%d",c);

/* Enter your code here. Read input from STDIN. Print output to STDOUT */

return 0;

Method 2

#include <stdio.h>

#include <string.h>

#include <math.h>

#include <stdlib.h>
int main() {

/* Enter your code here. Read input from STDIN. Print output to STDOUT */

int n,p;

scanf("%d",&n);

p=((n-4)/2);

printf("%d",p);

return 0;

To and Fro
#include <stdio.h>

#include <string.h>

#include <math.h>

#include <stdlib.h>

int main() {

int n;

scanf("%d",&n);

while(n--)

int f,b,t,d;
scanf("%d %d %d %d",&f,&b,&t,&d);

long long ans=0;

int count=0,dist=0;

while(1)

if(dist+b<d)

dist+=b;

else

ans=ans+(d-dist)*t;

break;

dist=dist-f;

count++;

ans=ans+(count*t)*(f+b);

printf("%lld\n",ans);

/* Enter your code here. Read input from STDIN. Print output to STDOUT */

return 0;

Domino piles

#include <stdio.h>
#include <string.h>

#include <math.h>

#include <stdlib.h>

int main() {

/* Enter your code here. Read input from STDIN. Print output to STDOUT */

int p,q,s;

scanf("%d%d",&p,&q);

s=p*q/2;

printf("%d",s);

return 0;

Parliament square
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main() {

/* Enter your code here. Read input from STDIN. Print output to STDOUT */
long n,m,a,z,y,i,area=0;
scanf("%ld %ld %ld",&n,&m,&a);
if(n%a!=0)
{
z=n/a;
n=a*(z+1);
}
if(m%a!=0)
{
y=m/a;
m=a*(y+1);
}
long t=n/a;
long u=m/a;
printf("%ld",t*u);
return 0;
}

Panner love
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main() {

/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int i,n,sum=0;
scanf("%d",&n);
int p[n],s[n];
for(i=0;i<n;i++)
{
scanf("%d %d",&p[i],&s[i]);
//scanf("%d",&s[n]);
}
for(i=0;i<n;i++)
{
if(s[i+1]>s[i])
{
s[i+1]=s[i];
}

sum=sum+p[i]*s[i];

}
printf("%d",sum);
return 0;
}

Group of jackels

#include <math.h>

#include <stdio.h>
#include <string.h>

#include <stdlib.h>

#include <assert.h>

#include <limits.h>

#include <stdbool.h>

int main()

int n;

scanf("%d",&n);

int a[n+1],sum=0,i;

for(i=1;i<=n;i++)

scanf("%d",&a[i]);

for(i=1;i<=n;i++)

if(a[i]>a[i+1])

sum=sum+a[i];

}
printf("%d",sum);

Array of hills

#include <stdio.h>

#include <string.h>

#include <math.h>

#include <stdlib.h>

int main() {

/* Enter your code here. Read input from STDIN. Print output to STDOUT */

int n;

scanf("%d",&n);

int a[n],min=a[0],count=0,i;

for(i=0;i<n;i++)

scanf("%d",&a[i]);

i=0;

for(;i<n-1;)

{
if(a[i]<a[i+1])

i++;//count++;

else{

break;

for(;i<n-1;)

if(a[i]==a[i+1])

i++;// count++;

else{

break;

for(;i<n-1;)

if(a[i]>a[i+1])
{

i++;// count++;

else

break;

if(i==n-1)

printf("yes");

else{

printf("no");

return 0;

Consecutive prime sum


#include <stdio.h>
int prime(int b)
{
int j,cnt;
cnt=1;
for(j=2;j<=b/2;j++)
{
if(b%j==0)
cnt=0;
}
if(cnt==0)
return 1;
else
return 0;
}
int main() {
int i,j,n,cnt,a[25],c,sum=0,count=0,k=0;
scanf("%d",&n);
for(i=2;i<=n;i++)
{
cnt=1;
for(j=2;j<=n/2;j++)
{
if(i%j==0)
cnt=0;
}
if(cnt==1)
{
a[k]=i;
k++;
}
}
for(i=0;i<k;i++)
{
sum=sum+a[i];
c= prime(sum);
if(c==1)
count++;
}
printf("%d",count);
return 0;
}

You might also like