Skip to content
Snippets Groups Projects
Select Git revision
  • 5cb489fc81ce13abec9dc1cae85e0890b101ecfa
  • master default
2 results

while_loop_summation.c

Blame
  • while_loop_summation.c 344 B
    #include <iostream>
    int main ()
    
    {
      int i;
      std::cout  << "please enter an integer value: ";
      std::cin >> i;
      int b=i;
      int a=b-1;
      while (a >= 1) {
      
        b += a--;}
          
      std::cout << "The value you entered is " << i;
      std::cout << " and the sum of all whole numbers up to and including your value is " << b << ".\n";
    return 0
      ;}