•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 429,898 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,348 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 215 | Replies: 3
![]() |
#include<stdio.h>
#include<conio.h>
#define MAX_ROWS 10
#define MAX_COLS 10
void add(int a[][MAX_COLS], int b[][MAX_COLS], int result[][MAX_COLS]);
void displayValues(int(*)[MAX_COLS]);
void diff(int a[][MAX_COLS], int b[][MAX_COLS], int result[][MAX_COLS]);
void main()
{
int val;
int i,j;
int choice;
int cols,rows;
int operation;
int table1[MAX_ROWS][MAX_COLS];
int table2[MAX_ROWS][MAX_COLS];
int result[MAX_ROWS][MAX_COLS];
clrscr();
printf("Press 1 to enter values for Table1... ");
scanf("%d", &choice);
if(choice==1)
{
printf("Enter no.of rows: ");
scanf("%d", &rows);
printf("Enter no. of cols: ");
scanf("%d" ,&cols);
if(rows<=MAX_ROWS && cols<=MAX_COLS)
{
printf("\nTable Created\n");
for(i=0;i<rows;i++)
{
for(j=0;j<cols;j++)
{
printf("\nEnter value for ROW %d, COL %d: ",i,j); //user input row x col
scanf("%d", &val);
table1[i] [j]=val;
}
}
printf("\n");
} //END IF
}
printf("Press 2 to enter values for Table2... ");
scanf("%d", &choice);
if(choice==2)
{
printf("Enter no.of rows: ");
scanf("%d", &rows);
printf("Enter no. of cols: ");
scanf("%d" ,&cols);
if(rows<=MAX_ROWS && cols<=MAX_COLS)
{
printf("\nTable Created\n");
for(i=0;i<rows;i++)
{
for(j=0;j<cols;j++)
{
printf("\nEnter value for ROW %d, COL %d: ",i,j); //user input row x col
scanf("%d", &val);
table2[i][j]=val;
}
}
printf("\n");
} //END IF
}
printf("Generated table......\n");
for(i=0;i<rows;i++)
{
for(j=0;j<cols;j++)
{
printf("%3d ", table1[i] [j]);
}
printf("\n");
}
printf("\n");
for(i=0;i<rows;i++)
{
for(j=0;j<cols;j++)
{
printf("%3d ", table2[i] [j]);
}
printf("\n");
}
/////////*** FOR THE MENU*****/////
printf("\n");
printf("---MENU---\n");
printf("1. Addition");
printf("\n2. Subtraction");
printf("\n3. Multiplication\n");
printf("Enter Operation: ");
scanf("%d", &operation);
switch(operation)
{
case 1: printf("The sum of 2 matrices is:\n");
add(table1,table2,result);
break;
case 2: printf("The Difference of 2 matrices is:\n");
diff(table1,table2,result);
break;
}
getch();
} //END MAIN
void add(int a[][MAX_COLS], int b[][MAX_COLS], int result[][MAX_COLS])
{
int i,j;
for (i=0;i<MAX_ROWS;i++)
{
for(j=0;j<MAX_COLS;j++)
{
result[i][j]=a[i][j]+b[i][j];
}
}
displayValues(result);
}
void displayValues(int(*t)[MAX_COLS]) //read and display elements
{
int i,j;
for(i=0;i<MAX_ROWS;i++)
{
for(j=0;j<MAX_COLS;j++)
{
printf("%4d ", t[i][j]);
}
printf("\n");
}
}
void diff(int a[][MAX_COLS], int b[][MAX_COLS], int result[][MAX_COLS])
{
int i,j;
for(i=0;i<MAX_ROWS;i++)
{
for(j=0;j<MAX_COLS;j++)
{
result[i][j]=a[i][j]-b[i][j];
}
}
displayValues(result);
}***when i run it, the 3rd matrix displays a lot of numbers, and i still have to multiply them. please help.
You know, I was going to help you, because this is an easy problem...
But then i get here and see not a single code block or conditional statement is indented. I mean, look at your code, look at all those opening and closing braces lined up like little tiny firing squad victims against a wall.
Does this look good to you? Does this look readable? And you're not the only one, by any stretch ... this happens all the time. What is wrong with you people?
More importantly, what is wrong with your instructors? What kind of professional lets you get away with writing code like this?
Or am i just going insane? Can you hear the sound of my head banging against particle board?
.
But then i get here and see not a single code block or conditional statement is indented. I mean, look at your code, look at all those opening and closing braces lined up like little tiny firing squad victims against a wall.
Does this look good to you? Does this look readable? And you're not the only one, by any stretch ... this happens all the time. What is wrong with you people?
More importantly, what is wrong with your instructors? What kind of professional lets you get away with writing code like this?
Or am i just going insane? Can you hear the sound of my head banging against particle board?
.
Last edited by jephthah : May 16th, 2008 at 2:10 pm.
Why so serious?
•
•
Join Date: May 2008
Location: Infinite Castle, below Beltline
Posts: 287
Reputation:
Rep Power: 1
Solved Threads: 24
Well, I would like to start by giving the same advice I recived here. Dont use conio.h and the turbo c compiler.
And Never Ever Use void main() search void main in this website & you woud know why.
And as for your question, you read values till rows & cols & print the answers till MAX_ROWS & MAX_COLS
And finaly, you should learn to intend as jephthah said It will help you a lot.
And Never Ever Use void main() search void main in this website & you woud know why.
And as for your question, you read values till rows & cols & print the answers till MAX_ROWS & MAX_COLS
And finaly, you should learn to intend as jephthah said It will help you a lot.
![]() |
•
•
•
•
•
•
•
•
DaniWeb C Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- The Matrix & Philosophy (Geeks' Lounge)
- I need help with matrix....please!!! (Java)
- I MUST HAVE this Microsoft - Matrix video with Bill Gates + Steve Ballmer from Comdex (Geeks' Lounge)
- Enter the Matrix-not working (Windows NT / 2000 / XP / 2003)
- MATRIX REVOLUTIONS in the IMAX (Geeks' Lounge)
- Microsoft Releases Web Matrix (ASP.NET)
Other Threads in the C Forum
- Previous Thread: Help with doing loops
- Next Thread: Adding, Storing and Accessing Records


Linear Mode