C Language Code Programming Questions Summary: Calculates and outputs the reciprocal sum of all natural numbers within N that can be divisible by 3 or 7

Source: Internet
Author: User

Calculates and outputs the reciprocal sum of all natural numbers within N that can be divisible by 3 or 7

The program code is as follows:

1 /*2 March 5, 2017 15:34:113 function: Calculates and outputs the reciprocal sum of all natural numbers within N that can be divisible by 3 or 74 */5 6#include"stdio.h"7 intMain (void)8 {9     intn, I;Ten     floatsum =0.0; One  Aprintf ("Please enter a value for the data n: \ N"); -scanf ("%d",&N);  -      for(i =1; I <= N; i++) the     { -         if((i%3==0) || I7==0)) -Sum + =1/(float) (i);//there must be a coercion type conversion, the quotient, when the divisor and the divisor has to have a number for the real type -         Else  +             Continue; -     } +printf ("Please output the final result after the operation is evaluated: \ n"); Aprintf ("%f\n", sum); at  -     return 0; - } - /* - Summary: - results shown in vc++6.0: in ———————————————————————— - Please enter a value for the data n: to  - + Please output the final result after the operation is evaluated: - 1.226323 the ———————————————————————— * */

C Language Code Programming Questions Summary: Calculates and outputs the reciprocal sum of all natural numbers within N that can be divisible by 3 or 7

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.