Finds sum of first 20 integers with while loop - C Statement

C examples for Statement:while

Description

Finds sum of first 20 integers with while loop

Demo Code

#include <stdio.h>
int main(void)          
{
    int count, sum;           
    //from  w ww. j  av  a  2s . co  m
    count = 0;                
    sum = 0;                  
    while (count++ < 20)      
        sum = sum + count;    
    printf("sum = %d\n", sum);
    
    return 0;                 
}

Result


Related Tutorials