October 25, 2024
Chicago 12, Melborne City, USA
C#

Assigning an expression to variables in C language


I have an assignment in C where i have to create a small program that would calculate some things. The only thing im struggling with is that according to said assignment, i need to let user declare x as 1.825*10^2 using scanf function. However, when doing that my program just exits.

Here’s the relevant part of my code

#include <stdio.h>
#include <math.h>

// VARIANT 2

int main()
{   
  
    float x, y, z, ans1, ans2, answer;
    printf("Declare x:\n");
    scanf("%f", &x);
    printf("Declare y:\n");
    scanf("%f", &y);
    printf("Declare z:\n");
    scanf("%f", &z);

    printf("%f %f %f \n", x,y,z);
}

Im declaring X in terminal as 1.825*pow(10,2). My guess is that scanf doesnt allow/read expressions – but the assignment is clear that i need to declare X via scanf.



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video