float calculate(float total,int i,int j,int b)
{
for (int z=0;z<b;z++)
{
total+=m1[i][z]*m2[z][j];
}
return total;
}
void main()
{
int a,b,c,d,i,j,z;
cout<<"This program counts the result of M1 * M2\n\n";
cout<<"What size do you want for matrix 1?";cin>>a;cin>>b;
cout<<"Input matrix 1 M1 : \n";
for (i=0;i<a;i++)
{
for (j=0;j<b;j++)
m1[i][j]=input(i,j);
}
cout<<"\n\nWhat size do you want for matrix 2?";cin>>d;cin>>c;
while (d!=b)
{
cout<<"those size aren't correct\n";
cout<<"\n\nWhat size do you want for matrix 2?";cin>>d;cin>>c;
cout<<"Now, for the matrix 2 M2 : \n";
}
d=b;
for (i=0;i<b;i++)
{
for (j=0;j<c;j++)
m2[i][j]=input(i,j);
}
for (i=0;i<a;i++)
{
for (j=0;j<c;j++)
{
mtimes[i][j]=0;
}
cout<<endl;
}
for (i=0;i<a;i++)
{
for (j=0;j<c;j++)mtimes[i][j]=calculate(0.0,i,j,b);
}
for (i=0;i<a;i++)
{
for (j=0;j<c;j++)
{
cout<<mtimes[i][j]<<'\t';
}
cout<<endl;
}
}
any suggestion for inputing a function on this program?
Thanks a lot for any suggest...
#include<iostream.h>
float input(int i,int j)
{
float a;
cout<<"Element in row : "<<i+1<<" and column "<<j+1<<" ";
cin>>a;
return a;
}
float m1[30][30],m2[30][30],mtimes[30][30];
float calculate(float total,int i,int j,int b)
{
for (int z=0;z<b;z++)
{
total+=m1[i][z]*m2[z][j];
}
return total;
}
void main()
{
int a,b,c,d,i,j,z;
cout<<"This program counts the result of M1 * M2\n\n";
cout<<"What size do you want for matrix 1?";cin>>a;cin>>b;
cout<<"Input matrix 1 M1 : \n";
for (i=0;i<a;i++)
{
for (j=0;j<b;j++)
m1[i][j]=input(i,j);
}
cout<<"\n\nWhat size do you want for matrix 2?";cin>>d;cin>>c;
while (d!=b)
{
cout<<"those size aren't correct\n";
cout<<"\n\nWhat size do you want for matrix 2?";cin>>d;cin>>c;
cout<<"Now, for the matrix 2 M2 : \n";
}
d=b;
for (i=0;i<b;i++)
{
for (j=0;j<c;j++)
m2[i][j]=input(i,j);
}
for (i=0;i<a;i++)
{
for (j=0;j<c;j++)
{
mtimes[i][j]=0;
}
cout<<endl;
}
for (i=0;i<a;i++)
{
for (j=0;j<c;j++)mtimes[i][j]=calculate(0.0,i,j,b);
}
for (i=0;i<a;i++)
{
for (j=0;j<c;j++)
{
cout<<mtimes[i][j]<<'\t';
}
cout<<endl;
}
}
sorry for the inconvenience...
what i want to do is i want to input function on the program, any function will do.. thanks for the replay...
and one more thing, i have a question about binary conversion
Operation Remainder
118 ÷ 2 = 59 0
59 ÷ 2 = 29 1 why is this 29 and,
29 ÷ 2 = 14 1 why is this 14?
14 ÷ 2 = 7 0
7 ÷ 2 = 3 1
3 ÷ 2 = 1 1
1 ÷ 2 = 0 1
i've got this from wikipedia on binary numeral system pages...
thanks again for the replay...
I don't really understand what you're asking. "Input a function"? You have already defined some functions in your previous code, why are you asking this?
Rephrase your question.
59÷2=29 because that's an integer division. The number next to it (1) is the remainder. 29*2+1=59.