Graph

i have code like this :
#include <iostream.h>
#include <conio.h>
int main()
{
int simpul,garis=0;
char A[20];

cout<<"banyak simpul = ";
cin>>simpul;
cout<<endl;

for (int i=0; i<simpul; i++){
cout<<"Simpul ke "<<i+1;
cout<<" = ";
cin>>A[i];
}

cout<<"\nSisi-sinya = ";
for (int i=0; i<simpul; i++){
for (int j=i+1; j<simpul; j++){
cout<<" ";
cout<<A[i]<<A[j];
}
}
getch();
return 0;
}


and result if your input 5 simpul A, B, C, D, E => AB, AC, AD, AE, BC, BD, BE, CD, DE, CE.

i want result A-B = 10, A-C = 25, A-D = 30, A-E = 40, B-C = 30, B-D = 25, B-E = 40, C-D = 10, D-E = 15, C-E = 15. how can it be like that?
i want result A-B = 10, A-C = 25, A-D = 30, A-E = 40, B-C = 30, B-D = 25, B-E = 40, C-D = 10, D-E = 15, C-E = 15. how can it be like that?

What do you mean? You want the physical output to look like "A-B = 10" or do you want "AB" to be printed 10 times? Or something different?


if (1) alter the cout:

cout<<A[i]<< '-' <<A[j] << " = 10";


if (2) put an extra loop:

1
2
for (int i = 0; i < 10; i++)
cout<<A[i]<<A[j];
Yeah i mean like this :
A-B = 10, A-C = 25, A-D = 30, A-E = 40, B-C = 30, B-D = 25, B-E = 40, C-D = 10, D-E = 15, C-E = 15
Yeah i mean like this :
A-B = 10, A-C = 25, A-D = 30, A-E = 40, B-C = 30, B-D = 25, B-E = 40, C-D = 10, D-E = 15, C-E = 15


cout<<A[i]<< '-' <<A[j] << " = 10";

Is there some kind of connection between those numbers and the letters? If there isn't, you'll have to hard code the values yourself.


1
2
3
4
5
6
7
8
9
10
//Make an array to hold all the values you want to print:
int arr[10]{ 10, 25, 30, 40, 30, 25, 40, 10, 15, 15 };

int main()
{
        //Imagine your code is here and the for-loops


	cout << A[i] << '-' << A[j] << " = " << arr[i];
}


As long as you implement it correctly this should work.
Last edited on
Topic archived. No new replies allowed.