0

i appreciate it if you would help me with this problem which i am struggling since 2 days.

i am using vs code and c.

i am trying to do some calculation on floating integers with more than 10 digits precision. so i added gmp.h . but just a simple code will end up with this error:

prelaunchtask'c/c++:gcc.exe build active file' terminated with exit code -1.

but vs code does not shows what is the problems.

my code from this source:"https://home.cs.colorado.edu/~srirams/courses/csci2824-spr14/gmpTutorial.html":

enter image description here

#include <gmp.h>
#include <stdio.h>
#include <assert.h>

int main(){

 char inputStr[1024];
  
     //mpz_t is the type defined for GMP integers.
    // It is a pointer to the internals of the GMP integer data structure
  
  mpz_t n;
  int flag;

  printf ("Enter your number: ");
  scanf("%1023s" , inputStr); /* NOTE: never every write a call scanf ("%s", inputStr);
                                  You are leaving a security hole in your code. */

  // 1. Initialize the number 
  mpz_init(n);
  mpz_set_ui(n,0);

 // 2. Parse the input string as a base 10 number
  flag = mpz_set_str(n,inputStr, 10);
  assert (flag == 0); //If flag is not 0 then the operation failed 

  // Print n 
  printf ("n = ");
  mpz_out_str(stdout,10,n);
  printf ("\n");

  // 3. Add one to the number 

  mpz_add_ui(n,n,1); //n = n + 1 

  // 4. Print the result 

  printf (" n +1 = ");
  mpz_out_str(stdout,10,n);
  printf ("\n");


  // 5. Square n+1

  mpz_mul(n,n,n); // n = n * n 


  printf (" (n +1)^2 = ");
  mpz_out_str(stdout,10,n);
  printf ("\n");


  // 6. Clean up the mpz_t handles or else we will leak memory 
  mpz_clear(n);

}

i have tried to run the code on other environments like code blocks but other error occurs.

i actually have some times the same problem when i try to add header files to my project.

enter image description here

pokemon
  • 1
  • 1
  • 1
    See https://stackoverflow.com/q/64519454/1216776 – stark Jun 07 '23 at 13:24
  • 1
    Please post code, errors, sample data or textual output here as plain-text, not as images that can be hard to read, can’t be copy-pasted to help test code or use in answers, and are barrier to those who depend on screen readers or translation tools. You can edit your question to add the code in the body of your question. For easy formatting use the `{}` button to mark blocks of code, or indent with four spaces for the same effect. The contents of a **screenshot can’t be searched, run as code, or easily copied and edited to create a solution.** – tadman Jun 07 '23 at 14:43

0 Answers0