answersLogoWhite

0


Best Answer

#includ<iostream.h>

int main ()

{

int n,n-1;

for(n=0);

cout<<"the number is even:"<<endl;

if(n=n-1)

cout<<"the number is prime:"<<endl;

getch 0;

return 0;

}

User Avatar

Wiki User

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

Wiki User

14y ago

#include

using std::cin;
using std::cout;
using std::endl;

long powerOfN(long parameter, short degree);
long sumOfN(long parameter);

int main()
{
long data = 0L;
cout << endl << "Enter N: ";
cin >> data;

cout << "Result is: " << sumOfN(data) << endl;

system("PAUSE");
return 0;

}

long powerOfN(long parameter, short degree)
{
long result = 1L;
for (int i = 1; i <= degree; i++)
{
result *= parameter;

}

return result;

}

long sumOfN(long parameter)
{
long sum = 0;
for (int i = 1; i <= parameter; i++)
{
sum += powerOfN(i, 2);

}

return sum;

}

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

This only works in Xcode Command Line Tool.

#include

int main (int argc, const char * argv[])

{

int sum=0, accum1, accum2;

int i, c, n;

printf("Enter Number: ");

scanf("%d", &n);

for(i=1;c<=n;i++){

accum1=1;

accum2=i;

for(c=1;c<=i;c++){

accum1 = accum1 * accum2;

}

sum = sum + accum1;

}

printf("Sum is %d.",sum);

}

This answer is:
User Avatar

User Avatar

Wiki User

7y ago

It is not clear what is being asked here because the powers from one to n depend on which values you apply those powers to. Assuming you mean the sum of n^1 ... n^n, then simply sum all the integers from 1 to n then raise n to that power:

#include<stdio.h>

#include<math.h> // pow() function

unsigned sum_powers (const unsigned n) {

unsigned tmp = n, pwr = 0;

while (tmp) pwr += tmp--;

return pow (n, pwr);

}

int main (void) {

unsigned n;

printf ("Enter a number: ");

scanf ("%u", n);

printf ("Sum of n^1 to n^n: %u\n", sum_powers (n));

return 0;

}

This answer is:
User Avatar

User Avatar

Wiki User

7y ago

You cannot sum powers. A power is an operator and, like all operators, it requires an operand. That is; 2^3 means 2 raised to the power of 3, where 2 is the operand and "raised to the power of 3" is the operator. But without the operand, "raised to power of three" becomes meaningless.

To answer the question you need two pieces of information: the range of powers (n) and the value to be raised by those powers (v).

#include<math.h> // for C standard library pow() function

unsigned sum_powers (unsigned v, unsigned n) {

unsigned sum;

sum = v; // v to the power 1 is v

while (n>1) { // sum v^n for all n>1

sum = sum + pow (v, n);

n--;

}

return sum;

}

int main (void) {

unsigned n, v;

printf ("Enter a value:\n");

scanf ("%d", &v);

printf ("Enter the maximum power:\n");

scanf ("%d", &n);

printf ("The sum of %d^1 to %d^n is: %d\n", v, v, n, sum_powers (v, n));

return 0;

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you write a program to scan a number n and then output the sum of the powers from 1 to n using for loop statement?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is any number raised to the power of one the answer is the number itself?

It is a true statement that can be derived easily from the laws of powers (or indices).


Is a number a variable or the product of a number and one or more variables raised to whole number powers?

The statement is true only if either the number is 0, or the variables are all raised to the power 0. In no other case can a variable involved.


The European powers viewed this statement of policy at that time as what?

unimportant


The European powers viewed this statement of policy at that time as?

unimportant


Was lend lease a program to aid allied powers?

Yes


Do a java program to scan a number n and then output the sum of the powers from 1 to n thus if the input is 4 the output should be 288 because?

#include &lt;stdio.h&gt; int main() { int n; long s = 0; scanf("%d", &amp;n); for (int i=1; i&lt;=n; i++) { int k = 1; for (int j=1; j&lt;=n; j++) k=k*i; s = s + k; } printf("%d\n", s); return 0; }


What is Jerraud Powers's number on the Arizona Cardinals?

Jerraud Powers is number 25 on the Arizona Cardinals.


How do you do a number to a power on a computer?

Depends on which program you're using. In some programs, use the carat (^) to express powers. For example, 2^3 reads 2 to the third power.


What are variable raised to whole number powers?

They are the integer powers of that variable.


What is the phone number of the Powers Museum in Carthage Missouri?

The phone number of the Powers Museum is: 417-358-2667.


What is the phone number of the Powers Memorial Library in Palmyra?

The phone number of the Powers Memorial Library is: 262-495-4605.


What is the phone number of the Powers Library Association in Moravia?

The phone number of the Powers Library Association is: 315-497-1955.