convert numbers in scientific notation to decimal [closed] - c

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Write a C program to convert a number in scientific notation to its equivalent decimal form :
Given
8.3e+2 output = 830
2.E-1 output = 0.2
4.3E2 output = 430
Is there any inbuilt library or function in C/C++ which can do this?
or one will have to write his own code, in that case, any easy way to achieve this?

try this
#include <iostream>
#include <string>
int32_t main(int32_t argc, char *argv[]) {
std::string str = "8.3e+2";
std::cout << std::stod(str) << std::endl;
return EXIT_SUCCESS;
}

Related

Alternatives for str.substr using <cstring> library? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 months ago.
Improve this question
Hi I was wondering if there is an alternative of str.substring() in string.h. If not, what is an efficient alternative?
Assuming that we all agree that using c++ it is safer and more professional to use the standard library tools.
That said, if we're talking about C and not C++, this should be one of the ways to extract a substring with the "string.h" library:
#include <stdio.h>
#include <string.h>
int main() {
char test[] = "abcdef";
char subtext[3];
memcpy(subtext, &test[1], 2); //Result: "bc"
subtext[2] = '\0';
printf("%s", subtext);
return 0;
}

Convert hex String to decimal string in C [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 months ago.
Improve this question
How would you convert a hexadecimal string, like "661efdf2e3b19f7c045f15" to the decimal string "123456789123456789123456789"?
Thanks in advance!
Using GMP you can assign the hex number to an "mpz_t" the GMP integer value. Here's an example.
#include <gmp.h>
int main(int argc, char** argv) {
mpz_t integer;
mpz_init(integer);
mpz_set_str(integer, "661efdf2e3b19f7c045f15", 16); //16 is the number base
gmp_printf("Your number is: %Zd\n", integer); //Outputs "Your number is: 123456789123456789123456789"
return 0;
}
GMP comes automatically with some linux distros but if you don't have it, you can download it here.
Hope this helps!

Can I make a float number in a C program always round up [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
Can I make a float number in a C program always round up
You can use the ceil() function. For example:
#include <stdio.h>
#include <math.h>
int main () {
float val1 = 1.6;
printf ("Round up to %.1lf\n", ceil(val1));
return(0);
}

Convert string of macro to macro [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
How can a string like "EINVAL" be converted into EINVAL?
I have to convert a lot of macro string to their value, what can be done?
Here is the simplest method I can think of:
#include <errno.h>
if (!strcmp(str, "EINVAL"))
value = EINVAL;
No preprocessor trick can convert the string literal to the corresponding symbol.
But you can use the preprocessor to simplify a sequence of such tests:
value = 0;
#define conv(s) do { if (!strcmp(str, #s)) value = s; } while (0)
conv(EINVAL);
conv(ENOMEM);
conv(ERANGE);
conv(EINTR);
#undef conv
A usual, be careful with the preprocessor...

could somebody give out some basic examples of this code? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I really don't understands this code:
#include <stdio.h>
int main (int argument c, char *argument v[])
{
return 0;
}
What does this code mean? How does it converts to other formation of coding?
This is (almost) the simplest C/C++ program. (It works for both languages.) It does nothing other than return 0, which signifies successful execution.
It should read
int main(int argc, char **argv)

Resources