fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. int n;
  5. printf("Donnez un nombre entier : ");
  6. scanf("%d", &n);
  7.  
  8. printf("Les sommes consécutives sont :\n");
  9.  
  10. for (int start = 1; start < n/2 +2; start++) {
  11. int somme = 0;
  12. int termes[100];
  13. int count = 0;
  14.  
  15. for (int x = start; x < n/2 +2; x++) {
  16. somme += x;
  17. termes[count++] = x;
  18.  
  19. if (somme == n) {
  20. printf("%d = ", n);
  21. for (int i = 0; i < count; i++) {
  22. if (i != count - 1)
  23. printf("%d+", termes[i]);
  24. else
  25. printf("%d", termes[i]);
  26. }
  27. printf("\n");
  28. break;
  29. } else if (somme > n) {
  30. break;
  31. }
  32. }
  33. }
  34.  
  35. return 0;
  36. }
  37.  
  38.  
Success #stdin #stdout 0s 5316KB
stdin
77
stdout
Donnez un nombre entier : Les sommes consécutives sont :
77 = 2+3+4+5+6+7+8+9+10+11+12
77 = 8+9+10+11+12+13+14
77 = 38+39