0% found this document useful (0 votes)
10 views

Contest Code

contest diu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Contest Code

contest diu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Here's the C code to solve the fruit basket problem:

#include <stdio.h>

int main() {
int alpha_q_fruits, beta_q_fruits;

// Get the number of fruits in each basket from the user


printf("Enter the number of fruits in Alpha-q: ");
scanf("%d", &alpha_q_fruits);
printf("Enter the number of fruits in Beta-q: ");
scanf("%d", &beta_q_fruits);

// Calculate the total number of fruits


int total_fruits = alpha_q_fruits + beta_q_fruits;

// Calculate the product of fruits in each basket


int product_fruits = alpha_q_fruits * beta_q_fruits;

// Print the results


printf("Total number of fruits: %d\n", total_fruits);
printf("Product of fruits in each basket: %d\n", product_fruits);

return 0;
}

#include <stdio.h>

int main() {
int num_bananas;

// Get the number of bananas from the user


printf("Enter the number of bananas Luffy has: ");
scanf("%d", &num_bananas);

// Determine the number of Picchi bandors based on bananas


int num_picchi;
if (num_bananas < 5) {
num_picchi = 0;
} else if (num_bananas < 15) {
num_picchi = 1;
} else if (num_bananas < 30) {
num_picchi = 2;
} else {
num_picchi = 3;
}

// Print the result


printf("Luffy can recruit %d Picchi bandors to his team.\n", num_picchi);

return 0;
}
#include <stdio.h>

int main() {
int tastiness, weight;

// Get the tastiness factor and weight of the banana from the user
printf("Enter the tastiness factor of the banana (between -10 and 10): ");
scanf("%d", &tastiness);
printf("Enter the weight of the banana (between 0 and 100 grams): ");
scanf("%d", &weight);

// Check if Bandor will eat the bananas


if (tastiness > 2000) {
printf("Bandor, these bananas are tasty enough.\n");
} else if (tastiness > 0 && weight > 100) {
printf("Bandor, these bananas are tasty enough.\n");
} else {
printf("No Bandor, bananas are not tasty enough.\n");
}

return 0;
}

#include <stdio.h>

int main() {

int luffy_stamina, zoro_stamina, distance;

// Get the stamina levels of Luffy and Zoro from the user

printf("Enter Luffy's stamina level (between 1 and 100): ");

scanf("%d", &luffy_stamina);

printf("Enter Zoro's stamina level (between 1 and 100): ");

scanf("%d", &zoro_stamina);

printf("Enter the total distance of the race (in meters): ");

scanf("%d", &distance);

// Determine the winner based on stamina

int luffy_distance = luffy_stamina * 4; // Luffy covers 4 meters per stamina point


int zoro_distance = zoro_stamina * 6; // Zoro covers 6 meters per stamina point

char *winner;

if (luffy_distance > distance) {

winner = "Luffy";

} else if (zoro_distance > distance) {

winner = "Zoro";

} else {

winner = "It's a tie!"; // If both reach the same distance or exceed it

// Calculate the total distance traveled (whichever reaches first or both if tied)

int total_traveled_distance = luffy_distance > zoro_distance ? zoro_distance : luffy_distance;

if (total_traveled_distance > distance) {

total_traveled_distance = distance;

// Print the results

printf("The winner is %s!\n", winner);

printf("Total distance traveled: %d meters\n", total_traveled_distance);

return 0;

}
Old

#include <stdio.h>

int main() {

int X, P;

scanf("%d %d", &X, &P);

int problems[X];

for (int i = 0; i < X; i++) {

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

// Check if the problem brought by Ahalla Habibi Sahab matches any trained secret officials

int found = 0;

for (int i = 0; i < X; i++) {

if (problems[i] == P) {

found = 1;

break;

// Print the result

if (found) {

printf("Senti Aunti Ramva will never be mine\n");

} else {

printf("Senti Aunti Ramva is mine\n");

return 0;}
#include <stdio.h>

void analyze_exam_scores(int students[][2], int num_students, int threshold) {

// Allocate memory for storing sorted scores (optional for efficiency)

int sorted_scores[num_students][2];

// Copy student data to avoid modifying original array

for (int i = 0; i < num_students; i++) {

sorted_scores[i][0] = students[i][0];

sorted_scores[i][1] = students[i][1];

// Sort students by score in ascending order using bubble sort

for (int i = 0; i < num_students - 1; i++) {

for (int j = 0; j < num_students - i - 1; j++) {

if (sorted_scores[j][1] > sorted_scores[j + 1][1]) {

int temp_id = sorted_scores[j][0];

int temp_score = sorted_scores[j][1];

sorted_scores[j][0] = sorted_scores[j + 1][0];

sorted_scores[j][1] = sorted_scores[j + 1][1];

sorted_scores[j + 1][0] = temp_id;

sorted_scores[j + 1][1] = temp_score;

// Calculate the sum of the three lowest scores

int lowest_sum = 0;

for (int i = 0; i < 3; i++) {


lowest_sum += sorted_scores[i][1];

// Check if counseling support is required

if (lowest_sum < threshold) {

printf("Counseling Support Required\n");

} else {

printf("Counseling Support Not Required: Lowest Scores - ");

for (int i = 0; i < 3; i++) {

printf("%d%s", sorted_scores[i][1], (i < 2) ? ", " : "\n");

int main() {

int num_students;

printf("Enter the number of students: ");

scanf("%d", &num_students);

int students[num_students][2];

printf("Enter student ID and score (separated by space) for each student:\n");

for (int i = 0; i < num_students; i++) {

scanf("%d %d", &students[i][0], &students[i][1]);

int threshold = 150; // Adjust threshold as needed

analyze_exam_scores(students, num_students, threshold);

return 0;}

You might also like