Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Projekt nr 1. - Dodawanie, odejmowanie, mnożenie i dzielenie z użyciem (opisaniem) printf, scanf, switch...case i jednym oficjalnym if'em.
- /*
- double a, b;
- printf("Give me first number.");
- scanf("%lf", &a);
- printf("Give me second number.");
- scanf("%lf", &b);
- printf("Tell me what do you want to do...\n");
- int option;
- printf("1. Sum.\t\t2. Sub.\t\t3. Mult.\t\t4. Div.\n");
- scanf("%d", &option);
- switch (option) {
- case 1:
- printf("You are summing.\n");
- printf("The sum = %lf", a + b);
- break;
- case 2:
- printf("You are subtracting.\n");
- printf("The sub = %lf", a - b);
- break;
- case 3:
- printf("You are multing.\n");
- printf("The sum = %lf", a * b);
- break;
- case 4:
- printf("You are dividing.\n");
- if (b == 0) {
- printf("You can not divide by 0!!\n");
- break;
- }
- printf("The div = %lf", a / b);
- break;
- default:
- printf("Wrong number!\n");
- break;
- }
- */
- // Projekt nr 2. Zastosowanie for'a oraz if'ów do znalezienia czy liczba podana jest liczbą pierwszą.
- /*
- int i, num, p = 0;
- printf("Please enter a number: \n");
- scanf("%d", &num);
- for (i = 1; i <= num; i++){
- if (num%i == 0) p++;
- }
- if (p == 2){
- printf("Entered number is %d "\
- "and it is a prime number.", num);
- }
- else{
- printf("Entered number is %d "\
- "and it is not a prime number.", num);
- }
- */
- // Projekt nr 3. Użycie while'a do programu obliczającego sumę cyfr wprowadzonej liczby. Użyte także skróty (number /= 10)
- /*
- int number;
- int result = 0;
- printf("Give a number...\n");
- scanf("%d", &number);
- while (number > 0) {
- int tmp = number / 10;
- tmp *= 10;
- tmp = number - tmp;
- result = result + tmp;
- number /= 10;
- }
- printf("The result = %d", result);
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement