Skip to content

Commit a859e3a

Browse files
committed
GeeksForGeeks Problem
Solution of the Problem From GeeksForGeeks Website.
1 parent 9679072 commit a859e3a

File tree

162 files changed

+5139
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

162 files changed

+5139
-0
lines changed

GEEKSFORGEEKS/Geek_AP_Sum.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//GeeksForGeeks Problem : Sum of an AP
2+
//Author : By PIYUSH
3+
#include<stdio.h>
4+
int main()
5+
{
6+
int t,a,n,d,sum;
7+
scanf("%d",&t);
8+
while(t--)
9+
{
10+
scanf("%d",&n);
11+
scanf("%d%d",&a,&d);
12+
sum=(2*a)+(n-1)*d;
13+
sum=(sum*n)/2;
14+
printf("%d\n",sum);
15+
}
16+
return 0;
17+
}

GEEKSFORGEEKS/Geek_All_Divisors.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//GeeksForGeeks Problem : All Divisors of a Natural Number (School)
2+
//Author : By PIYUSH
3+
#include<stdio.h>
4+
int main()
5+
{
6+
int t,no,i;
7+
scanf("%d",&t);
8+
while(t--)
9+
{
10+
scanf("%d",&no);
11+
for(i=1;i<=no;i++)
12+
{
13+
if(no%i==0)
14+
printf("%d ",i);
15+
}
16+
printf("\n");
17+
}
18+
return 0;
19+
}

GEEKSFORGEEKS/Geek_Alone_in_Couple.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//GeeksForGeeks Problem : ALone in Couple(Basic)
2+
//Author : PIYUSH
3+
#include<stdio.h>
4+
int main()
5+
{
6+
int t,a[505],i,count,n,j,temp;
7+
scanf("%d",&t);
8+
while(t--)
9+
{
10+
scanf("%d",&n);
11+
for(i=0;i<n;i++)
12+
{
13+
scanf("%d",&a[i]);
14+
}
15+
for(i=0;i<n-1;i++)
16+
{
17+
for(j=i;j<n;j++)
18+
{
19+
if(a[i]>a[j])
20+
{
21+
temp=a[i];
22+
a[i]=a[j];
23+
a[j]=temp;
24+
}
25+
}
26+
}
27+
for(i=0;i<n-1;i=i+2)
28+
{
29+
if(a[i]!=a[i+1])
30+
break;
31+
}
32+
printf("%d\n",a[i]);
33+
}
34+
return 0;
35+
}

GEEKSFORGEEKS/Geek_AlphaNumeric.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//GeeksForGeeks Problem : Remove Characters From AlphNumeric String.
2+
//Author : By PIYUSH
3+
#include<stdio.h>
4+
#include<string.h>
5+
int main()
6+
{
7+
int t,i;
8+
char str[105];
9+
scanf("%d",&t);
10+
while(t--)
11+
{
12+
scanf("%s",str);
13+
for(i=0;i<strlen(str);i++)
14+
{
15+
if((str[i]>=65 && str[i]<=90) || (str[i]>=97 && str[i]<=122))
16+
continue;
17+
else
18+
putchar(str[i]);
19+
}
20+
printf("\n");
21+
}
22+
return 0;
23+
24+
}

GEEKSFORGEEKS/Geek_Anagram.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//GeeksForGeeks Problem : Anagram(Easy)
2+
//Author : By PIYUSH
3+
#include<stdio.h>
4+
#include<string.h>
5+
int main()
6+
{
7+
int t,i,j,l,count,l1;
8+
char str[105],str1[105];
9+
scanf("%d",&t);
10+
while(t--)
11+
{
12+
scanf("%s",str);
13+
scanf("%s",str1);
14+
l=strlen(str);
15+
l1=strlen(str1);
16+
count=0;
17+
if(l==l1)
18+
{
19+
for(i=0;i<l;i++)
20+
{
21+
for(j=0;j<l;j++)
22+
{
23+
if(str1[j]==str[i])
24+
{
25+
str[i]='P';
26+
count++;
27+
break;
28+
}
29+
}
30+
}
31+
if(count==l)
32+
printf("YES\n");
33+
else
34+
printf("NO\n");
35+
}
36+
else
37+
printf("NO\n");
38+
}
39+
return 0;
40+
}

GEEKSFORGEEKS/Geek_And_Gate.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//GeeksForGeeks Problem : The AND Gate(Basic)
2+
//Author : PIYUSH
3+
#include<stdio.h>
4+
int main()
5+
{
6+
int t,n,no,count;
7+
scanf("%d",&t);
8+
while(t--)
9+
{
10+
count=0;
11+
scanf("%d",&n);
12+
while(n--)
13+
{
14+
scanf("%d",&no);
15+
if(no==0)
16+
count++;
17+
}
18+
if(count>0)
19+
printf("0\n");
20+
else
21+
printf("1\n");
22+
}
23+
return 0;
24+
}

GEEKSFORGEEKS/Geek_Angle_between.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//GeeksForGeeks Problem : Angle Between Hour And Minute Hand (Basic)
2+
//Author : PIYUSH
3+
#include<stdio.h>
4+
int main()
5+
{
6+
int t,h,m,a;
7+
scanf("%d",&t);
8+
while(t--)
9+
{
10+
scanf("%d%d",&h,&m);
11+
12+
}
13+
}

GEEKSFORGEEKS/Geek_Array_Sotred.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//GeeksForGeeks Problem: Check If an Array is Sorted
2+
//Author : By PIYUSH
3+
#include<stdio.h>
4+
int main()
5+
{
6+
int t,n,no[505],i,j,temp,a[505],count;
7+
scanf("%d",&t);
8+
while(t--)
9+
{
10+
scanf("%d",&n);
11+
for(i=0;i<n;i++)
12+
{
13+
scanf("%d",&no[i]);
14+
a[i]=no[i];
15+
}
16+
for(i=0;i<n-1;i++)
17+
{
18+
for(j=i+1;j<n;j++)
19+
{
20+
if(no[i]>no[j])
21+
{
22+
temp=no[i];
23+
no[i]=no[j];
24+
no[j]=temp;
25+
}
26+
}
27+
}
28+
count=0;
29+
for(i=0;i<n;i++)
30+
{
31+
if(no[i]!=a[i])
32+
{
33+
count++;
34+
break;
35+
}
36+
}
37+
if(count==0)
38+
printf("1\n");
39+
else
40+
printf("0\n");
41+
}
42+
return 0;
43+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//GeeksForGeeks Problem : Automorphic Number (Basic)
2+
//Author : By PIYUSH
3+
#include<stdio.h>
4+
int main()
5+
{
6+
int t,no,i,count;
7+
long int ans;
8+
scanf("%d",&t);
9+
while(t--)
10+
{
11+
scanf("%d",&no);
12+
ans=no*no;
13+
i=0;
14+
count=0;
15+
while(no)
16+
{
17+
i++;
18+
if((no%10) == (ans%10))
19+
{
20+
count++;
21+
22+
}
23+
else
24+
{
25+
i=-1;
26+
break;
27+
}
28+
no=no/10;
29+
ans=ans/10;
30+
31+
}
32+
if(count == i)
33+
printf("Automorphic\n");
34+
else
35+
printf("Not Automorphic\n");
36+
}
37+
return 0;
38+
}

GEEKSFORGEEKS/Geek_Average.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//GeeksForGeeks Problem: Avergae(School)
2+
//Author :PIYUSH
3+
#include<stdio.h>
4+
int main()
5+
{
6+
int t,n,a[105],i,j,sum;
7+
scanf("%d",&t);
8+
while(t--)
9+
{
10+
scanf("%d",&n);
11+
for(i=0;i<n;i++)
12+
{
13+
scanf("%d",&a[i]);
14+
}
15+
for(i=1;i<=n;i++)
16+
{
17+
sum=0;
18+
for(j=0;j<i;j++)
19+
{
20+
sum=sum+a[j];
21+
}
22+
printf("%d ",sum/i);
23+
}
24+
printf("\n");
25+
}
26+
}

GEEKSFORGEEKS/Geek_Binary_Decimal.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//GeeksForGeeks Problem : Binary Number to Decimal Number ( School)
2+
//Author : By PIYUSH
3+
#include<stdio.h>
4+
int main()
5+
{
6+
int t,no,sum,j,i;
7+
scanf("%d",&t);
8+
while(t--)
9+
{
10+
scanf("%d",&no);
11+
sum=0;
12+
i=1;
13+
while(no)
14+
{
15+
j = no % 10;
16+
sum=sum+(j*i);
17+
i = i*2;
18+
no=no/10;
19+
}
20+
printf("%d\n",sum);
21+
}
22+
return 0;
23+
}

GEEKSFORGEEKS/Geek_Binary_Represent.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//GeeksForGeeks Problem : Binary Representation (School)
2+
//Author : By PIYUSH
3+
#include<stdio.h>
4+
int main()
5+
{
6+
int t,no,bin[14],rev[15],j,k;
7+
static int i;
8+
scanf("%d",&t);
9+
while(t--)
10+
{
11+
for(i=0;i<14;i++)
12+
{
13+
bin[i]=0;
14+
}
15+
scanf("%d",&no);
16+
i=0;
17+
while(no != 1)
18+
{
19+
rev[i]=no%2;
20+
no=no/2;
21+
i++;
22+
}
23+
rev[i]=1;
24+
k=0;
25+
j=13;
26+
while(k != i)
27+
{
28+
bin[j]=rev[k];
29+
j--;
30+
k++;
31+
}
32+
for(i=0;i<14;i++)
33+
{
34+
printf("%d",bin[i]);
35+
}
36+
printf("\n");
37+
}
38+
return 0;
39+
}

GEEKSFORGEEKS/Geek_Binary_sorting.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//GeeksForGeeks Problem : Binary Array Sorting (school)
2+
//Author : By PIYUSH
3+
#include<stdio.h>
4+
int main()
5+
{
6+
int t,n,no,i,count_z,count_o;
7+
scanf("%d",&t);
8+
while(t--)
9+
{
10+
count_z=0;
11+
count_o=0;
12+
scanf("%d",&n);
13+
for(i=1;i<=n;i++)
14+
{
15+
scanf("%d",&no);
16+
if(no==0)
17+
count_z++;
18+
else
19+
count_o++;
20+
}
21+
while(count_z)
22+
{
23+
printf("0 ");
24+
count_z--;
25+
}
26+
while(count_o)
27+
{
28+
printf("1 ");
29+
count_o--;
30+
}
31+
printf("\n");
32+
}
33+
return 0;
34+
}

0 commit comments

Comments
 (0)