Code:
#include<stdio.h>
#define p printf
trying to avoid typing four letters twice by typing #define p printf seems a lot of work to me, and it's naturally obfuscating your code.
And #include <stdio.h> should be before main() definition.
The example shown is definitely an example of "no need for pointers" here. But to make sensible and yet simple examples can be quite difficult. This might be one:
Code:
#include <stdio.h>
int main()
{
int array[5];
int *pMax, *pMin;
int i;
int sum;
printf("Enter 5 numbers with space between them:\n");
for(i = 0; i < 5; i++)
{
scanf("%d", &arr[i]);
}
// Now, find the max and min values:
pMax = &array[0];
pMin = &array[0];
for(i = 0; i < 5; i++)
{
if (*pMax > array[i])
pMax = &array[i];
if (*pMin < array[i])
pMin = &array[i];
sum += array[i];
}
sum -= *pMax + *pMin;
printf("Average of 5 items, less biggest and smallest: %5.2f\n",
sum / 3.0);
printf("Max = %d, min = %d\n", *pMax, *pMin);
return 0;
}
--
Mats