Skip to content

Instantly share code, notes, and snippets.

@oykelrae
oykelrae / age_if.c
Last active December 19, 2019 13:52
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
int main() {
setlocale(LC_ALL,"Russian");
int age;
char *s = malloc(5);
scanf("%d", &age);
if (age%10==0||((age%10>=5) && (age%10<=9))||age/10==1)
@oykelrae
oykelrae / output.txt
Last active December 12, 2019 10:20
While loop. "Summing integers" interactive program
Please enter an integer to be summed (q to quit): 39
Please enter next integer (q to quit): 13
Please enter next integer (q to quit): 88
Please enter next integer (q to quit): q
________________________________________
Those integers sum to 140.
Program ended with exit code: 0
@oykelrae
oykelrae / divisible.c
Last active December 13, 2019 13:20
Switch statement. "Whether a entered number is divisible by 6" program
#include <stdio.h>
int main(void) {
printf("Let's see if your number is divisible by 6.\nEnter a number: ");
int num;
scanf("%d",&num);
switch (num%3) {
case 0 :
@oykelrae
oykelrae / output.txt
Last active December 10, 2019 19:09
Water drops and molecules in a glass
Enter a number of glasses of water: 3
The number of water drops in 3 glass.es is 14970
The number of water molecules is 2.495e+25
Program ended with exit code: 0
@oykelrae
oykelrae / output.txt
Last active December 9, 2019 22:23
Convert seconds to hh:mm:ss format
Enter the number of seconds elapsed today: 65434
The time is 18:10:34
Program ended with exit code: 0
@oykelrae
oykelrae / output.txt
Created December 9, 2019 20:02
Random integer generator
This is a random integer generator.
Enter number range (e.g., 1-25): 50-66
61
Program ended with exit code: 0
@oykelrae
oykelrae / main.c
Last active December 4, 2019 21:50
<math.h> The area of a triangle given 3 sides
#include <stdio.h>
#include <math.h>
int main() {
double s1, s2, s3, p, area;
printf("Enter the lengths of 3 sides of a triangle: ");
scanf("%lf %lf %lf", &s1, &s2, &s3);
p = (s1 + s2 + s3) / 2;
area = sqrt(p*(p-s1)*(p-s2)*(p-s3));
printf("The area of the triangle is %.2lf\n", area);
@oykelrae
oykelrae / main.c
Last active December 4, 2019 21:50
<math.h> The area of a triangle given 2 sides and the angle between them
#include <stdio.h>
#include <math.h>
int main() {
double s1, s2, angle, area;
printf("Enter the lengths of two sides of a triangle: ");
scanf("%lf %lf", &s1, &s2);
printf("Enter the angle between them (in degrees): ");
scanf("%lf", &angle);
area = (s1 * s2 * sin((3.141593 / 180) * angle)) / 2;
@oykelrae
oykelrae / distance.c
Last active December 9, 2019 22:57
<math.h> Distance between two points
#include <stdio.h>
#include <math.h>
int main() {
double x1, x2, y1, y2, dist;
printf("Enter the coordinates of a point A (x1 and y1): ");
scanf("%lf %lf", &x1, &y1);
printf("Enter the coordinates of a point B (x2 and y2): ");
scanf("%lf %lf", &x2, &y2);
dist = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
@oykelrae
oykelrae / absolute.c
Created December 4, 2019 09:40
Модуль числа
#include <stdio.h>
#include <math.h>
int main() {
double x, result;
printf("Введите число: ");
scanf("%lf", &x);
result = fabs(x);
printf("Модуль вашего числа = %.1lf\n", result);
return 0;