Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include < stdio.h >
- /*
- *
- * Excercise #1
- void main()
- {
- printf("1. Hello Yan\n");
- double PI = 3.141592;
- printf("2. %.2lf\n", PI);
- printf("3.\n *\n ***\n*****\n");
- printf("4.\nEnter 2 integers:\n");
- int a, b, c;
- scanf_s("%d%d", &a, &b);
- printf("Sum of (%d+%d): %d\n",a,b, (a + b));
- printf("Division of (%d/%d): %.2lf\n", a,b, (double) a / b);
- printf("Modulo of (%d mod %d): %d\n", a, b, a % b);
- printf("5.\nA = %d || B = %d\n", a, b);
- printf("#1: a = %d || b = %d\n", b, a);
- c = a;
- a = b;
- b = c;
- printf("#2: a = %d || b = %d\n", a, b );
- }
- */
- void main()
- {
- /*
- int a;
- printf("Enter a 3 digit number i.e 184\n");
- scanf_s("%d", &a);
- while (a <= 99 || a > 999)
- {
- printf("Enter a 3 digit number i.e 184\n");
- scanf_s("%d", &a);
- }
- int pos[4];
- pos[0] = (a / 100);
- pos[1] = (a % 100) / 10;
- pos[2] = (a % 100) % 10;
- printf("#1.\nThe sum of the number #%d is --> %d\n", a, pos[0] + pos[1] + pos[2]);
- printf("#2.\nThe new number is: %d%d%d\n", pos[2], pos[1], pos[0]);
- pos[3] = pos[0] + (pos[1] * 10) + (pos[2] * 100);
- printf("#2.\nThe new number is: %d\n", pos[3]);
- pos[0] = a / 365;
- pos[1] = (a % 365) / 30;
- pos[2] = (a % 365) % 30;
- printf("#3.\n%d days are %d years and %d months with %d extra days.\n", a, pos[0],pos[1],pos[2]);
- */
- /*
- int gTemp[4];
- int attempt;
- for (attempt = 0; attempt < 4; attempt++)
- {
- if (attempt < 3)
- printf("Please enter the grade you recieved for Task #%d\n", attempt + 1);
- else
- printf("Please enter the grade you recieved for the Test.\n");
- scanf_s("%d", &gTemp[attempt]);
- while (gTemp[attempt] < 0 || gTemp[attempt] > 100)
- {
- printf("Invalid value for the 'grade' please try again.\n");
- scanf_s("%d", &gTemp[attempt]);
- }
- }
- printf("* Test Results:\n");
- printf("[TASK 1] %d\n", gTemp[0] );
- printf("[TASK 2] %d\n", gTemp[1] );
- printf("[TASK 3] %d\n", gTemp[2]);
- printf("* Avg. Task Results: %d\n", (gTemp[0]+gTemp[1]+gTemp[2]) / 3);
- printf("[TEST] %d\n", gTemp[3]);
- printf("* Test Results: %.0lf\n", (((gTemp[0] + gTemp[1] + gTemp[2]) / 3) * 0.2) + (gTemp[3] * 0.8));
- */
- /*
- int i;
- double x, tempx;
- printf("Enter a value for X:\n");
- scanf_s("%lf", &x);
- tempx = x;
- for (i = 2; i <= 8;)
- {
- tempx *= x;
- printf("[X^%d]: %.0lf\n", i, tempx);
- tempx *= x;
- i += 2;
- }
- */
- int Distance, CarSpeed, FlySpeed;
- printf("First enter the distance in KM from City A to City B:\n");
- scanf_s("%d", &Distance);
- while (Distance < 1)
- {
- printf("Invalid value for distance, please enter a new value:\n");
- scanf_s("%d", &Distance);
- }
- printf("Now enter the speed of the cars in Km/h:\n");
- scanf_s("%d", &CarSpeed);
- while (CarSpeed < 1)
- {
- printf("Invalid value for speed, please enter a new value:\n");
- scanf_s("%d", &CarSpeed);
- }
- printf("Lastly enter the bonus speed for the fly over the cars in Km/h:\n");
- scanf_s("%d", &FlySpeed);
- while (FlySpeed < 1)
- {
- printf("Invalid value for bonus, please enter a new value:\n");
- scanf_s("%d", &FlySpeed);
- }
- printf("The distance between the cities in kilometers is: %d km\n", Distance);
- printf("The speed of the cars in km/h is: %d km/h\n", CarSpeed);
- printf("The speed of the fly in km/h is: %d km/h\n", CarSpeed + FlySpeed);
- printf("The cars will crash after: %.2lf hour(s)\n", (double) Distance / CarSpeed );
- printf("Over this time the fly will travel a distance of: %.2lf km\n", (FlySpeed + CarSpeed) * ((double)Distance / CarSpeed));
- }
Advertisement