Sum 1 to N Numbers using for statement - C Data Type

C examples for Data Type:int

Description

Sum 1 to N Numbers using for statement

Demo Code

#include <stdio.h>

int main(){//from w  w  w  .j  a v  a 2 s .c  o  m
          int counter = 100;
          unsigned long int sum = 0;

          for (int i = 1; i <= counter; i++) {
              sum = sum + i;
          }
    
          printf("Required sum is: %lu\n", sum);
          
          return(0);
}

Result


Related Tutorials