adspace
a number whose only prime factors are 2,3,5, and 7 is call
humble number,,write a program to find and display the nth
element in this sequence..
sample input : 2,3,4,11,12,13, and 100.. sample output : the
2nd humble number is 2,the 3rd humble number is 3,the 4th
humble number is ,the 11th humble number is 12, the 12th
humble number is 14, the 13th humble number is 15, the 100th
humble number is 450.
Answer Posted / Suresh Meena
Here's a C program to find and display the nth humble number:n```cn#include <stdio.h>nnint count_humble(int num, int humbles[], int len){ // Function to count humble numbers up to 'num'n int count = 0;n for (int i = 0; i < len; i++){n if ((humbles[i] & (humbles[i] - 1)) == humbles[i]) {n count++;n if (humbles[i] > num) break;n }n }n return count;n}nnint main(void){n int humbles[] = {2, 3, 5, 7}; // Humble numbersn int len = sizeof(humbles) / sizeof(humbles[0]); // Length of the arrayn int n; // User input for nth humble numbern printf("Enter the nth humble number you want to find: ");n scanf("%d", &n);n if (n > count_humble(humbles[len-1], humbles, len)) {n printf("The requested humble number does not exist in the sequence.
");n return 0;n }n int i = 0;n for (int j = 0; j < n - 1; j++) {n while ((humbles[i] & (humbles[i] + 1)) != humbles[i]) i++;n }n printf("The %dth humble number is: %d
", n, humbles[i]);n return 0;n}n```
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
Can a function be forced to be inline? Also, give a comparison between inline function and the C macro?
hi folks i m approching for h1 b interview on monday 8th of august at montreal and i m having little problem in my approval notice abt my bithdate my employer has made a mistake while applying it is 12th january and istead of that he had done 18 the of january do any body have any solution for that if yes how can i prove my visa officer abt my real birthdate it urgent please let me know guys thaks dipesh patel
what is ur strangth & weekness
What is variable initialization and why is it important?
The % symbol has a special use in a printf statement. How would you place this character as part of the output on the screen?
what is associativity explain what is the precidence for * and & , * and ++ how the folloing declaration work 1) *&p; 2) *p++;
What is pointer to pointer in c with example?
What are compound statements?
What are pointers? What are different types of pointers?
ATM machine and railway reservation class/object diagram
Write a C program that will accept a hexadecimal number as input and then display a menu that will permit any of the following operations to be carried out: Display the hexadecimal equivalent of the one's complement. (b) Carry out a masking operation and then display the hexadecimal equivalent of the result. (c) Carry out a bit shifting operation and then display the hexadecimal equivalent of the result. (d) Exit. If the masking operation is selected, prompt the user lor the type of operation (bitwise and, bitwise exclusive or, or bitwise or) and then a (hexadecimal) value for the mask. If the bit shifting operation is selected. prompt the user for the type of shift (left or right), and then the number of bits. Test the program with several different (hexadecimal) input values of your own choice.
write a c program to find the sum of five entered numbers using an array named number
`write a program to display the recomended action depends on a color of trafic light using nested if statments
How do you convert strings to numbers in C?
develop algorithms to add polynomials (i) in one variable