Introduction to Programming--c Language 6th week programming Exercise 2 finish (5 points)

Source: Internet
Author: User

2

Finish (5 points)

Topic content:

The factor of a positive integer is all positive integers that can be divisible by it. And if a number is exactly equal to the sum of factors other than itself, this number is called the end number. For example 6=1+2+3 (6 of the factor is the one-to-be).

Now you are going to write a program that reads two positive integers n and M (1<=n<m<1000) and outputs all the n,m in the range.

Tip: You can write a function to determine whether a number is complete.

Input format:

Two positive integers, separated by a space.

Output format:

In the meantime, all the numbers are separated by a space, and the last number has no space behind it. If not, output one line of text:

NIL

(output nil three uppercase letters plus a carriage return).

Input Sample:

1 10

Sample output:

6

Time limit: 500ms memory limit: 32000kb

  main.c//  C yuyan////  Created by Anzhongyin on 2016/11/29.//  Copyright 2016 anzhongyin. All rights reserved.//#include <stdio.h> #include <math.h>int perfnumber (int i); int main (int argc, const char * argv[]) {    //Insert code    here ... TODO auto-generated method stub    int n,m;    scanf ("%d%d", &n,&m);    int b=0;    for (int i=n+1;i<m;i++)    {                if (Perfnumber (i))        {            if (!b)            {            printf ("%d", I);            b=1;            }            else            {                    printf ("%d", i);    }}} if (!b)    {        printf ("NIL");    }    printf ("\ n");} int perfnumber (int i) {    int per=1;    for (int j=2;j<i;j++)    {        if (i%j==0)        {            per+=j;        }    }    if (per!=i)    {        i=0;    }        return i;}

  

Use case test Results

Run time

Memory consumption

Tips

Score

Use Case 1 by

1ms

136kb

1

Use Case 2 by

3ms

256kb

2

Use Case 3 by

1ms

256kb

2

Submit an Answer

Score/Score:5.00/5.00 min

Introduction to Programming--c Language 6th week programming Exercise 2 finish (5 points)

Related Article

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.