Language using with: C
- Datatype resource
- BASIC OF VARIABLE & CONSTANT resource
- OPERATOR resource
- TYPECASTING resource
- LIBRARY-FUNCTION resource
- RELATIONAL AND- LOGICAL OPERATORS resource
- IF-ELSE STATEMENT resource
- TYPE-CASTING resource
- POST & PRE-INCREMENT resource
- TERNARY-OPERATOR resource
- PATTERN PRINTING resource Youtube
- BASIC DATATYPES{*char} class
- SWITCH-CONTINUE- GOTO-DO.WHILE class
- ARRAY class:1D class:2D Youtube
- STRING Youtube class:2D
- FUNCTION resource
- RECURSSION class:1 class:2
Try to solve this problem using with Loop:
219432Y-Easy Fibonacci
Code
#include<stdio.h>
int main()
{
int a=0, b=1, c, i, n;
scanf("%d", &n);
if(n == 1)
printf("%d", a);
else
printf("%d %d", a, b);
for(i=1; i<=n-2; i++)
{
c = a + b;
printf(" %d", c);
a = b;
b = c;
}
printf("\n");
return 0;
}
219432J-Primes from 1 to n
Code
#include<stdio.h>
int main()
{
int i, n, x, f, j;
scanf("%d", &n);
i = 1;
while(i <= n)
{
f = 0;
x = i;
for(j=2; j<x; j++)
{
if(x%j == 0)
{
f++;
}
}
if(f == 0 && x != 1)
{
printf("%d ", x);
}
i++;
}
return 0;
}
219432G-Factorial
Code
#include<stdio.h>
int main()
{
long long int n, i, j, x, fact;
scanf("%lld", &n);
i=1;
while(i<=n)
{
scanf("%lld", &x);
fact = 1;
for(j=1; j<=x; j++)
{
fact *= j;
}
printf("%lld\n", fact);
i++;
}
return 0;
}
219432I-Palindrome
Code
#include<stdio.h>
int main()
{
int n, r, s=0, x;
scanf("%d", &n);
x = n;
while(x>0)
{
r = x % 10;
s = s*10+r;
x /= 10;
}
if(n == s)
{
printf("%d\n", s);
printf("YES");
}
else
{
printf("%d\n", s);
printf("NO");
}
return 0;
}
219432L-GCD
Code
#include<stdio.h>
int main()
{
int i, n, x, a, b, c=0;
scanf("%d%d", &a, &b);
i=1;
while(i<=a && i<=b)
{
if(a%i==0 && b%i==0)
{
c = i;
}
i++;
}
printf("%d", c);
return 0;
}
---------------------------------------------------------------
Try to solve this proble using with Array:
219774D-Positions in array
Code
#include<stdio.h>
int main()
{
int n, i, x, r, f, m, j, pos;
int arr[100010];
scanf("%d", &n);
for(i=0; i<=n-1; i++)
{
scanf("%d", &arr[i]);
}
pos=0;
for(i=0; i<=n-1; i++)
{
while(arr[i] <= 10)
{
pos=arr[i];
printf("A[%d] = %d\n", i, arr[i]);
break;
}
}
return 0;
}
219774E-Lowest Number
Code
#include<stdio.h>
int main()
{
int n, i, x, min, pos=0;
int arr[100010];
scanf("%d", &n);
for(i=1; i<=n; i++)
{
scanf("%d", &arr[i]);
}
for(i=1; i<=n; i++)
{
if(arr[i] < min)
{
min = arr[i];
pos=i;
}
}
printf("%d %d", min, pos);
return 0;
}
219774F-Reversing
Code
#include<stdio.h>
int main()
{
int n, i, x;
int arr[100010];
scanf("%d", &n);
i=1;
while(i<=n)
{
scanf("%d", &arr[i]);
i++;
}
for(i=n; i>=1; i--)
{
printf("%d ", arr[i]);
}
return 0;
}
219774H-Sorting
Code
#include<stdio.h>
int main()
{
int n, i, x;
int arr[100010];
scanf("%d", &n);
i=1;
while(i<=n)
{
scanf("%d", &arr[i]);
i++;
}
for(i=n; i>=1; i--)
{
printf("%d ", arr[i]);
}
return 0;
}
219774L-Max Subarray
Code
#include<stdio.h>
int main()
{
int n, i, x, j, a[10001], t, mx;
scanf("%d", &t);
while(t--)
{
scanf("%d", &n);
for(i=0; i<n; i++)
{
scanf("%d", &a[i]);
}
for(i=0; i<n; i++)
{
mx=-100001;
for(j=i; j<n; j++)
{
if(a[j] > mx)
{
mx=a[j];
}
printf("%d ", mx);
}
}
printf("\n");
}
return 0;
}
219774M-Replace MinMax
Code
#include<stdio.h>
int main()
{
int n, i, j, min, max, temp;
scanf("%d", &n);
int arr[100010];
for(i=1; i<=n; i++)
{
scanf("%d", &arr[i]);
}
min=arr[1], max=arr[1];
for(i=1; i<=n; i++)
{
if(arr[i] < min)
{
min = arr[i];
}
if(arr[i] > max)
{
max = arr[i];
}
}
for(i=1; i<=n; i++)
{
if(arr[i]==min){
printf("%d ", max);
}else if(arr[i]==max){
printf("%d ", min);
}else{
printf("%d ", arr[i]);}
}
return 0;
}
219774S-Search In Matrix
Code
#include<stdio.h>
int main()
{
int n, i, j, a[101][101], b[101][101], p, r, c, f;
scanf("%d%d", &r, &c);
for(i=1; i<=r; i++)
for(j=1; j<=c; j++)
scanf("%d", &a[i][j]);
f=0;
scanf("%d", &p);
for(i=1; i<=r; i++)
{
for(j=1; j<=c; j++)
{
if(a[i][j] == p)
{
f=1;
//break;
}
}
}
if(f==1)
{
printf("will not take number");
}
else
{
printf("will take number");
}
return 0;
}
219774V-Frequency Array
Code
#include<stdio.h>
int main()
{
int arr[100001], i,j,x, m, n, cnt, freq[100001]={0}, val;
scanf("%d%d", &n, &m);
for(i=0; i<n; i++)
{
scanf("%d", &arr[i]);
}
for(i=0; i<n; i++)
{
//arr[i]=10
val=arr[i];
freq[val]++;
}
for(i=1; i<=m; i++)
{
printf("%d\n", freq[i]);
}
return 0;
}
219774Z-Binary Search
Code
~~~~~
~~~~~
--------------------------------------------------------------------
Try to solve this proble using with String:
219856C-Compare
Code
#include<bits/stdc++.h>
using namespace std;
int main()
{
int i, j, mn;
string x, y;
cin>>x>>y;
if(x < y)
cout<<x;
else
cout<<y;
return 0;
}
219856F-Way Too Long Words
Code
#include<stdio.h>
#include<string.h>
int main()
{
int i, n, len, x;
scanf("%d", &n);
char a[1000001];
for(i=0; i<n; i++)
{
scanf("%s", a);
x=strlen(a);
if(x <= 10)
{
printf("%s\n", a);
}
else
{
printf("%c%d%c\n", a[0],x-2,a[x-1]);
}
}
return 0;
}
219856H-Good or Bad
Code
#include<stdio.h>
#include<string.h>
int main()
{
int n,i,j,x,t,f;
scanf("%d", &n);
char str[100001];
for(i=0; i<n; i++)
{
scanf("%s",str);
f=0;
for(j=0; j<strlen(str)-2; j++)
{
if(str[j]=='0' && str[j+1]=='1' && str[j+2]=='0' || str[j]=='1' && str[j+1]=='0' && str[j+2]=='1')
{
f=1;
break;
}
}
if(f==1)
printf("Good\n");
else
printf("Bad\n");
}
return 0;
}
219856J-Count Letters
Code
#include<stdio.h>
#include<string.h>
int main()
{
char str[10000001];
int i, hi[2000]={0};
scanf("%s", str);
for(i=0; str[i]!='\0'; i++)
{
hi[ str[i]]++;
}
for(i = 'a'; i <= 'z'; i++)
{
if(hi[i] > 0)
{
printf("%c : %d\n", i, hi[i]);
}
}
return 0;
}
219856K-I Love strings
Code
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
void call()
{
int i,j,k;
char s[100];
char s1[100];
scanf("%s%s", s, s1);
if(strlen(s) < strlen(s1))
{
j = strlen(s);
k = strlen(s1);
}
else
{
j = strlen(s1);
k = strlen(s);
}
for(i=0; i < j; i++)
{
printf("%c", s[i]);
printf("%c", s1[i]);
}
for(i = j; i < k; i++)
{
if(strlen(s) < strlen(s1))
{
printf("%c", s1[i]);
}
else printf("%c", s[i]);
}
}
int main()
{
int t, k;
scanf("%d", &t);
for(k=1; k<=t; k++)
{
call();
printf("\n");;
}
return 0;
}
219856L-String Functions
Code
~~~~~
~~~~~
219856O-Sort String
Code
#include<stdio.h>
#include<string.h>
int main()
{
int n,i,j,k,a[10001]={0};
scanf("%d ", &n);
char x;
for(i=0; i<n; i++)
{
scanf("%c", &x);
a[x]+=1;
}
for(i='a'; i<='z'; i++)
{
if(a[i]>0)
{
for(j=1; j<=a[i]; j++)
{
printf("%c", i);
}
}
}
return 0;
}
219856R-String Score
Code
~~~~~
~~~~~
--------------------------------------------------------------------
Try to solve this proble using with Function:
223205D-Prime Function
Code
#include<stdio.h>
#include<math.h>
int isprime(int n)
{
int i,f=0,x;
if(n==1)
return 1;
x=sqrt(n);
for(i=2; i<=x; i++)
{
if(n%i==0)
{
f=1;
break;
}
}
return f;
}
int main()
{
int a, x;
scanf("%d", &a);
while(a--)
{
scanf("%d", &x);
if(isprime(x)==1)
printf("NO\n");
else
printf("YES\n");
}
return 0;
}
22320E-Swap
Code
#include<stdio.h>
void reverse(int a, int b)
{
int temp=0;
temp=a;
a=b;
b=temp;
printf("%d %d\n", a, b);
}
int main()
{
int a, b, p;
scanf("%d%d", &a, &b);
reverse(a, b);
return 0;
}
22320G-Max and MIN
Code
#include<stdio.h>
int mn(int arr[], int n)
{
int i, y, mn=100001;
for(i=1; i<=n; i++)
{
if(arr[i] < mn)
{
mn=arr[i];
}
}
return mn;
}
int mx(int arr[], int n)
{
int i, x, mx=-1;
for(i=1; i<=n; i++)
{
if(arr[i] > mx)
{
mx=arr[i];
}
}
return mx;
}
int main()
{
int arr[100001], i, MIN, MAX, n, m, j;
scanf("%d", &n);
for(i=1; i<=n; i++)
{
scanf("%d", &arr[i]);
}
MIN=mn(arr,n);
MAX=mx(arr,n);
printf("%d %d\n",MIN, MAX);
return 0;
}
22320K-Shift Right
Code
#include <iostream>
using namespace std;
void change(int arr[], int n, int k, int ans[])
{
for(int i=0; i<n; i++)
{
int tmp = (i+k)%n;
ans[tmp]=arr[i];
}
return;
}
int main()
{
int n, k, i;
cin >> n >> k;
int arr[n], ans[n];
for(i=0; i<n; i++)
cin >> arr[i];
change(arr, n, k, ans);
for(i=0; i<n; i++)
cout << ans[i] << " ";
}