| | |
A Small Problem ....plz Help Me Out....
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2004
Posts: 47
Reputation:
Solved Threads: 0
hi
"this program is for adding 2 tables with 3 rows and 4 columns" ....
so i have done like this......
#include<stdio.h>
#include<conio.h>
void main()
{
int a[3][4],b[3][4],c[3][4];
int i,j;
clrscr();
printf("\nENTER AN ARRAY:");
printf("\n\nFIRST TABLE:");
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("\nENTER AN ARRAY:");
printf("\n\nSECOND TABLE:");
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("\nENTER AN ARRAY:");
printf("\nSUM OF TABLES:");
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{
printf("%4d",c[i][j]);
c[i][j]=a[i][j]+b[i][j];
printf("\n");
}
}
getch();
}
"this program is for adding 2 tables with 3 rows and 4 columns" ....
so i have done like this......
#include<stdio.h>
#include<conio.h>
void main()
{
int a[3][4],b[3][4],c[3][4];
int i,j;
clrscr();
printf("\nENTER AN ARRAY:");
printf("\n\nFIRST TABLE:");
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("\nENTER AN ARRAY:");
printf("\n\nSECOND TABLE:");
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("\nENTER AN ARRAY:");
printf("\nSUM OF TABLES:");
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{
printf("%4d",c[i][j]);
c[i][j]=a[i][j]+b[i][j];
printf("\n");
}
}
getch();
}
•
•
Join Date: Oct 2004
Posts: 47
Reputation:
Solved Threads: 0
But When I Run This Code.....then Here I Have To Print The Sum Of 2 Tables...
First Table:
1 2 3 4
5 6 7 8
9 10 11 12
Second Table:
10 11 12 13
14 15 16 17
18 19 20 21
Then It Prints The Sum.....exactly..the Way It Should....but Not In That Format Of Table.....
But Like....
11
13
15
17
19
21
23
25
27
29
31
33
In A Single Line......now What Do I Do....?to Make It Print Like That The Other 2 Tables Are....in 3 Rows And 4 Columns....plz Help Me Out....and Guide Me Here/////
First Table:
1 2 3 4
5 6 7 8
9 10 11 12
Second Table:
10 11 12 13
14 15 16 17
18 19 20 21
Then It Prints The Sum.....exactly..the Way It Should....but Not In That Format Of Table.....
But Like....
11
13
15
17
19
21
23
25
27
29
31
33
In A Single Line......now What Do I Do....?to Make It Print Like That The Other 2 Tables Are....in 3 Rows And 4 Columns....plz Help Me Out....and Guide Me Here/////
I think you should move the printf ("\n"); outside of one of the 2 for loops:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[3][4],b[3][4],c[3][4];
int i,j;
clrscr();
printf("\nENTER AN ARRAY:");
printf("\n\nFIRST TABLE:");
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("\nENTER AN ARRAY:");
printf("\n\nSECOND TABLE:");
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("\nENTER AN ARRAY:");
printf("\nSUM OF TABLES:");
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{
printf("%4d ",c[i][j]);
c[i][j]=a[i][j]+b[i][j];
}
printf("\n");
}
getch();
} Greetings,
There are a few issues with the program. Nothing major though.
Firstly, frrossk showed the first issue. The new line should only take place after the first loop is continuing, not the second loop. Also, the lines of: Try flipping the two codes around: It would do no good to display a variable and then set it.
- Stack Overflow
There are a few issues with the program. Nothing major though.
Firstly, frrossk showed the first issue. The new line should only take place after the first loop is continuing, not the second loop. Also, the lines of:
C Syntax (Toggle Plain Text)
printf("%4d ",c[i][j]); c[i][j]=a[i][j]+b[i][j];
C Syntax (Toggle Plain Text)
c[i][j]=a[i][j]+b[i][j]; printf("%4d ",c[i][j]);
- Stack Overflow
Following the rules will ensure you get a prompt answer to your question. If posting code, please include BB [code][/code] tags. Your question may have been asked before, try the search facility.
IRC
Channel: irc.daniweb.com
Room: #c, #shell
IRC
Channel: irc.daniweb.com
Room: #c, #shell
•
•
Join Date: Oct 2004
Posts: 44
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by frrossk
I think you should move the printf ("\n"); outside of one of the 2 for loops:
#include<stdio.h> #include<conio.h> void main() { int a[3][4],b[3][4],c[3][4]; int i,j; clrscr(); printf("\nENTER AN ARRAY:"); printf("\n\nFIRST TABLE:"); for(i=0;i<3;i++) { for(j=0;j<4;j++) { scanf("%d",&a[i][j]); } } printf("\nENTER AN ARRAY:"); printf("\n\nSECOND TABLE:"); for(i=0;i<3;i++) { for(j=0;j<4;j++) { scanf("%d",&b[i][j]); } } printf("\nENTER AN ARRAY:"); printf("\nSUM OF TABLES:"); for(i=0;i<3;i++) { for(j=0;j<4;j++) { printf("%4d ",c[i][j]); c[i][j]=a[i][j]+b[i][j]; } printf("\n"); } getch(); }
![]() |
Similar Threads
- wamp server problem plz help (PHP)
- small problem in the string (C++)
- A small problem in the output (C++)
Other Threads in the C Forum
- Previous Thread: code explanation required
- Next Thread: Duplicate lines when writing to output file. One formatted and on unformatted.
Views: 2005 | Replies: 6
| Thread Tools | Search this Thread |
Tag cloud for C
#include * .net append array arrays asterisks binarysearch calculate changingto char character cm command copyimagefile cprogramme creafecopyofanytypeoffileinc database directory dynamic execv feet fgets file fork forloop framework function functions givemetehcodez grade graphics gtkwinlinux hacking histogram homework include incrementoperators input intmain() iso kernel keyboard km lazy license linked linkedlist linux list lists locate logical_drives looping loopinsideloop. lowest matrix microsoft mqqueue mysql number oddnumber odf opensource overwrite owf pdf performance pointer pointers posix probleminc process program programming radix recursion recv recvblocked research reversing scanf scripting segmentationfault sequential socket spoonfeeding standard string student systemcall testing threads turboc unix user variable wab whythiscodecausesegmentationfault windowsapi





