So i am trying to get creative and solve this but for some reason when trying to find the largest number i find the lowest when trying to find the lowest i find the largest and when trying to find unsigned i get stuck in a loop.
// Second part
// setting variable with startup values
short x1 = 0;
// Printing startup value
printf("short x1 is currently %d\n", x1);
// Loop to find highest number allowed for short
printf("\nSigned Short:\n");
x1 = 0;
for (x1 = 0; x1 - 1 < !(abs(x1)) ; x1--){
if (x1 - 1 == x1) {
break;
}
}
printf("The largest number the short x1 can hold is %d\n", x1);
// Loop to find lowest number allowed for short
x1 = 0;
for (x1 = 0; x1 + 1 > abs(x1); x1++){
if (x1 + 1 == x1){
break;
}
}
// i get a problem with the abs command, says implicit declaration of function although it works so ???
printf("The smallest number the short x1 can hold is %d\n", x1);
printf("\nUnsigned short:\n");
// loop to find highest for unsigned short. Unfortunately unlike the first 2 i can't make it find it without inputting a numbered roof :( wanted it to solve itself but cant get it right.
unsigned short x2 = 0;
for (x2 = 0; x2 + 1 > x2; x2++) {
if (x2 + 1 == 65536) {
break ;
}
}
printf("The largest numb er the signed short x2 can hold is %d\n", x2);
for (x2 = 0; x2 - 1 > x2; x2--) {
if (x2 - 1 == 65536) {
break ;
}
printf("%d\n",x2);
}
printf("The largest numb er the signed short x2 can hold is %d\n", x2);
Any help on how i could have solved this without creating a cap and why the abs thing says implicit function but works none the less?