Last active
August 29, 2015 14:08
-
-
Save pizenblues/47a1e2d7d47f7171d208 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream.h> | |
#include <stdio.h> | |
using namespace std; | |
template <class T> | |
void read_input(T &var){ | |
while(! (cin>>var) ){ | |
printf(" \t \t ingrese un numero: "); | |
cin.clear(); | |
cin.ignore(256, '\n'); | |
}; | |
} | |
template <class T> | |
void read_char(T *var){ | |
while(! (std::cin>>var) ){ | |
// optional generic message, like 'wrong format, reinput' | |
std::cin.clear(); | |
std::cin.ignore(256, '\n'); | |
}; | |
} | |
int main(){ | |
char opc; | |
int tamano, multiple; | |
int fila = 1, columna = 1; | |
printf("\n\t cantidad de vertices "); | |
read_input(tamano); | |
int matriz[tamano][tamano]; | |
for(int i =0; i<tamano; i++) | |
for(int j = i; j<tamano; j++){ | |
fila = fila + i; | |
columna = columna + j; | |
printf("\n el vertice %i es adyacente al vertice %i (s/n): ", fila, columna); | |
read_char(opc); | |
if(opc == 's'){ | |
printf(" \n\t es multiple? (s/n): "); | |
cin>>opc; | |
if(opc == 's'){ | |
cout<<"\n\t cuantas veces?: "; | |
cin>>multiple; | |
matriz[i][j] = multiple; | |
matriz[j][i] = multiple; | |
}else{ | |
matriz[i][j] = 1; | |
matriz[j][i] = 1; | |
} | |
}else{ | |
matriz[i][j] = 0; | |
matriz[j][i] = 0; | |
} | |
fila = 1; | |
columna = 1; | |
} | |
system("cls"); | |
cout<<endl<<endl; | |
for(int i=0; i<tamano; i++){ | |
for(int j=0; j<tamano; j++){ | |
cout<<"\t"<<matriz[i][j]; | |
} | |
cout<<endl; | |
} | |
printf("menu"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment