In: Computer Science
Write an algorithm that print all numbers that are divisible by 3 between 1000 and 2000
Algorithm that print all numbers that are divisble by 3 between 1000 and 2000:-
So, it is given that range to check is between 1000 to 2000. Hence starting position will be 1000 where we start to check and 2000 will be ending point.
Algorithm:-
Step 1: START
Step 2: Start from the 1000 and one by one check that number is divisible by 3 or not untill we reached the number 2000.
Step 3: If number is divisible by 3, print that number.
Step 4: If number is not divisible by 3, don't print anything.
Step 5: END.
C++ program that print all numbers that are divisible by 3 between 1000 and 2000:-
//C++ program that print all numbers that are divisible by 3 between 1000 and 2000
#include<iostream>
using namespace std;
//main function
int main() {
//initiaslising that all numbers that are divisible by 3 between 1000 and 2000.
int starting_pos=1000, ending_pos= 2000;
//declaring i variable to check the number is divisible by 3 or not.
int i;
//range is between 1000 to 2000
for(i=1000;i<=2000;i++)
{
//checking i is divisible by 3 or not
if(i%3==0)
//printing the divisble values
cout<<i<<" ";
}
return 0;
}
Output:-