fork 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 a, b, tmp, i;
  5. int main(void) { int somma = 0;
  6. scanf("%d %d", &a, &b);
  7. if (a > b) { tmp=a; a=b; b=tmp;}
  8. for (i = a; i<= b; i++) {
  9. somma += i; // somma = somma + i;
  10. printf("\nstep %i somma = %d ", i, somma);
  11. }
  12. printf("\n%d", somma);
  13. return 0;
  14. }
  15.  
  16.  
Success #stdin #stdout 0.01s 5300KB
stdin
100 102
stdout
step 100 somma = 100 
step 101 somma = 201 
step 102 somma = 303 
303