/* to find the age of individuals according to youngest to oldest */
#include <stdio.h>
int main(void){
int age1, age2, age3, youngest, middle, oldest;
printf ("Enter the age of the first individual: ");
scanf ("%d", &age1);
printf ("Enter the age of the second individual: ");
scanf ("%d", &age2);
printf ("Enter the age of the third individual: ");
scanf ("%d", &age3);
if ((age1 == age2) && (age2 == age3)){
printf("All individuals have the same age of %d", &age2);
}
else (age1 != age2) && (age1 != age3) && (age2 != age3);{
youngest = age1;
if (age1 > age2)
youngest = age2;
if (age2 > age3)
youngest = age3;
middle = age1;
if (age1 > age2)
middle = age2;
if (age2 < age3)
middle = age2;
oldest = age1;
if (age1 < age2)
oldest = age2;
if (age2 < age3)
oldest = age3;
printf("%d is the youngest.\n", youngest);
printf("%d is the middle.\n", middle);
printf("%d is the oldest.\n", oldest);
}
return 0;
}
嗨我改變了我的代碼,但顯示仍然顯示一個奇怪的數字,當我輸入每個人的相同年齡。我如何做到這一點,如果每個人都有同樣的年齡,那麼只有說所有人都有相同年齡的線。請幫助我作爲它的分級任務,並且即時遇到這個問題排序3個人的年齡
所有人的年齡都是63567321是最年輕的。 1是中間的。 1是最古老的。
'printf(「所有人的%d年齡都一樣」,&age2);'Remove'&' - >'printf(「所有人的年齡都是%d \ n」,age2);' – BLUEPIXY
請學習如何正確縮進你的代碼,我個人甚至不會嘗試閱讀代碼像那樣呈現。然後,這不是一個問題,而是你的調試器。 –
請勿[REPOST](https://stackoverflow.com/questions/45939540/sort-the-age-of-3-individuals)。 – gsamaras