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