answersLogoWhite

0


Best Answer

#include<iostream>

#include<vector>

std::vector<size_t> multiples(size_t const num, const size_t terms)

{

std::vector<size_t> result;

size_t term=0;

while (++term<=terms)

result.push_back (num*term);

return result;

}

int main()

{

const std::vector<size_t> mults = multiples (42, 5);

std::cout << "The first 5 multiples of 42 are:";

for (auto value : mults) std::cout << '\t' << value;

std::cout << std::endl;

}

User Avatar

Wiki User

9y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

To write a program to check whether a particular number is a multiple of 5, or any other number for that matter, you check to see if the first number, modulus the second number, is zero.

if (N % 5 == 0) { /* N is divisible by 5 */ }

If you don't have the modulus (%) operator, you can use the explicit expression

if (N - int (N / 5) * 5 == 0) { /* N is divisible by 5 */ }

This answer is:
User Avatar

User Avatar

Wiki User

7y ago

There is no modulus operator in C. Presumably you meant modulus in the literal sense to sum the absolute values of 5 signed integers. To obtain the absolute value of a signed integer, simply invoke the C standard library abs() function declared in <math.h>:

#include<math.h>

int sum_abs (int* arr, int size) {

int sum = 0;

for (int i=0; i<size; ++i) sum += abs (arr[i]);

return sum;

}

If you actually meant the modulo operator (%), it is not clear how you intend to use this operator to calculate a sum given that the modulo operator is a division operator (it returns the remainder after division) but it's not clear how the five values should be divided let alone what is to be summed.

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

The "%" operator gives the remainder of a division, for example: b = a % 5;

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you write a C plus plus program to find the first 5 multiples of a number?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

manthan?

Write the first 6 Multiples of 12 and 14.


Write down the first three multiples of 340?

340, 680, 1020.


How do you write a program to print the first n multiples of 7?

Algorithm: multiples input: two positive integers, m and n output: print first n multiples of m i = m; for j = 1 to n print i i = i + m; next j


Identify the first three common multiples of 4 and 5?

write the first three common. multiples of 3,4,5


Write down the first 3 multiples of 7?

The first 3 multiples of 7 are: 7, 14, and 21.


How can number patterns help in finding the least common multiples?

Example: Find the LCM of 12 and 30.Write the multiples of 12: 12, 24, 36, 48, 60, 72, ...Write the multiples of 30: 30, 60, 90, ...The first number you find which is in both lists is the LCM: 60.


Multiples of 5 in even number write in rule form?

Even multiples of 5 must end with a zero.


Write a program to convert a 2 digit BCD number into hexadecimal number?

Write a program to convert a 2-digit BCD number into hexadecimal


Write a java script program to print first ten odd natural numbers in C?

Q.1 Write a program to print first ten odd natural numbers. Q.2 Write a program to input a number. Print their table. Q.3 Write a function to print a factorial value.


How do write out multiples of a hundred thousand?

Multiples of a Hundred thousand have a number followed by 5 zeroes Example: 300,000 400,000


What is the largest number you can write using the multiples of 3?

There is no largest number. You can just keep going.


How manys ways can you write 100?

You can write 100 an infinite number of ways; as fractions, multiples, notations, and others.