- #1

Raghav Gupta

- 1,011

- 76

## Homework Statement

My Program is not showing the sum value or not returning it. A blank space is coming.Why that is so?

## Homework Equations

Showing the attempt below in form of code.

## The Attempt at a Solution

Code:

```
#include<iostream.h>
#include<conio.h>
Prime_Sum(int arr[30][30],int m, int n);
void main()
{
clrscr();
int arr[30][30],i,j, m, n;
cout<<"Enter the rows\n";
cin>>m;
cout<<"Enter the columns\n";
cin>>n;
cout<<"Enter the matrix elements\n";
for(i=0;i<m;i++)
for(j=0;j<n;j++)
cin>>arr[i][j];
cout<<"Matrix form:\n";
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
cout<<"\t"<<arr[i][j];
cout<<"\n";
}
Prime_Sum(arr,m,n);
getch();
}
Prime_Sum(int arr[30][30],int m,int n)
{
cout<<"The sum of prime numbers in matrix is:\t";
int sum=0,flag;
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
for(int k=2;k<arr[i][j];k++)
{
if(arr[i][j]==2)
{
flag=1;
break;
}
else if(arr[i][j]%k!=0)
flag=1;
else
{
flag=0;
break;
}
}
if(flag==1)
sum+=arr[i][j];
}
}
return sum; // not returning sum value, are brackets necessary? Although then also not returning.
}
```

Enter rows

2

Enter columns

2

Enter elements

2

1

3

4

Matrix form:

2 1

3 4

The sum of prime nos. is:

and when I press key the screen terminates why that is so?

When I wrote

**void**before Prime_Sum function and then instead of return sum wrote

**cout<< sum;**

The output came. What is problem in return function here?

Last edited: