Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Antonio Villanueva Segura
- * Suma mas grande de series armonicas entre S0 y S9
- * donde d en Sd no aparezca en ningun momento de la serie armonica
- */
- #include <stdio.h>
- int containsDigit(int number, int digit) {
- while (number > 0) {
- if (number % 10 == digit) {
- return 1;
- }
- number /= 10;
- }
- return 0;
- }
- double serieArmonicaSinD(int d,int max,int debug) {
- double sum = 0.0;
- int n = 1;
- if (debug) { printf ("S%d = {",d);}
- while (n<max) {
- if (!containsDigit(n, d)) {
- if (debug) { printf ("1/%d + ",n);}
- sum += 1.0 / n;
- }
- n++;
- }
- if (debug) { printf("} \n");}
- return sum;
- }
- int main() {
- int debug=1 ;//1 para graficar la serie
- int valores=35;//Numeros de valores a calcular 35 ejemplo
- int serie=0;//Serie mas grande Sserie
- double mayor;//Resultado de la suma mayor
- for (int s=0 ;s<10;s++){
- double sum = serieArmonicaSinD(s,valores,debug);
- printf("S%d= %lf\n" ,s,sum);
- if (mayor <sum){
- serie=s;
- mayor=sum;
- }
- }
- printf ("Suma mas grande S%d= %lf \n",serie,mayor);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement