1. Type a 'sumade2en2' function that receives an n number and
returns the sum of the numbers from 1 and
increments of 2 without going over n. For example, if the function
is invoked with 7, it must return 16 (1+3+5+7). Yes
invoked with the 8 must return 16 (1+3+5+7).
2. Type a 'productmultiply' function that receives two integers
a and b. The function must return the
product of all multiples of a that do not exceed b. For example, if
the function is invoked with 7 and 30,
57624 (7*14*21*28). If the function is invoked with 6 and 18, it
must return 1296 (6*12*18).
1.
CODE:
int sumaden2en2(int n)
{
int sum=0;
for(int i=1;i<=n;i+=2)
{
sum+=i;
}
return sum;
}
SCREENSHOT:
2.
CODE:
int productmultiply(int a, int b)
{
int product=1;
for(int i=1;(a*i)<=b;i++)
{
product=product*(a*i);
}
return product;
}
SCREENSHOT:
Get Answers For Free
Most questions answered within 1 hours.