C# Homework - Need Help

by 4 replies
5
Hi guys!

I am currently taking up C# programming on our school..
Our instructor gave us a homework to work with..

The problem are:

1.) To get the exponential product of the two input integer values using any loops (for loop, while or do while).

Ex:

Input integer value: 2
Input Exponent: 3
Output >>> 8

2.) To get the square root of the input value using any loops (for loop, while or do while)..

Ex:

Input Value: 25
Square root : 5


I need it ASAP..
Thank you guys!
#programming #homework
  • 1. Logic goes like this:

    Take the values from the user and store it in different variables . Assume x= integer value and y = exponent

    for(i=1;i<=y;i++)
    {
    answer= x*x;
    }

    display the value of answer
  • That wont work...

    if x = 2 and y = 4, the loop would run as follows

    1... answer (4) = x (2) * x (2)
    2... answer (4) = x (2) * x (2)
    3... answer (4) = x (2) * x (2)
    4... answer (4) = x (2) * x (2)

    display answer (4) when we all know that 2^4 = 16 is the correct answer



    Note: I dont make a habit of giving people answers for homework related questions but if you post what code you do have I dont mind advising you were you are going wrong.
  • for (1) - use this:

    int a, b, c, d;

    a = (exponent);
    b = (integer);
    d = b;
    for (c = 1; c <a; c++)
    d *= b;

    result will be given in d
  • Seeing how this is YOUR homework, don't you think YOU should be doing it? Is this how you're going to program, by getting other people to solve your problem for you? There's a reference for a reason, use it.

Next Topics on Trending Feed