נשלח בתאריך: 15 December 2008 בשעה 14:59 | | IP רשוּם
|
|
|
|
אני צריך להמיר את התרגיל שעשיתי ללולאה של WHILE או FOR אשמח לדעת מאיזה מקטע בתכנית עליי להתחיל.
תודה #include <stdio.h>
void main() { int sum = 0 ; int max1 = 0, max2 = 0, min1 = 0, min2 = 0 ; int maxdif = 0, mindif = 0 , tmp ; int n1, n2, n3, n4, n5, n6, n7, n8 ;
printf("Get 8 Number In Ordered List : \n"); scanf("%d", &n1); flushall(); scanf("%d", &n2); flushall(); scanf("%d", &n3); flushall(); scanf("%d", &n4); flushall(); scanf("%d", &n5); flushall(); scanf("%d", &n6); flushall(); scanf("%d", &n7); flushall(); scanf("%d", &n8); flushall();
tmp = n2 - n1 ; maxdif = tmp ; mindif = tmp ; max1 = n1 ; max2 = n2 ; min1 = n1 ; min2 = n2 ; sum = n2 + n1 ;
tmp = n3 - n2 ; for (maxdif < tmp); { //*for loop*// maxdif = tmp; max1 = n2 ; max2 = n3 ;
for (mindif > tmp) { mindif = tmp ; min1 = n2 ; min2 = n3 ; } sum = sum + n3 ;
tmp = n4 - n3 ; if (maxdif < tmp) { maxdif = tmp ; max1 = n3 ; max2 = n4 ; } if (mindif > tmp) { mindif = tmp ; min1 = n3 ; min2 = n4 ; } sum = sum + n4 ;
tmp = n5 - n4 ; if (maxdif < tmp) { maxdif = tmp ; max1 = n4 ; max2 = n5 ; } if (mindif > tmp) { mindif = tmp ; min1 = n4 ; min2 = n5 ; } sum = sum + n5 ;
tmp = n6 - n5 ; if (maxdif < tmp) { maxdif = tmp ; max1 = n5 ; max2 = n6 ; } if (mindif > tmp) { mindif = tmp ; min1 = n5 ; min2 = n6 ; } sum = sum + n6 ;
tmp = n7 - n6 ; if (maxdif < tmp) { maxdif = tmp ; max1 = n6 ; max2 = n7 ; } if (mindif > tmp) { mindif = tmp ; min1 = n6 ; min2 = n7 ; } sum = sum + n7 ;
tmp = n8 - n7 ; if (maxdif < tmp) { maxdif = tmp ; max1 = n7 ; max2 = n8 ; } if (mindif > tmp) { mindif = tmp ; min1 = n7 ; min2 = n8 ; } sum = sum + n8 ;
printf("The Sum Of The Given Numbers Is : %d \n", sum ); printf("The Avg Of The Given Numbers Is : %f \n", sum/8.0 ); printf("The Max Diff Of The Given Numbers Is : %d Max1 %d Max2 %d \n", maxdif, max1, max2); printf("The Min Diff Of The Given Numbers Is : %d Mon1 %d Min2 %d \n", mindif, min1, min2); }
|