Write a Program in C That Calculate The Sum of The Integers From 1 To 10

// Calculate the sum of the integers from 1 to 10 
#include <stdio.h>

int main( void )
{
   unsigned int sum, x; // define variables sum and x 
   
   x = 1; // set x 
   sum = 0; // set sum 
    
   while ( x <= 10 ) { // loop while x is less than or equal to 10 
      sum += x; // add x to sum 
      ++x; // increment x 
   } // end while 

   printf( "The sum is: %u\n", sum ); // display sum 
} // end main function

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...