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

visit:- allinpython.com  for more practicals

Hello Friend’s

Today we write our program using the while loop and we all know that in the while loop we first “initialize the variable ”, ”give condition to the variable(loop)” and last “increment or decrement the variable.(these three basic things are always applied to any loop)

So in our program, we take numbers greater than 100 à so we take initialize variable 101

Now according to the question we are taking a number less than 200 à so we give a condition to the loop that is less than 200 (<200)

Then we increment our variable in the loop

Now with this concept, we are writing our program so let’s started

Source Code:-


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

Output:-

i=105
i=110
i=115
i=120
i=125
i=130
i=135
i=140
i=145
i=150
i=155
i=160
i=165
i=170
i=175
i=180
i=185
i=190
i=195
sum=2850


 

Thank-you guys


0 Comments