Advertisement
patryk

Tworzenie grafu

Apr 16th, 2014
443
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include <iostream>
  2. #include<stdio.h>
  3. #include<conio.h>
  4. #include<stdlib.h>
  5. #include<math.h>
  6. #include<fstream>
  7. #include<time.h>
  8. #define N 100
  9.  
  10. using namespace std;
  11.  
  12. int tab[1000][1000];
  13.  
  14. void CreateGraph(){
  15.     int i, j, k, maks;
  16.     int nasycenie = 60;
  17.     srand(time(NULL));
  18.     maks = floor(N*N*nasycenie/100);
  19.     k=0;
  20.     while(k<maks){
  21.         i = rand() %N + 1;
  22.         j = rand() %N + 1;
  23.         if((tab[i][j] == 0) && (i != j)){
  24.             tab[i][j] = 1;
  25.             tab[j][i] = 1;
  26.             k+=2;
  27.         }
  28.     }
  29. }
  30.  
  31. int main()
  32. {
  33.     CreateGraph();
  34.     fstream plik;
  35.     plik.open("dane.txt", ios::out | ios::app);
  36.     if(plik.good() == true){
  37.         for(int i=1; i<=N; i++){
  38.             for(int j=1; j<=N; j++)
  39.                 if(tab[i][j] == 1) plik << i << "\t" << j << endl;
  40.         }
  41.         plik.close();
  42.     }
  43.     getch();
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement