C Programming Problems Collection
Table of Contents
Problem 1: A Fuchka Date Dilemma ........................... 2
Problem 2: And Or XOr ........................... 3
Problem 3: Back To High School Physics ........................... 4
Problem 4: Badminton Serves ........................... 5
Problem 5: Bandor Is Hungry ........................... 6
Problem 6: Black And White Cows ........................... 7
Problem 7: Buddy The Boro Bhai ........................... 8
Problem 8: Can Chief ........................... 9
Problem 9: Checking Vowel and Consonant ........................... 10
Problem 10: Compare Two Strings ........................... 11
Problem 11: Copy String ........................... 12
Problem 12: De Dour ........................... 13
Problem 13: Election Hopes ........................... 14
Problem 14: Equalizing Numbers ........................... 15
Problem 15: Find Total Alpha Nums Special Chars ........................... 16
Problem 16: Greedy Grid ........................... 17
Problem 17: Is He A Thief ........................... 18
Problem 18: Jumping Mario ........................... 19
Problem 19: Khana Pina ........................... 20
Problem 20: Leaderboard Laddu ........................... 21
Problem 21: Lowercase to Uppercase ........................... 22
Problem 22: Luffy and the One Banana ........................... 23
Problem 23: Math Eww ........................... 24
Problem 24: Missing In Array ........................... 25
Problem 25: Missing Number ........................... 27
Problem 26: Moo Mystery ........................... 28
Problem 27: Never Play Chess ........................... 29
Problem 28: Only One Digit ........................... 30
Problem 29: Point Location ........................... 31
Problem 30: Primality Test ........................... 32
Problem 31: Relational Operator ........................... 33
Problem 32: Character Frequency Counter ........................... 34
Problem 33: Six Friends ........................... 35
Problem 34: Skibidus and Amogus ........................... 36
Problem 35: Squid Game Piggy Bank ........................... 37
Problem 36: String Length ........................... 38
Problem 37: Temp Code Runner File ........................... 39
Problem 38: The Great Palindromic Platter Challenge ........................... 40
Problem 39: The Judgemental Restaurant ........................... 41
Problem 40: Triangle Waves ........................... 42
Problem 41: Uppercase to Lowercase ........................... 43
Problem 42: Weird Algorithm ........................... 44
Problem 1: A Fuchka Date Dilemma
**File:** `AFuchkaDateDilloma.c`
```c
#include <stdio.h>
int main() {
int n, t;
scanf("%d %d", &n, &t);
int a[n], b[n];
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
for (int i = 0; i < n; i++) scanf("%d", &b[i]);
int min = 1000001;
for (int i = 0; i < n; i++) {
if (b[i] >= t && a[i] < min) {
min = a[i];
}
}
if (min == 1000001)
printf("Bad Luck!\n");
else
printf("%d\n", min);
return 0;
}
```
Problem 2: And Or XOr
**File:** `AndOrXOr.c`
```c
#include <stdio.h>
int min(int a, int b) {
return a < b ? a : b;
}
int main() {
int t;
scanf("%d", &t);
while (t--) {
int a, b;
long long x, y;
scanf("%d %d %lld %lld", &a, &b, &x, &y);
if (a == b) {
printf("0\n");
continue;
}
long long cost = -1;
if (a < b) {
cost = (b - a) * x;
}
if ((a ^ 1) == b) {
if (cost == -1 || y < cost)
cost = y;
}
int ax1 = a ^ 1;
if (ax1 < b) {
long long temp = y + (b - ax1) * x;
if (cost == -1 || temp < cost)
cost = temp;
}
int ax1p1 = (a ^ 1) + 1;
if ((ax1p1 ^ 1) == b) {
long long temp = y + x + y;
if (cost == -1 || temp < cost)
cost = temp;
}
printf("%lld\n", cost);
}
return 0;
}
```
Problem 3: Back To High School Physics
**File:** `BackToHighSchoolPhysics.c`
```c
#include <stdio.h>
int main() {
int v, t;
while (scanf("%d %d", &v, &t) == 2) {
printf("%d\n", 2 * v * t);
}
return 0;
}
```
Problem 4: Badminton Serves
**File:** `BadmintonServes.c`
```c
#include <stdio.h>
int main()
{
int t;
scanf("%d", &t);
for (int i = 0; i < t; i++)
{
int p;
scanf("%d", &p);
printf("%d\n", (p / 2) + 1);
}
return 0;
}
```
Problem 5: Bandor Is Hungry
**File:** `BandorIsHungry.c`
```c
#include <stdio.h>
int main()
{
int T, W;
scanf("%d %d", &T, &W);
if (T > 2000)
printf("Bandor, these bananas are tasty enough.\n");
else if (T > 0 && T <= 2000 && W > 100)
printf("Bandor, these bananas are tasty enough.\n");
else
printf("No Bandor, bananas are not tasty enough.\n");
return 0;
}
```
Problem 6: Black And White Cows
**File:** `BlackAndWhiteCows.c`
```c
#include <stdio.h>
int main() {
int N, X;
scanf("%d %d", &N, &X);
int cows[10];
for (int i = 0; i < 10; i++) {
scanf("%d", &cows[i]);
}
int totalMoney = N;
int whiteBought = 0;
for (int i = 0; i < 10; i++) {
int price = i + 1;
if (cows[i] == 0 && totalMoney >= price) {
whiteBought++;
totalMoney -= price;
}
}
if (whiteBought >= X) {
printf("Amago Genday Happy Go!\n");
} else {
printf("Genda Kandis na\n");
}
return 0;
}
```
Problem 7: Buddy The Boro Bhai
**File:** `BuddyTheBoroBhai.c`
```c
#include <stdio.h>
int main()
{
int n;
scanf("%d", &n);
if (n >= 200)
printf("Biryani Burhan\n");
else if (n == 0)
printf("Panta Pasha\n");
else
printf("Fuchka Feroze\n");
return 0;
}
```
Problem 8: Can Chief
**File:** `CanChief.c`
```c
#include <stdio.h>
int main()
{
int x, y;
int t;
scanf("%d", &t);
for (int i = 0; i < t; i++)
{
scanf("%d %d", &x, &y);
int petrol = x * 15;
int distance = 2 * y;
if (petrol >= distance)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
```
Problem 9: Checking Vowel and Consonant
**File:** `Checkingvowelandconsonant.c`
```c
#include <stdio.h>
#include <string.h>
int main()
{
char str[100];
int vowel = 0, consonant = 0;
printf("Enter a string:");
gets(str);
for (int i = 0; str[i] != '\0'; i++)
{
if (str[i] == 'a' || str[i] == 'e' || str[i] == 'i' || str[i] == 'o' || str[i] == 'u' ||
str[i] == 'A' || str[i] == 'E' || str[i] == 'I' || str[i] == 'O' || str[i] == 'U')
vowel++;
else
consonant++;
}
printf("Vowel = %d\n", vowel);
printf("Consonant = %d\n", consonant);
return 0;
}
```
Problem 10: Compare Two Strings
**File:** `comparetwostrings.c`
```c
#include <stdio.h>
#include <string.h>
int main()
{
char str1[100], str2[100];
int i, result = 1;
printf("Enter first string: ");
gets(str1);
printf("Enter second string: ");
gets(str2);
for (i = 0; str1[i] != '\0' || str2[i] != '\0'; i++)
{
if (str1[i] != str2[i])
{
result = 0;
break;
}
}
if (result == 1)
printf("strings are equal.\n");
else
printf("strings are not equal\n");
return 0;
}
```
Problem 11: Copy String
**File:** `CopyString.c`
```c
#include <stdio.h>
int main()
{
char src[100], dest[100]; //here dest is destination & src is source.
int i;
printf("Enter a string to copy: ");
gets(src);
for (i = 0; src[i] != '\0'; i++)
{
dest[i] = src[i];
}
dest[i] = '\0';
printf("Copied string: %s\n", dest);
return 0;
}
```
Problem 12: De Dour
**File:** `DeDour.c`
```c
#include<stdio.h>
int main()
{
int D,T,S;
scanf("%d %d",&D,&T);
S=D/T;
printf("%d\n",S);
return 0;
}
```
Problem 13: Election Hopes
**File:** `Electionhopes.c`
```c
#include <stdio.h>
int main()
{
int x, y;
scanf("%d %d", &x, &y);
if (x / y == 2)
printf("Yes\n");
else
printf("No\n");
return 0;
}
```
Problem 14: Equalizing Numbers
**File:** `equalizingnumbers.c`
```c
#include <stdio.h>
int main()
{
int t, a, b;
scanf("%d", &t);
for (int i = 0; i < t; i++)
{
scanf("%d %d", &a, &b);
if ((a - b) % 2 == 0)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
```
Problem 15: Find Total Alpha Nums Special Chars
**File:** `Findtotalalphanumsc.c`
```c
#include <stdio.h>
#include <string.h>
int main()
{
char str[100];
int alphabet = 0, number = 0, specialchars = 0;
printf("Enter a string:");
gets(str);
for (int i = 0; str[i] != '\0'; i++)
{
if ((str[i] >= 'a' && str[i] <= 'z' || str[i] >= 'A' && str[i] <= 'Z'))
alphabet++;
else if (str[i] >= '0' && str[i] <= '9')
number++;
else
specialchars++;
}
printf("Alphabets: %d\n", alphabet);
printf("Digits: %d\n", number);
printf("Special Characters: %d\n", specialchars);
return 0;
}
```
Problem 16: Greedy Grid
**File:** `GreedyGrid.c`
```c
#include <stdio.h>
int main() {
int t, n, m;
scanf("%d", &t);
while (t--) {
scanf("%d %d", &n, &m);
if (n > 1 && m > 1)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
```
Problem 17: Is He A Thief
**File:** `IsHeathief.c`
```c
#include<stdio.h>
int main()
{
int X,Y;
int H,M;
scanf("%d %d",&X,&Y);
scanf("%d %d",&H,&M);
if(H>=X && M>=Y)
printf("He is the thief!\n");
else
printf("He is innocent!\n");
return 0;
}
```
Problem 18: Jumping Mario
**File:** `JumpingMario.c`
```c
#include <stdio.h>
int main() {
int T, N, i, j, high, low;
scanf("%d", &T);
for (i = 1; i <= T; i++) {
scanf("%d", &N);
int walls[N];
for (j = 0; j < N; j++) {
scanf("%d", &walls[j]);
}
high = 0;
low = 0;
for (j = 1; j < N; j++) {
if (walls[j] > walls[j - 1]) {
high++;
} else if (walls[j] < walls[j - 1]) {
low++;
}
}
printf("Case %d: %d %d\n", i, high, low);
}
return 0;
}
```
Problem 19: Khana Pina
**File:** `Khanapina.c`
```c
#include <stdio.h>
int main()
{
int a, b;
scanf("%d %d", &a, &b);
int sum = (a * 100) + (b * 50);
printf("%d", sum);
return 0;
}
```
Problem 20: Leaderboard Laddu
**File:** `LeaderboardLaddu.c`
```c
#include <stdio.h>
int main()
{
int N;
scanf("%d", &N);
int a[N];
for (int i = 0; i < N; i++)
{
scanf("%d", &a[i]);
}
int max = a[0], min = a[0], diff = 0;
for (int i = 0; i < N; i++)
{
if (a[i] > max)
max = a[i];
if (a[i] < min)
min = a[i];
}
diff = max - min;
printf("%d", diff);
return 0;
}
```
Problem 21: Lowercase to Uppercase
**File:** `lowercasetouppercase.c`
```c
#include <stdio.h>
#include <string.h>
int main()
{
char str[100];
printf("Enter a string: ");
gets(str);
for (int i = 0; str[i] != '\0'; i++)
{
if (str[i] >= 'a' && str[i] <= 'z')
str[i] = str[i] - 32;
}
printf("Uppercase string: %s\n", str);
return 0;
}
```
Problem 22: Luffy and the One Banana
**File:** `Luffy_and_the_One_Banana.c`
```c
#include <stdio.h>
int main()
{
int B;
scanf("%d", &B);
int bandor = 0;
if (B >= 30)
{
bandor = 3;
}
else if (B >= 15)
{
bandor = 2;
}
else if (B >= 5)
{
bandor = 1;
}
printf("%d\n",bandor);
return 0;
}
```
Problem 23: Math Eww
**File:** `MathEww.c`
```c
#include <stdio.h>
int main()
{
int A, B;
long long X, Y;
scanf("%d %d", &A, &B);
X = (long long)A + B;
Y = (long long)A * B;
printf("%lld %lld\n", X, Y);
return 0;
}
```
Problem 24: Missing In Array
**File:** `MissingInArray.c`
```c
#include <stdio.h>
int findMissing(int arr[], int n) {
int total = (n + 1) * (n + 2) / 2;
for (int i = 0; i < n; i++) {
total -= arr[i];
}
return total;
}
int main() {
int arr[] = {1, 2, 3, 5};
int n = sizeof(arr)/sizeof(arr[0]);
printf("Missing number is: %d\n", findMissing(arr, n));
return 0;
}
```
Problem 25: Missing Number
**File:** `MissingNumber.c`
```c
#include <stdio.h>
int main() {
int n, x;
long long total = 0, sum = 0;
scanf("%d", &n);
total = (long long)n * (n + 1) / 2;
for (int i = 0; i < n - 1; i++) {
scanf("%d", &x);
sum += x;
}
printf("%lld\n", total - sum);
return 0;
}
```
Problem 26: Moo Mystery
**File:** `MooMistery.c`
```c
#include<stdio.h>
int main()
{
int M;
scanf("%d",&M);
if(M>=20)
printf("Healthy\n");
else if(M<=10)
printf("Infected\n");
else
printf("Need Checkup\n");
return 0;
}
```
Problem 27: Never Play Chess
**File:** `NeverPlayChess.c`
```c
#include <stdio.h>
#include <math.h>
int main() {
int t;
scanf("%d", &t);
while (t--) {
long long n;
scanf("%lld", &n);
long long rows = (long long)( (-1 + sqrt(1 + 8.0 * n)) / 2 );
printf("%lld\n", rows);
}
return 0;
}
```
Problem 28: Only One Digit
**File:** `OnlyOneDigi.c`
```c
#include <stdio.h>
#include <string.h>
int has_common_digit(int x, int y)
{
int digits_x[10] = {0};
int temp = x;
while (temp > 0)
{
digits_x[temp % 10] = 1;
temp /= 10;
}
temp = y;
if (y == 0 && digits_x[0])
return 1;
while (temp > 0)
{
if (digits_x[temp % 10])
return 1;
temp /= 10;
}
return 0;
}
int main()
{
int t, x;
scanf("%d", &t);
while (t--)
{
scanf("%d", &x);
for (int y = 0;; y++)
{
if (has_common_digit(x, y))
{
printf("%d\n", y);
break;
}
}
}
return 0;
}
```
Problem 29: Point Location
**File:** `PointLocation.c`
```c
#include <stdio.h>
int main() {
int t;
scanf("%d", &t);
while (t--) {
long long x1, y1, x2, y2, x3, y3;
scanf("%lld%lld%lld%lld%lld%lld", &x1, &y1, &x2, &y2, &x3, &y3);
long long cross = (x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1);
if (cross > 0)
printf("LEFT\n");
else if (cross < 0)
printf("RIGHT\n");
else
printf("TOUCH\n");
}
return 0;
}
```
Problem 30: Primality Test
**File:** `Primalitytest.c`
```c
#include <stdio.h>
int isPrime(int n)
{
if (n == 1)
return 0;
for (int i = 2; i < n; i++)
{
if (n % i == 0)
return 0;
}
return 1;
}
int main()
{
int t, n;
scanf("%d", &t);
for (int i = 0; i < t; i++)
{
scanf("%d", &n);
if (isPrime(n))
printf("yes\n");
else
printf("no\n");
}
return 0;
}
```
Problem 31: Relational Operator
**File:** `RelationalOperator.c`
```c
#include <stdio.h>
int main() {
int t;
scanf("%d", &t);
while (t--) {
int a, b;
scanf("%d %d", &a, &b);
if (a > b)
printf(">\n");
else if (a < b)
printf("<\n");
else
printf("=\n");
}
return 0;
}
```
Problem 32: Character Frequency Counter
**File:** `s.c`
```c
#include <stdio.h>
int main() {
char str[100];
int freq[256] = {0}, i;
gets(str);
for (i = 0; str[i] != '\0'; i++)
freq[(unsigned char)str[i]]++;
for (i = 0; i < 256; i++)
if (freq[i] > 0)
printf("%c = %d\n", i, freq[i]);
return 0;
}
```
Problem 33: Six Friends
**File:** `SixFriends.c`
```c
#include <stdio.h>
int main()
{
int T;
scanf("%d", &T);
for (int i = 0; i < T; i++)
{
int X, Y;
scanf("%d %d", &X, &Y);
int doubler = 3 * X;
int triple = 2 * Y;
if (doubler < triple)
printf("%d\n", doubler);
else
printf("%d\n", triple);
}
return 0;
}
```
Problem 34: Skibidus and Amogus
**File:** `skibidusandamogus.c`
```c
#include <stdio.h>
int main()
{
int t;
scanf("%d", &t);
getchar();
for (int i = 0; i < t; i++)
{
char str[100];
gets(str);
for (int j = 0; str[j + 2] != '\0'; j++)
{
printf("%c", str[j]);
}
printf("i\n");
}
return 0;
}
```
Problem 35: Squid Game Piggy Bank
**File:** `squidgamepiggybank.c`
```c
#include<stdio.h>
int main()
{
int n,k;
scanf("%d %d",&n,&k);
int total=(n-k)*10000;
printf("%d\n",total);
return 0;
}
```
Problem 36: String Length
**File:** `StringLength.c`
```c
#include <stdio.h>
#include <string.h>
int main()
{
char name[100];
printf("Enter a String: ");
gets(name);
int i, len = 0;
for (i = 0; name[i] != '\0'; i++)
{
len++;
}
printf("Length of the string is: %d\n", len);
return 0;
}
```
Problem 37: Temp Code Runner File
**File:** `tempCodeRunnerFile.c`
```c
#include<stdio.h>
int main()
{
int X,Y,H,M;
scanf("%d %d %d %d",&X,&Y,&H,&M);
if(X>=H && M>=Y)
printf("He is the thief!\n");
else
printf("He is innocent!\n");
return 0;
}
```
Problem 38: The Great Palindromic Platter Challenge
**File:** `TheGreatPalindromicPlatterChallenge.c`
```c
#include <stdio.h>
#include <string.h>
int is_palindrome_possible(int count[26]) {
int odd_count = 0;
for (int i = 0; i < 26; i++) {
if (count[i] % 2 != 0) {
odd_count++;
}
}
return odd_count <= 1;
}
int count_palindromic_substrings(char s[]) {
int len = strlen(s);
int total = 0;
for (int i = 0; i < len; i++) {
int count[26] = {0};
for (int j = i; j < len; j++) {
count[s[j] - 'a']++;
if (is_palindrome_possible(count)) {
total++;
}
}
}
return total;
}
int main() {
int T;
char s[5005];
scanf("%d", &T);
while (T--) {
scanf("%s", s);
printf("%d\n", count_palindromic_substrings(s));
}
return 0;
}
```
Problem 39: The Judgemental Restaurant
**File:** `TheJudgementalResturant.c`
```c
#include <stdio.h>
int main()
{
int w, m;
scanf("%d %d", &w, &m);
if (w > 100)
{
if (m >= 500)
printf("Fruits\n");
else
printf("Salad\n");
}
else
{
if (m >= 500)
printf("Biriyani\n");
else
printf("Khichuri\n");
}
return 0;
}
```
Problem 40: Triangle Waves
**File:** `TriangleWaves.c`
```c
#include <stdio.h>
int main()
{
int t;
scanf("%d", &t);
while (t--)
{
int amp, freq;
int f, i, j;
scanf("%d", &);
scanf("%d", &freq);
for (f = 0; f < freq; f++)
{
for (i = 1; i <= amp; i++)
{
for (j = 0; j < i; j++)
printf("%d", i);
printf("\n");
}
for (i = amp - 1; i >= 1; i--)
{
for (j = 0; j < i; j++)
printf("%d", i);
printf("\n");
}
if (f < freq - 1)
printf("\n");
}
if (t)
printf("\n");
}
return 0;
}
```
Problem 41: Uppercase to Lowercase
**File:** `uppercasetolowercase.c`
```c
#include <stdio.h>
#include <string.h>
int main()
{
char str[100];
printf("Enter a string: ");
gets(str);
for (int i = 0; str[i] != '\0'; i++)
{
if (str[i] >= 'A' && str[i] <= 'Z')
str[i] = str[i] + 32;
}
printf("Lowercase string: %s\n", str);
return 0;
}
```
Problem 42: Weird Algorithm
**File:** `WeirdAlgorythm.c`
```c
#include <stdio.h>
int main() {
long long n;
scanf("%lld", &n);
while (n != 1) {
printf("%lld ", n);
if (n % 2 == 0)
n /= 2;
else
n = n * 3 + 1;
}
printf("1\n");
return 0;
}
```