Thread: I need help with a little calculation on C

  1. #1
    Registered User
    Join Date
    Oct 2019
    Posts
    6

    I need help with a little calculation on C

    Hello smart ones,
    Please I want to perform this calculation and save it in a variable 'x'. like
    X1. A
    X2. A+H
    X3. A+H+CH
    X4. A+H+CH+C^2H
    X5. A+H+CH+C^3H .....etc
    to 15 times
    and save it in variable x. I will use x to calculate this function y = (6 * pow(x,2) + 29*x + 14) / (32 - pow(x,5)). so that when I print 'y', I will get the values from X1 to X15

    double i, x = a;
    for (i = 0; i < b ; i++)
    x = x + pow(c,i)* h

    I Used this but I'm getting the value from X2 instead of from X1

    Thank you. It's urgent, I am new to programming..
    Last edited by Chibisco; 3 Weeks Ago at 05:37 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,489
    So this?
    Code:
    for (i = 0; i < b ; i++) {
        x = x + pow(c,i)* h;
        y = (6 * pow(x,2) + 29*x + 14) / (32 - pow(x,5));
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Oct 2019
    Posts
    6
    This is what I get. Note the value of A is 0.1.
    x1 should be 0.1 not 0.3

    I need help with a little calculation on C-code-png

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,489
    Do you have code for that, or is it just a screen-shot from your assignment.

    > x1 should be 0.1 not 0.3
    Code:
    for (i = 0; i < b ; i++, x = xnew ) {
        xnew = x + pow(c,i)* h;
        // figure out whether you need x or xnew in this calc.
        y = (6 * pow(x,2) + 29*x + 14) / (32 - pow(x,5));
        // figure out whether you print x or xnew along with y
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Oct 2019
    Posts
    6
    Thank you. You are The best. I have a code already but It is ok now.I need help with a little calculation on C-code2-png
    Can I have a means of communicating with you like from facebook or WhatsApp.
    Last edited by Chibisco; 3 Weeks Ago at 07:53 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. calculation
    By Rohit88 in forum C Programming
    Replies: 9
    Last Post: 01-03-2012, 01:53 PM
  2. Tax Calculation Help
    By Cyberdine in forum C Programming
    Replies: 22
    Last Post: 04-09-2007, 11:06 PM
  3. Help With Calculation
    By WackoWolf in forum C++ Programming
    Replies: 4
    Last Post: 10-12-2005, 05:18 PM
  4. calculation
    By coo_pal in forum C Programming
    Replies: 2
    Last Post: 02-09-2003, 11:41 PM
  5. Calculation Help
    By reddtee in forum C Programming
    Replies: 19
    Last Post: 11-24-2001, 04:17 PM

Tags for this Thread