C# Homework - Need Help

by 6logos
4 replies
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!
#homework
  • Profile picture of the author purpleviolet
    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
    {{ DiscussionBoard.errors[6529389].message }}
  • Profile picture of the author webpeon
    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.
    Signature
    Web 2 Mobile
    The Future of The Web
    {{ DiscussionBoard.errors[6531710].message }}
  • Profile picture of the author CodeShack
    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
    {{ DiscussionBoard.errors[6542702].message }}
  • Profile picture of the author wayfarer
    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.
    Signature
    I build web things, server things. I help build the startup Veenome. | Remote Programming Jobs
    {{ DiscussionBoard.errors[6542735].message }}

Trending Topics