1. Input 5 numbers on the keyboard to output the largest and smallest elements and their subscript.
# Include
Int main (void)
{
Int I, j, k, max, min;
Int a [10] = {0 };
Printf ("input number :");
For (I = 0; I <5; I ++)
Scanf ("% d", & a [I]);
Max = min = a [0];
J = k = 0;
For (I = 0; I <5; I ++)
{
If (max <a [I])
{
Max = a [I];
J = I;
}
Else if (min> a [I])
{
Min = a [I];
K = I;
}
}
Printf ("% d \ n", j, max, k, min );
Return 0;
}
2. Enter 16 integers on the keyboard and save them to the two-dimensional array 4*4 to output the elements of even rows and even columns.
# Include
Int main (void)
{
Int a [5] [5] = {0 };
Int I, j;
Printf ("input numbers :");
For (I = 0; I <4; I ++)
For (j = 0; j <4; j ++)
Scanf ("% d", & a [I] [j]);
For (I = 0; I <4; I ++)
For (j = 0; j <4; j ++)
{
If (I % 2 = 0 & j % 2 = 0)
Printf ("% d \ n", a [I] [j]);
}
Return 0;
}
3. In an ordered array, enter a number. If this number exists, the output number and its position are displayed. If this number does not exist, the output information is displayed.
# Include
# Define M 10
Int main (void)
{
Int a [M] = };
Int n; // The number of queries.
Int low, high, mid;
Int found;
Low = 0;
High = M-1;
Found = 0;
Printf ("input n :");
Scanf ("% d", & n );
While (low <= high)
{
Mid = (low + high)/2;
If (n = a [mid])
{
Found = 1;
Break;
}
Else if (n <a [mid])
High = mid-1;
Else
Low = mid + 1;
}
If (found = 1)
Printf ("index of % d is % d", n, mid );
Else
Printf ("there is not % d", n );
Return 0;
}