C Language Blog Jobs-functions

Source: Internet
Author: User

I. PTA lab Assignment 1. Topic 6.6 Use the function to output daffodils number 1. List of topics submitted 2. Design Ideas

int narcissistic (int number) function
1. The first step is to define the I,J variable control loop, count indicates the number of input values, W represents the sum of the counts on each digit of the input value, and Y represents the count of each single digit, sum is used to hold the value of number
2. Step two, while (sum>0) {sum=sum/10;count++;} Calculate the number of input values
3. Step three, for (j=1;j<=count;j++)
Y=y*h;
Calculates the number of W=w+y and w on each digit of the input value
4. Fourth step, if W==number, return 1, otherwise return 0
PRINTN (int m, int n) function
Define r storage number, for (r=m+1;r<=n-1;r++) Call narcissistic function, if return 1 print that number

3. Problems encountered 2. Title 6.7 Use the function output to complete the number of 1 in the specified range. Topic submission List 2. Design ideas

1. Custom functions int factorsum (int number), function name Factorsum (), return value is integer type, input data is integer;
2. Define variable i,total=0;
3. If number==1, the return result is 1; otherwise enter the loop for (i=1;i<number;i++);
4. If number%i==0,total=total+i;
5. Repeat 3, 4, until I=number, if total==number after the end of the cycle, return total;
6. Custom function void Printpn (int m, int n), function named PRINTPN (), function no return value, input m,n is integer type;
7. Define the variable i,j,r,sum=0,flag=0,
8. If m==1;printf ("%d =%d\n", m,m), flag=1;
9. Otherwise enter the loop for (i=m;i<=n;i++) if Factorsum (i) ==i,sum=0; Flag=1, and enter the sub-loop for (j=1;j<i;j++) if i%j==0,sum=sum+j;
10. Repeat step nine until the condition is not established;
11. If sum==i,printf ("%d =", i), and outputs the first factor 1, enter the loop for (r=2;r<i;r++), if i%r==0,printf ("+%d", r), and output a newline character after the end of the loop;
12. If flag==0, output no perfect number.

3. Problems encountered 3. Topic 7.1, combinatorial number 1. Submit List 2. Design ideas

Define variable M,n store input number, input m,n; invoke fact function, output result;
Fact function
Define floating-point variable result=1; make i=1, Judge I<=n?, is result=result*i,i++, otherwise return result.

3. Problems encountered two. PTA final rankings for this week's topic set

C Language Blog Jobs-functions

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.