On Sun, 13 Oct 2024 17:12:52 -0500
o1bigtenor via Dng <dng@???> wrote:
> 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!
Hi,
i suggest you should try to nicely align the output to add a little
more challenge. See man fprintf for hints how to do so.
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
Ciao,
Tito