Algoritmlarni loyihalash
Dasturimizga qiyamatni dinamik holatda bersak quyidagi natijalarga erishamiz
Download 344.54 Kb.
|
Algaritmlash Oraliq Nazorat ishi 1
- Bu sahifa navigatsiya:
- Dastur Natijasi
- 1 , 2 , 3.Agar dasturimizga qiymatni statik holatda bersak quyidagi masofa yog`indilariga ega bo`larkanmiz. Dastur kodi
Dasturimizga qiyamatni dinamik holatda bersak quyidagi natijalarga erishamiz. Dastur kodi: #define _CRT_SECURE_NO_WARNINGS #include #include #define SIZE 7 #include int main() { int a[SIZE][SIZE]; int d[SIZE]; int v[SIZE]; int temp, minindex, min; int begin_index = 0; system("chcp 1251"); system("cls"); for (int i = 0; i {
a[i][i] = 0; printf("Orasidagi masofani kiriting: %d - %d: ", i + 1, j + 1); scanf("%d", &temp);
a[i][j] = temp; a[j][i] = temp;
}
} {
for (int j = 0; j printf("\n"); }
for (int i = 0; i d[i] = 10000; v[i] = 1;
}
d[begin_index] = 0; minindex = 10000; min = 10000; for (int i = 0; i {
if ((v[i] == 1) && (d[i] min = d[i]; minindex = i;
}
} { for (int i = 0; i if (a[minindex][i] > 0) { temp = min + a[minindex][i]; if (temp < d[i]) { d[i] = temp; } } } v[minindex] = 0; } } while (minindex < 10000); printf("\nYuqori nuqtagacha bolgan masofa: \n"); for (int i = 0; i printf("%5d ", d[i]);
int ver[SIZE]; int end = 4;
ver[0] = end + 1; int k = 1;
int weight = d[end]; while (end != begin_index)
{
for (int i = 0; i {
int temp = weight - a[i][end]; {
weight = temp; end = i; ver[k] = i + 1; k++;
} } } printf("\nChiqi yaqin bo`ldan\n"); for (int i = k - 1; i >= 0; i--) printf("%3d " , ver[i]); getchar(); getchar(); return 0; }
1 , 2 , 3.Agar dasturimizga qiymatni statik holatda bersak quyidagi masofa yog`indilariga ega bo`larkanmiz. Dastur kodi: #define _CRT_SECURE_NO_WARNINGS #include #include #define SIZE 7 #include int main() { int d[SIZE]; int v[SIZE]; int temp, minindex, min; int begin_index = 0; system("chcp 1251"); system("cls"); /*0 1 2 3 4 5 6*/ int a[SIZE][SIZE] = {/*0*/{ 0, 0,21,71, 0, 0,63 }, /*1*/{ 0, 0, 9,83, 7, 0,70 }, /*2*/{21, 9, 0, 0, 0,18, 0 }, /*3*/{71,83, 0, 0,57,87,93 }, /*4*/{ 0, 7, 0,57, 0, 6,59 }, /*5*/{ 0, 0,18,87, 6, 0,66 }, /*6*/{63,70, 0,93,59,66, 0 } };; for (int i = 0; i {
for (int j = 0; j printf("\n"); }
for (int i = 0; i d[i] = 10000; v[i] = 1;
}
d[begin_index] = 0; minindex = 10000; min = 10000; for (int i = 0; i {
if ((v[i] == 1) && (d[i] min = d[i]; minindex = i;
}
} { for (int i = 0; i if (a[minindex][i] > 0) { temp = min + a[minindex][i]; if (temp < d[i]) { d[i] = temp; } } } v[minindex] = 0; } } while (minindex < 10000); printf("\nYuqori nuqtagacha bolgan masofa: \n"); for (int i = 0; i printf("%5d ", d[i]);
int ver[SIZE]; int end = 4;
ver[0] = end + 1; int k = 1;
int weight = d[end]; while (end != begin_index)
{
for (int i = 0; i {
int temp = weight - a[i][end]; {
weight = temp; end = i; ver[k] = i + 1; k++;
} } } printf("\nChiqish yaqin bo`ldigan nuqtagacha:\n"); for (int i = k - 1; i >= 0; i--) printf("%3d " , ver[i]); getchar(); getchar(); return 0; }
Ikkala Statik va dinamik qiymat berganimizda ham bir hil qiymat oldik. Download 344.54 Kb. Do'stlaringiz bilan baham: |
ma'muriyatiga murojaat qiling