// c program to add 10 elements entered by the user
            #include <stdio.h>  
            int main ()
            {   
              int i;    
              float elements[10];       //declaring the array
              float sum = 0;

              for (i = 0; i < 10; ++i)
                {
                  printf ("Enter element %d: ", i + 1); //getting the elements from the user
                  scanf ("%f", &elements[i]);   //storing the elements
                  sum += elements[i];   //adding integers entered by the user to the sum variable

                }

              printf ("sum of above entered elements is : %.4f", sum);  //printing the sum to four decimal places
              return 0;
            }

kindly help because i have tried and tried but i could not get the exact output i wanted

Line 12 seems to input floats. But your reply now writes you can not get the exact output you wanted but didn't share what happened versus what you wanted.

     **   I tried to use *isdigit* but i could not get the the exact output i wanted **





         #include <stdio.h>
            #include<stdlib.h>
            #include<string.h>
            #include<time.h>
            #include<ctype.h>
            int main ()
            {   
              int i;    
              char elements[10];        //declaring the array
              float element;
              float sum = 0;

              for (i = 0; i < 10; ++i)
                {
                  printf ("Enter element %d: ", i + 1); //getting the elements from the user 
                  //fgets(elements[i], 10, stdin);
                  scanf ("%s", &(elements[i])); //storing the elements 

                  if (isdigit(elements[i]))
                 { 
                    element=atof(elements[i]);
                     sum += element;    //adding elements  entered by the user to the sum variable  
                 }
                else
                 {printf("invalid input()\n");
                     break;
                 }
                }

              printf ("sum of above entered elements is : %.4f", sum);  //printing the sum to four decimal places
              return 0;
            }

First you appear to have mark this solved.

Second, you mention "output" a second time yet you neglect to share what the output was and share what you wanted the output to be.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.