Created
August 15, 2023 04:50
-
-
Save vtvh/0789fd126a36aae9f22dab2eff71bd67 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// De Thi 1 | |
// 15.08.2023 | |
#include <stdio.h> | |
#include <stdlib.h> | |
#define MAX 20 | |
struct CannedMilk | |
{ | |
char label[30]; | |
int weight; | |
int price; | |
}; | |
struct CannedMilk cm[MAX]; | |
void inputCannedMilk(struct CannedMilk cm[MAX], int numberOfCannedMilk); | |
void outputCannedMilk(struct CannedMilk cm[MAX]); | |
void doQuestionR1() | |
{ | |
int n, evenDivisor = 0; | |
printf("Input an integer k: "); | |
scanf("%d", &n); | |
printf("All the devisors of k:"); | |
for (int i = 1; i <= n; i++) | |
{ | |
if (n % i == 0) | |
{ | |
if (i % 2 == 0) | |
evenDivisor++; | |
printf("%d ", i); | |
} | |
} | |
printf("\n Number of even divisors: %d \n", evenDivisor); | |
return; | |
} | |
void doQuestionR2() | |
{ | |
int numberOfCannedMilks; | |
printf("Please enter Number of Canned Milk: "); | |
scanf("%d", &numberOfCannedMilks); | |
inputCannedMilk(cm, numberOfCannedMilks); | |
outputCannedMilk(cm); | |
return; | |
} | |
void inputCannedMilk(struct CannedMilk cm[], int numberOfCannedMilk) | |
{ | |
for (int i = 0; i < numberOfCannedMilk; i++) | |
{ | |
printf("Input for canned milk %d: \n", i + 1); | |
printf("\t Label: "); | |
scanf("%s", cm[i].label); | |
printf("\t Weight: "); | |
scanf("%d", &cm[i].weight); | |
printf("\t Price: "); | |
scanf("%d", &cm[i].price); | |
printf("\n"); | |
} | |
} | |
void outputCannedMilk(struct CannedMilk cm[MAX]) | |
{ | |
puts("------------------------------"); | |
puts("Displaying the cans which have the weight from 100 to 400:"); | |
for (int i = 0; i < MAX; i++) | |
{ | |
if (cm[i].weight >= 100 && cm[i].weight <= 400) | |
{ | |
printf("\t Label: %s \n", cm[i].label); | |
printf("\t Weight: %d \n", cm[i].weight); | |
printf("\t Price: %d \n\n", cm[i].price); | |
} | |
} | |
puts("-END OF R2-"); | |
} | |
void doQuestionR3() | |
{ | |
puts("Exit program...."); | |
exit(0); | |
} | |
void menu() | |
{ | |
puts("*********************************"); | |
puts("* Select Action: "); | |
puts("* \t 1. R1"); | |
puts("* \t 2. R2"); | |
puts("* \t 3. R3"); | |
puts("*********************************"); | |
} | |
int main() | |
{ | |
int choice; | |
do | |
{ | |
menu(); | |
printf("Option: "); | |
scanf("%d", &choice); | |
// clear screen | |
printf("\033[H\033[2J"); | |
// Choice into programs: | |
switch (choice) | |
{ | |
case 1: | |
doQuestionR1(); | |
break; | |
case 2: | |
doQuestionR2(); | |
break; | |
case 3: | |
doQuestionR3(); | |
break; | |
default: | |
// clear screen | |
printf("\033[H\033[2J"); | |
puts("\n\t INVALID! Please choose from 1 2 or 3."); | |
continue; | |
} | |
} while (1); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment