:: Re: [DNG] continuing in C programmi…
Etusivu
Poista viesti
Vastaa
Lähettäjä: Dan Purgert
Päiväys:  
Vastaanottaja: dng
Aihe: Re: [DNG] continuing in C programming
On Oct 13, 2024, o1bigtenor via Dng wrote:
> Greetings
>
> (using gcc compiler - - just in case that makes a difference
>    book is 'Modern C')

>
> program is :
>
> /* This may look like nonsense, but really is -*- mode: C -*- */
> #include <stdlib.h>
> #include <stdio.h>
>
> /* The main thins that is program does. */
> int main(void) {
>    //Declarations
>    double A[5] = {
>       [0] = 9.0,
>       [1] = 2.9,
>       [4] = 3.E+25,
>       [3] = .00007,
>    };

>
>    //Doing some work
>    for (size_t i=0; i < 5; ++i) {
>       printf("element_%zu_is_%g,_\tits_square_is_%g\n",
>              i,
>              A[i],
>              A[i]*A[i]);
>    }

>
>    return EXIT_SUCCESS;
> }

>
> When I run it I'm getting :
>
> $ ./firstprogram
> element_0_is_9,_    its_square_is_81
> element_1_is_2.9,_    its_square_is_8.41
> element_2_is_0,_    its_square_is_0
> element_3_is_7e-05,_    its_square_is_4.9e-09
> element_4_is_3e+25,_    its_square_is_9e+50

>
> I don't think all the underscores are supposed to be there - - - what
> did I do wrong?


You put them there ...

      printf("element_%zu_is_%g,_\tits_square_is_%g\n",


If you don't want them:

      printf("element %zu is %g,\tits square is %g\n",



--
|_|O|_|
|_|_|O| Github: https://github.com/dpurgert
|O|O|O| PGP: DDAB 23FB 19FA 7D85 1CC1 E067 6D65 70E5 4CE7 2860