O’ZBEKISTON RESPUBLIKASI AXBOROT TEXNOLOGIYALARI VA KOMMUNIKATSIYALARINI RIVOJLANTIRISH VAZIRLIGI
MUHAMMAD AL-XORAZMIY NOMIDAGI TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI SAMARQAND FILIALI
“KOMPYUTER INJINIRINGI” FAKULTETI
201-guruh talabasi
JONIQULOVA SADOQATNING
ALGORITMLARNI LOYIHALASH fanidan
LABORATORIYA MASHG`ULOTI
5-hafta.
Bajardi: Joniqulova S
Tekshirdi: Mamayev E
Berilgan topshiriqlar
Quyidagi nazariy savollarga javob bering
Graflar turlarini sanab bering.
To’liq graf, to’liqmas graf, yo’naltirilgan graf (orgraf), siklli(sirtmoq yoki halqali) graf,
2. Graflar qanday usullarda beriladi?
3. Grafning chekkalari ro'yxati qanday tuziladi?
4. Graf moslashuvi qanday hosil bo'ladi?
5. Grafning qo'shilish matritsasi qanday hosil bo'ladi?
6. Grafning tarqalish matritsasi qanday tuzilgan?
Quyidagi graf ko’rinishlari uchun matritsa quring va dastur kodini yozib natija oling.
1-masala: Grafning chekkalari ro’yxatini shakllantirish uchun dastur tuzing.
Dastur kodi:
#include
using namespace std;
int main(){
int n;
cout<<"Grafning tugunlari sonini kiriting: ";
cin>>n;
int k=0;
int a[n][n];
for(int i=0;ifor(int j=0;ja[i][j]=rand()%2;
if(a[i][j]==1){
k++;
}
}
}
cout<<"Graf tugunlarining bog'liqlik matritsasi:\n"<<"(Random 0 va1 lar bilan to'ldirildi.)\n";
for(int i=0;ifor(int j=0;jcout<cout<<" ";
}
cout<<"\n";
}
int l=k/2;
cout<<"\nBu grafning qirralari soni "<cout<<"JONIQULOVA SADOQAT 204";
return 0;
}
Natijasi:
2-masala: Grafga moslik yaratish uchun dastur tuzing.
Dastur kodi:
#include
#define infinity 999
void dij(int n, int v,int cost[20][20], int dist[]){
int i,u,count,w,flag[20],min;
for(i=1;i<=n;i++)
flag[i]=0, dist[i]=cost[v][i];
count=2;
while(count<=n){
min=99;
for(w=1;w<=n;w++)
if(dist[w]min=dist[w];
u=w;
}
flag[u]=1;
count++;
for(w=1;w<=n;w++)
if((dist[u]+cost[u][w]dist[w]=dist[u]+cost[u][w];
}
}
int main(){
int n,v,i,j,cost[20][20],dist[20];
printf("Grafning tugunlari sonini kiriting :");
scanf("%d",&n);
printf("\nGrafning matritsalari qiymatini kiriting :\n");
for(i=1;i<=n;i++)
for(j=1;j<=n;j++){
scanf("%d",&cost[i][j]);
if(cost[i][j] == 0)
cost[i][j]=infinity;
}
printf("\nBiror tugunni kiriting:");
scanf("%d",&v);
dij(n,v,cost,dist);
printf("\nBu tugundan qolgan tugunlargacha bolgan eng qisqa masofalar:\n");
for(i=1;i<=n;i++)
if(i!=v)
printf("%d->%d,cost=%d\n",v,i,dist[i]);
printf("208-G Nematov Akbarjon");
}
Natijasi:
3-masala Qavurgalar soni
Dastur kodi:
#include
using namespace std;
int main()
{
int n,m=0;
cout<<"Massiv sonini kiriting => ";
cin>>n;
int a[n][n];
for(int i=0;i
for(int j=0;jcin>>a[i][j];
for(int i=0;ifor(int j=0;jif(a[i][j]!=0)
m++;
cout<<" Qovurg'asi soni => "<cout<<"JONIQULOVA SADOQAT 204 ";
return 0;
}
Natijasi:
Do'stlaringiz bilan baham: |