0

I'm just learning the C programming language . Could you explain to me why isn't my output produced?

#include <stdio.h>
int main (void)
{
    int x , total ;
    printf("Enter the value of x : ");
    scanf("%i\n", x);
    total = (3 * x * x * x * x * x) + (2 * x * x * x * x) - (5 * x * x * x) - (2 * x * x) + (7 * x) - 6;
    printf("Total value of the polynomial is %i\n", total);
    return 0 ;
}

John Lim
  • 81
  • 5
  • scanf is not special as far as functions go. When you pass a variable to a function, the function gets a copy of the variable. Even if it puts something into that variable, it is only modifying its copy so the caller's version is never changed. To allow any function to change a variable you need to pass a pointer to the variable. – Jerry Jeremiah Sep 28 '20 at 01:57
  • Save time, enable all compiler warnings. – chux - Reinstate Monica Sep 28 '20 at 03:19
  • Aside: consider `((((3*x + 2)*x - 5)*x - 2)*x + 7)* x - 6`. It has various advantages over original code: Speed, better range, better precision retention when `x` is floating point. – chux - Reinstate Monica Sep 28 '20 at 03:22

1 Answers1

0

Change the scanf to:

   scanf("%i", &x);

You need to pass in the address of x to assign it a value from the scanf function. Also no \n

OldProgrammer
  • 12,050
  • 4
  • 24
  • 45