This commit is contained in:
k0rrluna 2025-02-06 01:55:44 +03:00
parent 0b7e3b6cb0
commit 08ec3be7a9
7 changed files with 97 additions and 0 deletions

View File

@ -0,0 +1,26 @@
#include <stdio.h>
int main(void) {
int i = 0, total = 0;
puts("Enter an integer!");
if(scanf("%d", &i)) {
for(int sum = 0; sum <= i; sum++) {
total += sum;
}
printf("Total sum: %d\n", total);
total = 0;
for(int sum = 0; sum * sum <= i * i; sum++) {
int pow = sum * sum;
total += pow;
}
printf("Sum of squares: %d\n", total);
total = 0;
for(int sum = 0; sum * sum * sum <= i * i * i; sum++) {
int pow = sum * sum * sum;
total += pow;
}
printf("Sum of cubes: %d\n", total);
} else {
puts("Enter valid integer!");
}
}

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,11 @@
#include <stdio.h>
int main(void) {
puts("Factorial 1 to 5: ");
double sum = 1;
for(double i = 1; i <= 20; i++) {
sum *= i;
printf("The %0.lf! are: %0.lf\n", i, sum);
}
return 0;
}

View File

@ -0,0 +1,11 @@
#include <stdio.h>
int main(void) {
int start = 10;
for(int i = 1; i <= start; i++) {
for(int j = 0; j <= i; j++){
printf("%s", "*");
}
}
printf("\n");
}

BIN
a.out Normal file

Binary file not shown.

49
montyHall.c Normal file
View File

@ -0,0 +1,49 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void) {
srand(time(NULL)); // Seed random number generator
int r, s, openD;
int counter = 0, win = 0;
while (1) {
r = rand() % 3; // Winning door (0, 1, or 2)
s = -1;
puts("Select one of the 3 doors (0, 1, 2). Enter -1 to quit:");
scanf("%d", &s);
if (s == -1) break;
// Open a door with a goat (not the winning door or the selected door)
openD = rand() % 3;
while (openD == r || openD == s) {
openD = rand() % 3;
}
printf("You chose: %d, a goat is behind door: %d\n", s, openD);
puts("Do you want to choose another door? (Enter new door number):");
scanf("%d", &s);
while (s == openD) {
puts("This door is already opened! Select another door:");
scanf("%d", &s);
}
if (s == r) {
puts("YOU WON!");
win++;
} else {
puts("YOU LOSE!");
}
counter++;
}
if (counter > 0) {
printf("Win percentage: %d%%\n", (win * 100) / counter);
} else {
puts("No games played.");
}
return 0;
}