cInsert real numbers into language strings

Asked 2 years ago, Updated 2 years ago, 141 views

char practice[100];

float value;

int main() {

value = 12.6332;
practice[0] = value;
printf("%f\n", practice[0]);

}

I put 12.6332 as the value value in the practice, but the result doesn't come out like that What should I do?

c string input float

2022-09-21 23:14

1 Answers

Hello :-)

You have declared the type of value as float.

However, it is because you entered the value as an element in the character (character) type - char practice[100] array. The types are inconsistent with each other.

Please note that we have corrected some mistakes in the code you gave us.

#include<stdio.h>
float practice [100]; # Change the type of array from char[100] to float[100].
float value;

int main() { # The main function must return an integer int.
    value = 12.6332;
    practice[0] = value;
    printf("%f\n", practice[0]);
    The return 0; # main function must return an integer int.
}

In addition, we will give you a C unlink from Tutorials Point, so it will be helpful if you read the data type part step by step: https://www.tutorialspoint.com/cprogramming/c_arrays.htm

I hope you will help in a matter of experiencing

.

Thank you.


2022-09-21 23:14

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.