Description
Write the function int fun (int x, int *pp). Its function is to find all the odd factor of X, and in the order from small to large in the PP point of memory, the function return value is the number of these integers. If the value of X is 30, the number in the array is 1,3,5,15, and the function returns 4.
Test with the following main () function:
int main ()
{
int a[50],x,n;
cin>>x;
N=fun (X,a);
cout<<n<<endl;
for (int i=0; i<n; i++)
cout<<a[i]<< "";
cout<<endl;
return 0;
}
Input
An integer
Output
The number of odd factors of the input integers, and the odd factors
Sample Input
30
Sample Output
Code
#include <iostream>using namespace std;int fun (int x,int *a); int main () { int a[50],x,n; cin>>x; N=fun (x,a); cout<<n<<endl; for (int i=0; i<n; i++) cout<<a[i]<< ""; cout<<endl; return 0;} int fun (int x,int *a) { int i=1,m=0; while (i<x) { if (i%2==1&&x%i==0) { * (a+m) =i; m++; } i++; } return m;}
Operation Result:
Learning experience:
Good study Day Day up
16th Week OJ platform problem D: pointer out odd factor