good time people
I have a code like the one below:
#include <vector>
#include <stdio.h>
#include "mymath.h"
using namespace std;
int main(){
int n;
char a='y';
do{
cout<<"\n----------------------------------------\n";
cout<<"Enter a number for prime factorization : ";
cin>>n;
cout<<"\n----------------------------------------\n";
int *result=pfact(n);
for(int i;result[i][0]!=0;++i){
if(result[i+1][0]!=0) cout<<result[i][0]<<"^"<<result[i][1]<<"*";
else cout<<result[i][0]<<"^"<<result[i][1]<<"=";}
cout<<n;
cout<<"\n----------------------------------------\n";
cout<<"Do you want to continue (y/n) ? ";
cin>>a;}while(a=='y');}
with having mymath.h like the one below:
#ifndef MYMATH_H_INCLUDED
#define MYMATH_H_INCLUDED
#endif // MYMATH_H_INCLUDED
#include <stdio.h>
#include <vector.h>
int *pfind(int num){
int index=0,*prime;
prime=new int[num];
for(int i=1;i<=num;++i){
int flag=0;
for(int j=2;j<i;++j){
if(i%j==0){
++flag;}}
if(flag==0 && i>1){
prime[index]=i;
++index;}}
prime[index]=0;
return prime;}
int *pfact(int num){
int *prime=pfind(num/2);
int re[num][2];
int index=0;
for(int i=0;prime[i]!=0;++i){
for(int j=1;num%prime[i]==0;++j){
re[index][0]=prime[i];
re[index][1]=j;}
++index;}
re[index][0]=0;
return *re;}
when I run the program,I'll get six errors like:
error : invalid types 'int[int]' for array subscript
for every use of array result.
please help
thanks