-
March 15th, 2004, 02:27 AM
#1
Member
C Programming
Hi All
Does anyone know what the sourcecode in C would be for the following program ? .
it simply has to display the following table.
1 2 3 4 5 6 7 8 9 10
1 - 23 12 89 456 123 46 732 345 123
2 23 - 46 234 123 46 89 234 567 90
3 12 46 - 767 456 46 234 123 732 35
4 89 234 767 - 732 32 48 67 98 100
5 456 123 456 732 - 234 46 89 89 732
6 123 46 46 32 234 - 123 46 123 234
7 46 89 234 48 46 123 - 46 89 19
8 732 234 123 67 89 46 46 - 123 732
9 345 567 732 98 89 123 89 123 - 78
10 123 90 35 100 732 234 19 732 78 -
thanks
-
March 15th, 2004, 07:28 AM
#2
what exactly is this matrix are they random numbers or does they mean anything. you can meke a matrix in C using two nested" For " loops . Something like this:
Code:
#include<stdio.h>
#include<conio.h>
void main(void)
{
int i,j;
clrscr();
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
printf("%d\t",j);
}
printf("\n");
}
getch();
}
If you want the user to enter the values for the Matrix you can use a two dimensional array to store those valuse and then ptint the array it could be something like this
Code:
#include<stdio.h>
#include<conio.h>
void main(void)
{
int num[2][2],i,j;
clrscr();
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf("Enter the Number to be Displayed :");
scanf("%d",&num[i][j]);
}
}
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf("%d ",num[i][j]);
}
printf("\n");
}
getch();
}
-
April 10th, 2004, 06:02 PM
#3
Junior Member
Actually, I see a pattern in the matrix.
Filling in some 0:s makes it easier to see:
000 023 012 089 456 123 046 732 345 123
023 000 046 234 123 046 089 234 567 090
012 046 000 767 456 046 234 123 732 035
089 234 767 000 732 032 048 067 098 100
456 123 456 732 000 234 046 089 089 732
123 046 046 032 234 000 123 046 123 234
046 089 234 048 046 123 000 046 089 019
732 234 123 067 089 046 046 000 123 732
345 567 732 098 089 123 089 123 000 078
123 090 035 100 732 234 019 732 078 000
The positions (row,column) and (column,row) has the same value, and when row = column, the value is 0.
So position 3,2 has the same value as position 2,3, and position 1,1, 2,2, 3,3 etc is 0.
Use this information to alter swordfish's program to suit your needs. Its good practice...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|