Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //se citeste un nr n>1. Apoi se va afisa suma lui Gauss: "1+2+...n=s". Daca n<=1 =>STOP.
- #include <stdio.h>
- void writeGauss(int n) {
- int s = 1;
- printf("1");
- for (int i = 2; i <= n; i++) {
- s += i;
- printf("+%d", i);
- }
- printf("=%d\n", s);
- }
- int main(void) {
- int n = 2;
- while (n > 1) {
- printf("n="); scanf("%d", &n);
- if (n > 1) {
- writeGauss(n);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement