<?xml version="1.0" encoding="utf-8"?>

<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
	<channel>
		<title>DaniWeb IT Discussion Community</title>
		<link>http://www.daniweb.com/forums/</link>
		<description>Tech support, programming, web development, and internet marketing community. Forums to get free computer help and support.</description>
		<language>en-US</language>
		<lastBuildDate>Tue, 01 Dec 2009 01:07:00 GMT</lastBuildDate>
		<generator>vBulletin</generator>
		<ttl>60</ttl>
		<image>
			<url>http://www.daniweb.com/alphaimages/misc/rss.jpg</url>
			<title>DaniWeb IT Discussion Community</title>
			<link>http://www.daniweb.com/forums/</link>
		</image>
		<item>
			<title>Matrix Multiplication - Dynamic Pointers (Seg Fault)</title>
			<link>http://www.daniweb.com/forums/thread242485.html</link>
			<pubDate>Mon, 30 Nov 2009 16:49:50 GMT</pubDate>
			<description><![CDATA[Hey Everyone, 
 
I have written this Matrix Multiplication program. But The Program seems to crash when during the filling of the first matrix, exactly after the completion of the first row. 
 
Here is my implementation  
  <div class="codeblock"> <div class="spaced"> <div style="float:right;...]]></description>
			<content:encoded><![CDATA[<div>Hey Everyone,<br />
<br />
I have written this Matrix Multiplication program. But The Program seems to crash when during the filling of the first matrix, exactly after the completion of the first row.<br />
<br />
Here is my implementation <br />
 <pre style="margin:20px; line-height:13px">#include &lt;iostream&gt;<br />
using namespace std;<br />
void generate (int ** ,int ,int);<br />
void fill (int ** ,int,int);<br />
int** compute(int **,int **,int,int,int,int);<br />
void dellocate(int **val,int x,int y);<br />
void display(int **val,int x,int y);<br />
<br />
int main()<br />
{<br />
&nbsp;  int **r, **p , **q,row1,row2,col1,col2;<br />
&nbsp;  cout&lt;&lt;&quot;Matrix Multiplication Program :\n&quot;;<br />
&nbsp;  cout&lt;&lt;&quot;Please Enter Number of Rows for first matrix :&quot;;<br />
&nbsp;  cin&gt;&gt;row1;<br />
&nbsp;  cout&lt;&lt;&quot;Please Enter Number of Columns for first matrix :&quot;;<br />
&nbsp;  cin&gt;&gt;col1;<br />
&nbsp;  cout&lt;&lt;&quot;Please Enter Number of Rows for 2nd matrix:&quot;;<br />
&nbsp;  cin&gt;&gt;row2;<br />
&nbsp;  cout&lt;&lt;&quot;Please Enter Number of Columns for 2nd matrix :&quot;;<br />
&nbsp;  cin&gt;&gt;col2;<br />
&nbsp;  if(col1!=row2)<br />
&nbsp;  {<br />
&nbsp;  cout&lt;&lt;&quot;Multiplication not possible &quot;;<br />
&nbsp;  return 0;<br />
&nbsp;  }<br />
&nbsp;  else<br />
&nbsp;  {<br />
&nbsp; &nbsp;  generate(p,row1,col1);<br />
&nbsp; &nbsp;  generate(q,row2,col2);<br />
&nbsp; &nbsp;  fill(p,row1,col1);<br />
&nbsp; &nbsp;  fill(q,row2,col2);<br />
&nbsp; &nbsp;  r=compute(p,q,row1,col1,row2,col2);<br />
&nbsp; &nbsp;  cout&lt;&lt;&quot;Matrix ONE: &quot;&lt;&lt;endl;<br />
&nbsp; &nbsp;  display(p,row1,col1);<br />
&nbsp; &nbsp;  cout&lt;&lt;&quot;Matrix TWO: &quot;&lt;&lt;endl;<br />
&nbsp; &nbsp;  display(q,row2,col2);<br />
&nbsp; &nbsp;  cout&lt;&lt;&quot;The Output Matrix after Multiplication &quot;&lt;&lt;endl;<br />
&nbsp; &nbsp;  display(r,row1,col2);<br />
&nbsp; &nbsp;  dellocate(p,row1,col1);<br />
&nbsp; &nbsp;  dellocate(q,row2,col2);<br />
&nbsp; &nbsp;  dellocate(r,row1,col2);<br />
&nbsp;  }<br />
}<br />
<br />
void generate ( int **x,int a ,int b)<br />
{<br />
&nbsp;  x=new int*[a];<br />
&nbsp;  for (int i=0;i&lt;a;i++)<br />
&nbsp;  {<br />
&nbsp;  x[i]=new int[b];<br />
&nbsp;  }<br />
}<br />
<br />
void fill(int **x,int a , int b)<br />
{<br />
&nbsp;  for(int i=0;i&lt;a;i++)<br />
&nbsp; &nbsp; &nbsp; for(int j=0;j&lt;b;j++)<br />
&nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; cout&lt;&lt;&quot;Enter element no (&quot;&lt;&lt;i&lt;&lt;&quot;,&quot;&lt;&lt;j&lt;&lt;&quot;) :&quot;;<br />
&nbsp; &nbsp; &nbsp; cin&gt;&gt;x[i][j];<br />
&nbsp; &nbsp; &nbsp; }<br />
}<br />
<br />
int** compute(int **x,int **y,int r1,int col1,int r2,int col2)<br />
{<br />
&nbsp;  int ** temp;<br />
&nbsp;  generate(temp,r1,col2);<br />
&nbsp;  for(int i=0;i&lt;r1;i++)<br />
&nbsp; &nbsp; &nbsp; for(int j=0;j&lt;col2;j++)<br />
&nbsp; &nbsp; &nbsp;  {<br />
&nbsp; &nbsp; &nbsp; &nbsp;  temp[i][j]=0;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  for(int k=0;k&lt;col1;k++)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  temp[i][j]+=(x[i][k])*(y[k][j]);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; }<br />
&nbsp;  return temp;<br />
}<br />
<br />
void display(int **val,int x,int y)<br />
{<br />
&nbsp;  for(int i=0;i&lt;x;i++)<br />
&nbsp;  {&nbsp; <br />
&nbsp; &nbsp; &nbsp;  for(int j=0;j&lt;y;j++)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cout&lt;&lt;val[i][j]&lt;&lt;&quot; &quot;;<br />
&nbsp;  cout&lt;&lt;endl;<br />
&nbsp;  }<br />
}&nbsp;  <br />
<br />
void dellocate(int **val,int x,int y)<br />
{<br />
&nbsp; &nbsp; &nbsp; for(int i=0;i&lt;x;i++)<br />
&nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp;  delete [] val[i] ;<br />
&nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; delete [] val;<br />
}</pre></div> ]]></content:encoded>
			<category domain="http://www.daniweb.com/forums/forum8.html">C++</category>
			<dc:creator>Sky Diploma</dc:creator>
			<guid isPermaLink="true">http://www.daniweb.com/forums/thread242485.html</guid>
		</item>
	</channel>
</rss>
