Create a C++ program that allows the user to enter any integer value (whole number)
Link will be apear in 30 seconds.
Well done! you have successfully gained access to Decrypted Link.
Question:
- Create a C++ program that allows the user to enter any integer value (whole number)
- Program would then display all values divisible by 5
- Use while or do-while loop
- Screenshot your codes and output
- Save your answer in pdf format
- Submit your file in Canvas
Example output:
Please enter a number: 20
5
10
15
20
Answer:
Step 1
Algorithm:
- Start
- Read a number n
- Initialize i to 1
- Iterate through the loop till i<=n
- If i%5==0 and i!=0 print i
- Set i=i+5
- Stop
Step 2
Program:
#include <iostream>
using namespace std;
int main() {
int n;
cout<<"Please enter a number: ";
cin>>n;
int i=0;
while(i<=n){
if(i%5==0 && i!=0)
cout<<i<<endl;
i+=5;
}
return 0;
}
Step 3
Screenshot:
