This commit is contained in:
k0rrluna 2025-05-07 14:05:25 +03:00
parent 785c2b0e50
commit 50a27f1d6c
7 changed files with 128 additions and 0 deletions

View File

@ -0,0 +1,19 @@
#include <stdio.h>
int main(void) {
float f1, f2, f3, f4;
puts("Enter 4 float!");
scanf("%f%f%f%f", &f1, &f2, &f3, &f4);
float listF[] = {f1, f2, f3, f4};
float temp;
for(int i = 0; i < 3; i++) {
if(listF[i] >= listF[i+1]) {
temp = listF[i];
} else if (listF[i+1] >= listF[i]) {
temp = listF[i+1];
}
}
printf("%s%f\n", "Biggest float: ", temp);
return 0;
}

View File

@ -0,0 +1,17 @@
#include <stdio.h>
int isPerfect(int);
int isPerfect(int num) {
int temp = 0;
for(int i = 1; i < num; i++) {
if(num % i == 0) {
temp += i;
}
}
if (temp == num) {
return 1;
} else {
return 0;
}
}

View File

@ -0,0 +1,18 @@
#include <stdio.h>
#include "isPerfect.c"
int main(void) {
/*puts("Enter a int!");
int num;
scanf("%d", &num);
printf("%d\n", isPerfect(num));*/
for(int i = 0; i < 1000; i++) {
if(isPerfect(i)) {
printf("%d ", i);
}
}
puts("");
return 0;
}

19
DeitelC/Chapter5/lcm.c Normal file
View File

@ -0,0 +1,19 @@
#include <stdio.h>
int lcm (int, int);
int lcm (int i1, int i2)
{
int i3 = 0;
if (i1 >= i2) {
i3 = i1;
} else {
i3 = i2;
}
for (int i = 2; i < i3; i++) {
if (i1 % i == 0 && i2 % i == 0) {
i3 = i;
}
}
return i3;
}

View File

@ -0,0 +1,11 @@
#include <stdio.h>
#include "lcm.c"
int main (void)
{
int i1, i2 = 0;
puts("Enter int1 and int 2");
scanf("%d%d", &i1, &i2);
printf("%s%d\n", "Lowest common integer: ", lcm(i1, i2));
return 0;
}

View File

@ -0,0 +1,26 @@
#include <stdio.h>
#include <math.h>
void rootsOfQuad(int, int, int);
int main(void) {
int a, b, c = 0;
puts("Enter coefficients!");
scanf("%d%d%d", &a, &b, &c);
rootsOfQuad(a, b, c);
return 0;
}
void rootsOfQuad(int a, int b, int c) {
int discriminant = (b * b) - 4 * a * c;
if(discriminant) {
int x1 = (-b - sqrt(discriminant))/2 * a;
int x2 = (-b + sqrt(discriminant))/2 * a;
printf("%s%d%d\n", "x1 and x2 are: ", x1, x2);
} else {
puts("Not reel!");
}
}

View File

@ -0,0 +1,18 @@
#include <stdio.h>
int sumOfDigits(int);
int main(void) {
int t = 7613;
printf("%d\n", sumOfDigits(t));
return 0;
}
int sumOfDigits(int num) {
int result = 0;
while (num > 0) {
result += num % 10;
num /= 10;
}
return result;
}