Advertisement
STANAANDREY

pclab3 custom1

Oct 12th, 2022 (edited)
637
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.42 KB | None | 0 0
  1. //se citeste un nr n>1. Apoi se va afisa suma lui Gauss: "1+2+...n=s". Daca n<=1 =>STOP.
  2. #include <stdio.h>
  3.  
  4. void writeGauss(int n) {
  5.   int s = 1;
  6.   printf("1");
  7.   for (int i = 2; i <= n; i++) {
  8.     s += i;
  9.     printf("+%d", i);
  10.   }
  11.   printf("=%d\n", s);
  12. }
  13.  
  14. int main(void) {
  15.   int n = 2;
  16.   while (n > 1) {
  17.     printf("n="); scanf("%d", &n);
  18.     if (n > 1) {
  19.       writeGauss(n);
  20.     }
  21.   }
  22.  
  23.   return 0;
  24. }
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement