fork(1) download
  1. #include <stdio.h>
  2. //Lorenzo Borsello 2SC
  3. //Programma che somma tutti i numeri compresi fra a b. Caso b<a risolto con “if”
  4. int main(void) {int a, b, sum=0, temp;
  5. scanf("%d %d", &a, &b);
  6. if(b < a) {
  7. temp=a;
  8. a=b;
  9. b=temp;
  10. }
  11. while(a<=b)
  12. {sum = sum + a;
  13. a = a + 1;
  14. printf("%d ", sum);
  15. }
  16. return 0;
  17. }
  18.  
Success #stdin #stdout 0.01s 5276KB
stdin
4 2
stdout
2 5 9