16th Week OJ platform problem D: pointer out odd factor

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.