Advertisement
Mary_99

Sum Of n number in while loop

Nov 25th, 2018
144
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. #include <math.h>
  3. int main()
  4. {
  5.  long num;
  6.  long suma = 0L; //przypisanie zmiennej suma warosci poczatkowej zero
  7.  
  8.  int stan;
  9.  
  10.  printf("Podaj liczbe calkowita do zsumowania. ");
  11.  printf("wpisz q, aby zakonczyc program.\n");
  12.  stan = scanf("%1d", &num);
  13.  while (stan == 1)
  14.  {
  15.      suma = suma + num;
  16.      printf("Podaj nastepna liczbe calkowita do zumowania.");
  17.      printf("wpisz q any zakonczyc program.\n");
  18.      stan = scanf("%1d", &num);
  19.  }
  20.  printf("Suma podanych liczb wynosi %1d.\n", suma);
  21.  
  22.    return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement