C language Tempered 5

Source: Internet
Author: User

//Title 13: Print out all the "daffodils", the so-called "Narcissus number" refers to a three-digit number, its number of cubic and equal to the number//itself. For example: 153 is a "narcissus number", because 153 = 1 of the three times +5 three of the +3-time square. #define_crt_secure_no_warnings#include<stdio.h>#include<stdlib.h>#include<math.h>//Analysis: First prepare a dynamic memory array to store all three digits, this three bit hundreds of bit can not be 0//to facilitate decomposition, first define the structure//then get the Hundred, num/100, get 10 bits, (num-hundred *100)/10, digit is (num-hundred *100-10 bit *10)//break out the number of bits, 10, hundred, to see if the daffodils are satisfied//use of the POW () functionstructnarcissunum{intHundred; intTen; intIndiv;};voidMain () {//Defining dynamic Arrays    structNarcissunum *p =malloc(sizeof(structNarcissunum) * -); structNarcissunum num,*PN; PN= &num; //3 cycles to build all three-digit numbers    intm =0;  for(inti =1; I <Ten; i++)    {         for(intj =0; J <Ten; J + +)        {             for(intK =0; K <Ten; k++)            {                if((int) (Pow (i,3.0) + (int) Pow (J,3.0) + (int) Pow (k,3.0) = = (I * -+ J *Ten+k)) {PN->hundred =i; PN->ten =J; PN->indiv =K; * (p + m) = *PN; M++; }            }        }    }     for(inti =0; I < m; i++) {printf ("\n%d%d%d", (P + i)->hundred, (P + i)->ten, (P + i)indiv); } System ("Pause");}
View Code

//Topic 14: Decomposition of a positive integer factorization. For example: Enter 90 and print out 90=2*3*3*5. #define_crt_secure_no_warnings#include<stdio.h>#include<stdlib.h>#include<math.h>//Analysis: First find the factor of this integer, and then the factor, until the value can not be evaluated, recursive call---- This thinking error //positive integer decomposition factorization, if small to large decomposition, there will be no (can be decomposed factor)voidMain () {intnum =0; intindex =0; scanf ("%d", &num); printf ("\ n"); //index = (int) sqrt ((double) (num+1));     for(inti =2; I <= num; i++)    {         while(1){            if(num%i = =0)            {                if(num/i==1) {printf ("%d", i); }                Else{printf ("%d*", i); } num= num/i; }            Else{                 Break; }}} System ("Pause");}

//Topic 15: Use the nesting of conditional operators to complete this problem: the students of the academic score >=90 A, 60-89 points between the use of B,//60 points or less is indicated in C. #define_crt_secure_no_warnings#include<stdio.h>#include<stdlib.h>#include<math.h>//you can use if nested or switch statements to completevoidProtect1 (intnum) {    if(Num >= -) {printf ("A"); }    Else if(Num >= -) {printf ("B"); }    Else{printf ("C"); }}voidProtect2 (intnum) {    inttemp = num/Ten; Switch(temp) { Case 9: printf ("A");  Break;  Case 8:     Case 7:     Case 6: printf ("B");  Break; default: printf ("C");  Break; }}voidMain () {intnum =0; scanf ("%d",&num); printf ("\ n");    Protect2 (num); System ("Pause");}

C language Tempered 5

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.