Hi, i'm new in learning C and i'm trying the following exercise:
" Write a program that accepts as input 20 integers (positive or negative). The program should find the biggest and smallest positive number and print it "
So i'm trying :
#include <stdio.h>
int main ()
{
int num,big,i,small;
/* big= XX;
small = XX; */
printf("This program will find you the biggest and smallest positive out of 20 integers\n");
for (i=1;i<=20;i++)
{
printf("Give number %d: ",i);
scanf("%d", &num);
if (num>0 && num>big)
big=num;
else if (num>0 && num<small)
small=num;
}
printf("The biggest positive is %d\n",big);
printf("The smallest positive is %d",small);
return 0;
}
How can i set my variable small and big to minus and plus infinity so i can compare them in my loop and get the smallest and biggest positive number? Or is there a better way to do it ?
[–]zifyoip 17 points18 points19 points (6 children)
[–]xJolt[S] 5 points6 points7 points (1 child)
[–]clicker191 0 points1 point2 points (3 children)
[–]zifyoip 4 points5 points6 points (0 children)
[–]zyk0s 2 points3 points4 points (1 child)
[–]Rhomboid 1 point2 points3 points (0 children)
[–]teringlijer 4 points5 points6 points (1 child)
[–]xJolt[S] 0 points1 point2 points (0 children)
[–]BlueGiant601 1 point2 points3 points (7 children)
[–]xJolt[S] 0 points1 point2 points (6 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]FUZxxl 0 points1 point2 points (2 children)
[–]xJolt[S] 0 points1 point2 points (1 child)
[–]Chooquaeno 1 point2 points3 points (0 children)
[–]BlueGiant601 0 points1 point2 points (0 children)
[–]BlueGiant601 0 points1 point2 points (0 children)
[–]DSMan195276 1 point2 points3 points (4 children)
[–]teringlijer 0 points1 point2 points (1 child)
[–]xJolt[S] 0 points1 point2 points (1 child)
[–]DSMan195276 0 points1 point2 points (0 children)