plugin23

zadanie4prog

May 4th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.54 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main() {
  4.     int n, d;
  5.     scanf_s("%d %d", &n, &d);
  6.     if ((n > 0) && (d >= 0)) {
  7.         if (d == 0) {
  8.             int suma = 0;
  9.             for (int i = 1; i <= n; i++) {
  10.                 suma = suma + i;
  11.             }
  12.             printf("Suma cisiel od 1 po %d je %d.\n", n, suma);
  13.         }
  14.         else if (d > 0) {
  15.             int suma1 = 0;
  16.             for (int j = 1; j <= n; j++) {
  17.                 if (j%d == 0) {
  18.                     suma1 = suma1 + j;
  19.                 }
  20.             }
  21.             printf("Suma cisiel od 1 po %d delitelnych cislom %d je %d.\n", n, d, suma1);
  22.         }
  23.     }
  24.     else {
  25.         printf("Nespravny vstup.\n");
  26.     }
  27.     return 0;
  28. }
Add Comment
Please, Sign In to add comment