how to make function on this program?

i have a big problem i think..
can anyone please teach me about how to input a function on this program?

#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;
}
}

any suggestion for inputing a function on this program?
Thanks a lot for any suggest...
Last edited on
could you tell me what do you want to do with this prog?
sorry don't know what your asking...do you want to get input from a function? or just put a function in your code?


you should use the code tags to make your code more readable.. its the the # on the right
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#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;
		}
	}


Last edited on
I == Lost
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...
another question, are DD and D13 are same in hexadecimal?
thanks
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.

DD(16)=221(10)
D13(16)=3347(10)
okay... thanks about the function and the binary,

o, isee... so
DD binary's code is 1101 1101(2) and,
D13 binary's code is 1101 0001 0011(2)
am i correct?
Last edited on
Topic archived. No new replies allowed.