如何在C ++中随机数生成1 ...... 100 [英] How to random number generation 1......100 in C++

查看:452
本文介绍了如何在C ++中随机数生成1 ...... 100的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include <iostream>
#include <cstdlib>
#include <conio.h>
using namespace std;
int source,No_Of_Nodes,No_Of_Edges,visited[20],Graph[20][20],Graph1[20][20];
int main()
{
    int i,j,vertex1,vertex2,cost;
    cout<<"\t\t\tGraphs\n";
    cout<<"Enter the no of Vertices : ";
    cin>>No_Of_Nodes;
    cout<<"Enter the no of Edges : ";
    cin>>No_Of_Edges;
    for(i=0;i<No_Of_Nodes;i++)
    {
     
		for(j=0;j<No_Of_Nodes;j++)
            Graph[i][j]=0;
    }
    for(i=0;i<No_Of_Edges;i++)
    {
        cout<<"Enter first : ";
        cin>>vertex1;
		cout<<"entre seconde : ";
		cin>>vertex2;
		cout<<"Enter the cost of : "<<vertex1<<" and "<<vertex2<<" ";
		cin>>cost;
	    Graph[vertex1-1][vertex2-1]=Graph[vertex2-1][vertex1-1]=cost;
		Graph1[vertex1-1][vertex2-1]=Graph1[vertex2-1][vertex1-1]=1;
    }
	cout<<"\nThe Matrix Adjacency is : \n"<<endl;
    for(i=0;i<No_Of_Nodes;i++)
    {
        for(j=0;j<No_Of_Nodes;j++)
			cout<<"\t"<<Graph1[i][j];
            cout<<"\n";
    }
	cout<<"\nThe Matrix bandwidth values is : \n"<<endl;
	  for(i=0;i<No_Of_Nodes;i++)
    {
        for(j=0;j<No_Of_Nodes;j++)
            cout<<"\t"<<Graph[i][j];
            cout<<"\n";
    }
		getch();
    return 0;
}





我的尝试:



输入长度图和节点源和节点目的地



What I have tried:

input lenght graph and node source and node destination

推荐答案

看来你在课堂上没有注意到。为了弥补这一点,你真的需要提高你的Google技能。 C ++随机数 [ ^ ]。
It appears you haven't been paying attention in class. To compensate for this, you really need to brush up on your Google skills. "C++ random number"[^].


看看srand和rand。 Srand种子RNG和rand返回随机值。
Have a look at srand and rand. Srand seeds the RNG and rand returns random values.


这篇关于如何在C ++中随机数生成1 ...... 100的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆