Write a Program in C That Do Summation With For

// Summation with for
#include <stdio.h>

// function main begins program execution
int main( void )
{
   unsigned int sum = 0; // initialize sum
   unsigned int number; // number to be added to sum

   for ( number = 2; number <= 100; number += 2 ) {
      sum += number; // add number to sum          
   } // end for

   printf( "Sum is %u\n", sum ); // output sum
} // end function main

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...