Basic

Switch Case

Goto

Operators

if Statement

Nested if

While Loop

For Loop

Array

Patterns

Excersises


Sum of all number using while in c program


C program to Find sum of all numbers in given range using while Loop.

Example : pgm.c

#include<stdio.h>
int main(){
    int i,f,t,sum=0;
    printf("\nEnter From Value : ");
    scanf("%d",&f);
    printf("\nEnter To Value : ");
    scanf("%d",&t);
    i=f;
    while(i<=t){
        sum=sum+i;
        i++;
    }
    printf("\nSum of %d to %d is %d",f,t,sum);
    return 0;
}

Output:

Enter From Value : 1
Enter To Value : 10
Sum of 1 to 10 is 55