Community Sites
Create your own community website and start earning today !
It's Free !
 
Communities Members BookmarksPolls Fresher Jobs Funny Photos B.Tech Projects New Member FAQ  



My Profile
Active Members
TodayLast 7 Days more...



Awards & Gifts
Online Exams

Fresher Jobs


Our fresher job section is exclusively for fresh graduates! Find jobs for freshers in major Indian cities including Bangalore, Chennai, Hyderabad, Pune or Kochi

Resources


Find educational articles, blogs, discussion threads and other resources.

Colleges


Find details about any college in India or search for courses.

website counter



C Program- matrix addition in dynamic way


Posted Date: 10 Jun 2008    Resource Type: Articles/Knowledge Sharing    Category: Computer & Technology

Posted By: Girish Patil       Member Level: Diamond
Rating:     Points: 2



/*objective:
matrix addition in dynamic way
*/
void main()
{

int **a,**b,**c;
//int c[3][3];
int a_r,a_c,b_r,b_c;
int i,j;
clrscr();
again:
printf("\nenter rows and columns for matrix one:");
scanf("%d%d",&a_r,&a_c);
printf("\nenter rows and columns for matrix two:");
scanf("%d%d",&b_r,&b_c);
if(a_r!=b_r || a_c!=b_c)
{
printf("\ncan not add");
goto again;
}
/* allocate memory for matrix one */
a=(int **) malloc(sizeof(int *),a_r);
for( i=0;i {
a[i]=(int *) malloc(sizeof(int),a_c);
}

/* allocate memory for matrix two */
b=(int **) malloc(sizeof(int *),a_r);
for( i=0;i {
b[i]=(int *) malloc(sizeof(int),a_c);
}
/* allocate memory for sum matrix */
c=(int **) malloc(sizeof(int *),a_r);
for( i=0;i {
c[i]=(int *) malloc(sizeof(int),a_c);
}


printf("\n enter matrix one %d by %d\n",a_r,a_c);
for(i=0;i {
for(j=0;j {
scanf("%d",&a[i][j]);
}
}

printf("\n enter matrix two %d by %d\n",a_r,a_c);
for(i=0;i {
for(j=0;j {
scanf("%d",&b[i][j]);
}
}



/* add matrix one and matrix two */
for(i=0;i {
for(j=0;j {
c[i][j]=a[i][j]+b[i][j];
}
}
/* display result */

printf("\n sum of matrix one and two is\n");
for(i=0;i {
for(j=0;j {
printf("%d\t",c[i][j]);

}
printf("\n");
}

/*free memory*/
for(i=0;i {
free(a[i]);
}
free(a);
for(i=0;i {
free(b[i]);
}
free(b);
for(i=0;i {
free(c[i]);
}
free(c);

printf("\npress any key");
getch();
}









Responses

Author: Lenin    10 Jun 2008Member Level: Diamond   Points : 2
hi giri are you a computer student , i know only small programs in C.But i know C is a SEA.Am i right ? I remember the days when i used to mugup the codings for Lab exams.still c fear is there.
Also still C is in flying colours


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: C Program- convert a string into number
Previous Resource: C Program- Check whether given string is palindrome
Return to Discussion Resource Index
Post New Resource
Category: Computer & Technology


Post resources and earn money!
 
Related Resources

Watch TV Channels



Contact Us    Privacy Policy    Terms Of Use   

SpiderWorks Technologies Pvt Ltd. 2006 - 2007 All Rights Reserved.