stdying_to_happy

 

gcc task

task1

  #include <stdio.h>

   int SecondLargest(int *a,int size);
   int SecondLargest(int *a,int size)
   {
        for(int i = 0;i < 2; i++)
        {
            for (int j = 0;j < size - 1 - i ; j++)
            {
                if(a[j] > a[j+1])
                {
                    int temp;
                    temp = a[j+1];
                    a[j+1] = a[j];
                    a[j] = temp;
                }
            }
            
        }
        return a[size-2];
   }
   
  
  int main()
  {
    int A[5];
    int a, max2;
    for (int i = 0; i < 5; i++)
    {   
        scanf("%d",&a);
        A[i] = a;
    }
    
    max2 = SecondLargest(A, 5);
    printf("%d", max2);
    return 0;
  
  }

task2

_main.c

#include <stdio.h>
#include "mysort.h"

int main()
{
    double A[10], a;
    double *p;
    int size = 10;

    for (int i = 0; i < size; i++)
    {   
        scanf("%lf",&a);
        A[i] = a;
    }
    
    p = mysort(A, size);

    for (int i = 0; i < size-1; i++)
    {
        printf("%lf\n",*(p+i));

    }
    
}

mysort.h

double* mysort(double *a,int size);

mysort.c

#include "mysort.h"

   
   double* mysort(double *a,int size)
   {
        for(int i = 0;i < size - 1; i++)
        {
            for (int j = 0;j < size - 1 - i ; j++)
            {
                if(a[j] < a[j+1])
                {
                    int temp;
                    temp = a[j+1];
                    a[j+1] = a[j];
                    a[j] = temp;
                }
            }
            
        }
        return a;
   }

posted on 2022-03-06 21:30  stdying_to_happy  阅读(32)  评论(0编辑  收藏  举报

导航