SHARE
TWEET

Untitled

a guest Oct 23rd, 2019 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Projekt nr 1. - Dodawanie, odejmowanie, mnożenie i dzielenie z użyciem (opisaniem) printf, scanf, switch...case i jednym oficjalnym if'em.
  2.  
  3. /*
  4. double a, b;
  5.     printf("Give me first number.");
  6.     scanf("%lf", &a);
  7.     printf("Give me second number.");
  8.     scanf("%lf", &b);
  9.     printf("Tell me what do you want to do...\n");
  10.  
  11.     int option;
  12.     printf("1. Sum.\t\t2. Sub.\t\t3. Mult.\t\t4. Div.\n");
  13.     scanf("%d", &option);
  14.     switch (option) {
  15.     case 1:
  16.         printf("You are summing.\n");
  17.         printf("The sum = %lf", a + b);
  18.         break;
  19.     case 2:
  20.         printf("You are subtracting.\n");
  21.         printf("The sub = %lf", a - b);
  22.         break;
  23.     case 3:
  24.         printf("You are multing.\n");
  25.         printf("The sum = %lf", a * b);
  26.         break;
  27.     case 4:
  28.         printf("You are dividing.\n");
  29.         if (b == 0) {
  30.             printf("You can not divide by 0!!\n");
  31.             break;
  32.         }
  33.         printf("The div = %lf", a / b);
  34.         break;
  35.     default:
  36.         printf("Wrong number!\n");
  37.         break;
  38.     }
  39. */
  40.  
  41. // Projekt nr 2. Zastosowanie for'a oraz if'ów do znalezienia czy liczba podana jest liczbą pierwszą.
  42.  
  43. /* 
  44.     int i, num, p = 0;
  45.     printf("Please enter a number: \n");
  46.     scanf("%d", &num);
  47.     for (i = 1; i <= num; i++){
  48.         if (num%i == 0) p++;
  49.     }
  50.     if (p == 2){
  51.         printf("Entered number is %d "\
  52.             "and it is a prime number.", num);
  53.     }
  54.     else{
  55.         printf("Entered number is %d "\
  56.             "and it is not a prime number.", num);
  57.     }
  58. */
  59.  
  60. // Projekt nr 3. Użycie while'a do programu obliczającego sumę cyfr wprowadzonej liczby. Użyte także skróty (number /= 10)
  61. /*
  62.     int number;
  63.     int result = 0;
  64.  
  65.     printf("Give a number...\n");
  66.     scanf("%d", &number);
  67.  
  68.     while (number > 0) {
  69.         int tmp = number / 10;
  70.         tmp *= 10;
  71.         tmp = number - tmp;
  72.         result = result + tmp;
  73.         number /= 10;
  74.     }
  75.     printf("The result = %d", result);
  76. */
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top