:: Re: [DNG] continuing in C programmi…
Pàgina inicial
Delete this message
Reply to this message
Autor: o1bigtenor
Data:  
CC: dng
Assumpte: Re: [DNG] continuing in C programming
On Sun, Oct 13, 2024 at 4:22 PM Marc Shapiro via Dng <dng@???> wrote:
>
> On 10/13/24 1:45 PM, 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?
>
> It's been a while since I used C, but... you have underscores in your
> printf call, so they are being treated as literals and being printed.
> Change those underscores to spaces, and I think you should be OK.
>
>

That did it - - - thank you for the help!