I am having problem getting the final result here, it keeps on looping.

#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
#include<ctype.h>
int main()

{


        int i,  t, k, max, min, sumof;
        printf("Enter number of integer elements in array: ");
       scanf("%d",&t);


       int a[t];

      printf("Enter list of array: \n");
      for ( i = 0; i < t ; i++)
      {
      scanf("%d",&a[i]);
      fflush(stdin);
         }


         // search for secound first and second last number in array 
         // t-1 = second last and t-2 = secound first#
         k=1;
          for (i = 0; i < t; i++)

          {
             if (k==(t-(t-2)))
            {
                printf("\n The second first number is %d",a[i]);
            }
            k++;
          }


         k=1;
          for (i = 0; i < t; i++)

          { 

            if (k==(t-1))
            {
                printf("\nthe second last number is %d",a[i]);
            }
             k++;
          }

      //for maximum
      max=a[0];
      for (i = 0; i < t; i++)
      {

             if (a[i]> max )
                         max = a[i];
      }

          printf("\n  maximum is %d \n", max);


      //for minimum
      min=a[0];
      for (i = 0; i < t; i++)
      {

             if (a[i]< min )
                         min = a[i];
      }

      printf(" \n minimum is %d\n ", min);


      sumof = 0;
    for (i = 0; i < t; i++)
    {

            sumof = sumof + a[i];
        }   
            printf (" \n sum of array  is %d\n ", sumof);



      return 0;
}

// t-1 = second last and t-2 = secound first

What?? The second last is t-2, the second first is 1. Why do you need loops to find the second last and second first numbers?

Sometimes ... the obvious ... is alarmingly simple ... when you 'see' it :)

C arrays start at index 0, so next in, from front, has index 1,

and ... the last index is size-1 (if size > 0 ),

so next to last index is size-2 (if size > 1)

No what i meant was the program those does terminate. If i run it.

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.