Function

Prompt how to alter these two arrays to a function, please.

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
 # include <iostream.h>
# include <conio.h>
using namespace std;
const int u=3,t=4;
int main ()
{ 
int a[u][t],n=0,i,f,s;
cout<<"enter array\n";
for (i=0;i<u;i++)
{
for (f=0;f<t;f++)
cin>>a[i][f];}
cout<<endl;

for (f=0;f<t;f++)
{
n=0;
for (i=0;i<u;i++)
{
if (a[i][f]==0)
{
 n++;
break;
}
if (n==t)
{
s=0;
for (i=0;i<u;i++)
  s=s+a[i][f];
  cout<<"s= "<<s<<endl;

}
}
}
getch();
return 0;
}



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
#include <iostream.h>
#include <conio.h>

using namespace std;
const int z=10;
int main()
{
	int a[z], i, b=0;
	cout<<"enter array:\n";
	for (i=0; i<z; i++)
	 {
	  cin>>a[i];
	  if (a[i] % 3==0)
	  {
	   b=b+1;
      }
	 }
 for (i=0; i<z; i+=2)
a[i]=b;
	 cout<<"final array:\n";
	 for (i=0; i<z; i++)
	 {
	 cout<<a[i]<<", ";
	 }
	getch();
	return 0;
}              

Last edited on
Topic archived. No new replies allowed.