Tyl Programs
Tyl Programs
1.An automobile company manufactures both a two wheeler (TW) and a four wheeler
(FW). A company manager wants to make the production of both types of vehicle
according to the given data below:
● 1st data, Total number of vehicle (two-wheeler + four-wheeler)=v
● 2nd data, Total number of wheels = W
Example :
Input :
200 -> Value of V
540 -> Value of W
Output :
TW =130 FW=70
Explanation:
130+70 = 200 vehicles
(70*4)+(130*2)= 540 wheels
Constraints :
● 2<=W
● W%2=0
● V<W
Print “INVALID INPUT” , if inputs did not meet the constraints.
The input format for testing :
The candidate has to write the code to accept two positive numbers separated by a new
line.
● First Input line – Accept value of V.
● Second Input line- Accept value for W.
#include<stdio.h>
int main() {
int V, W;
scanf("%d", &V);
scanf("%d", &W);
if (W % 2 != 0 || V >= W) {
printf("INVALID INPUT\n");
} else {
int TW, FW;
FW = (W - (2 * V)) / 2;
TW = V - FW;
printf("TW=%d FW=%d\n", TW, FW);
}
return 0;
}
}
printf("\n");
}
return 0;
}
3.C Program for Merge Sort
#include <stdio.h>
#include <stdlib.h>
void merge(int arr[], int l, int m, int r)
{
int i, j, k;
int n1 = m - l + 1;
int n2 = r - m;
merge(arr, l, m, r);
}
}
// Driver code
int main()
{
// Define three complex type numbers
complex a, b, sum;
return 0;
}
return (add);
}
There are total n number of Monkeys sitting on the branches of a huge Tree. As
travelers offer Bananas and Peanuts, the Monkeys jump down the Tree. If every
Monkey can eat k Bananas and j Peanuts. If total m number of Bananas and p number
of Peanuts are offered by travelers, calculate how many Monkeys remain on the Tree
after some of them jumped down to eat.
At a time one Monkeys gets down and finishes eating and go to the other side of the
road. The Monkey who climbed down does not climb up again after eating until the
other Monkeys finish eating.
Monkey can either eat k Bananas or j Peanuts. If for last Monkey there are less than k
Bananas left on the ground or less than j Peanuts left on the ground, only that Monkey
can eat Bananas(<k) along with the Peanuts(<j).
Write code to take inputs as n, m, p, k, j and return the number of Monkeys left on the
Tree.
Where, n= Total no of Monkeys
k= Number of eatable Bananas by Single Monkey (Monkey that jumped down last
may get less than k Bananas)
j = Number of eatable Peanuts by single Monkey(Monkey that jumped down last
may get less than j Peanuts)
m = Total number of Bananas
p = Total number of Peanuts
Remember that the Monkeys always eat Bananas and Peanuts, so there is no
possibility of k and j having a value zero
#include <stdio.h>
int main ()
{
int n, k, j, m, p;
float atebanana = 0.0, atepeanut = 0.0;
scanf ("%d %d %d %d %d", &n, &k, &j, &m, &p);
if (n < 0 || k < 0 || j < 0 || m < 0 || p < 0)
{
printf ("INVALID INPUT");
}
else
{
if (k > 0)
{
atebanana = (float) (m / k);
m = m % k;
}
if (j > 0)
{
atepeanut = (float) (p / j);
p = p % j;
}
n = n - atebanana - atepeanut;
if ((m != 0) || (p != 0))
n = n - 1;
printf ("Number of Monkeys left on the Tree:%d", n);
}
return 0;
}
int main()
{
char str[100], result;
int i, len;
int max = 0;
int freq[256] = {0};
printf("C Program to Find Maximum Occurring Character in a String \n");
printf("Please Enter a String : ");
fgets(str, 100, stdin);
len = strlen(str);
for(i = 0; i < len; i++)
{
freq[str[i]]++;
}
for(i = 0; i < len; i++)
{
if(max <= freq[str[i]])
{
max = freq[str[i]];
result = str[i];
}
}
printf("\n Maximum Occurring Character in a String %s is '%c' %d times", str, result, max);
return 0;
}
int main()
{
//Initialize array
int arr[] = {1, 2, 3, 4, 5};
//Calculate length of array arr
int length = sizeof(arr)/sizeof(arr[0]);
//n determine the number of times an array should be rotated
int n = 3;
printf("\n");
int main() {
// declare variables
int h, m, am_pm, h1, m1;
// take input
printf("Enter the time in 12-hour format (hh:mm am/pm): ");
scanf("%d:%d %c", & h, & m, & am_pm);
return 0;
}