Header Ads

Write a program to find sum of all integers greater than 100 & less than 200 and are divisible by 5.

Code :


#include<stdio.h>
int main(){
    int i, sum = 0;
    for (i = 101; i < 200; i++)
    {
        if(i%5==0){
            sum = sum+i;
        }
    }
    printf("Sum : %d",sum);
    return 0;
}


Output :

Sum : 2850

Explanation :

Declare a variable i and sum. Initialize sum is equal to zero. sum is used to store the value of sum and i is used to iterate through the for loop. Declare for loop with range between 100 to 200. Using if statement check whether number is divisible by 5 or not. If divisible by 5 then add it to sum. At the end print the value of sum.




Related Links : 








Post a Comment

0 Comments