230k views
1 vote
Write a program in which given an integer num, return the sum of the multiples of num between 1 and 100. For example, if num is 20, the returned value should be the sum of 20, 40, 60, 80, and 100, which is 300. If num is not positive, return 0.

User Wextux
by
4.8k points

1 Answer

4 votes

Answer:

#include<iostream>

using namespace std;

int main()

{

int num=0,sum=0;

cout<<"Insert Number to find sum of mutiples.";

cin>>num;

int temp=num;

if(num>0){

sum+=num;

while(num<100){

num+=temp;

sum+=num;

}

cout<<"Sum of Multiples is ="<<sum<<endl;

}else{

return 0;

}

return 0;

}

Step-by-step explanation:

This code is written in c++. Written by Saad-Ur-Rehman.

User Andrew Davey
by
5.0k points