Beispiel #1
0
int main(int argc, char* argv[]){

	if(argc == 1){
		printf("No elements entered\n");
		printf("usage ./largest [list of numbers: 1 2 3 4]\n");
		return 0;
	}
	int size = argc - 1;
	int fst = 0;
	int snd = 0;
	int i = 1;
	//allocateing size of argc into *in, init everything to zero with calloc
	int* in = (int*) calloc((size), sizeof(int));
	/*
	I really should error check for values that will break atoi()...
	*/
	while(i < argc){
		*(in + (i - 1)) = atoi(*(argv+i));//convert argv elements into ints
		i++;
	}

	find_two_largest(in, size, &fst, &snd);
	printf("Two largest elements entered: %d, %d\n", fst, snd);
	free(in);
	return 0;
}
int main()
{
	int num[N]={1,4,5,6,9},largest,second_largest,i;
    printf("随意一个数组为:\n");
    for(i=0;i<N;i++)
    printf("%d,",num[i]);
	find_two_largest(num,N,&largest,&second_largest);
	printf("\n");
	printf("最大的数是%d 第二大的数是%d \n",largest,second_largest);
	return 0;
}
Beispiel #3
0
int main(void)
{
  //int size_t = sizeof(a) / sizeof(a[0]);
  int first, second;

  find_two_largest(b, N, &first, &second);

  printf("Largest value is: %d\n", first);
  printf("Second largest is: %d\n", second);

  return 0;
}
Beispiel #4
0
int main()
{
    int a[100];
    int n;
    int l,sl;
    printf("Enter the total number of elements=>");
    scanf("%d",&n);
    if(n>100)
        printf("Error: number of elemets must be less than 100");
    else
    {
        for(int i=0; i<n; i++)
        {
            scanf("%d",&a[i]);
        }
        find_two_largest(a,n,&l,&sl);
        printf("largest=%d\nsecond largest=%d",l,sl);
    }
    getch();

}
int main(void)
{
	/*
	int a, b;
	
	printf("Enter a: "); scanf("%d", &a);
	printf("Enter b: "); scanf("%d", &b);
	
	printf("\na = %d, b = %d\n", a, b);
	
	printf("\nSwapping...\n");
	swap(&a, &b);
	
	printf("\na = %d, b = %d\n", a, b);
	*/
	int a[4] = {5, 5, 4, 1}; //{3, 3, 2, 1};
	int big, big2;
	find_two_largest(a, 4, &big, &big2);
	
	printf("Largest: %d\nSecond largest: %d\n", big, big2);
	return 0;
}