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 / 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 |
Why c is a procedural language?
int *a[5] refers to
What language is windows 1.0 written?
how many keywords do C compile?
7 Answers Microsoft, Practical Viva Questions,
What is the right type to use for boolean values in c? Is there a standard type? Should I use #defines or enums for the true and false values?
What is the Difference between Class and Struct?
how to execute a program using if else condition and the output should enter number and the number is odd only...
If 4 digits number is input through the keyboard, Write a program to calculate sum of its 1st & 4th digit.
please send me papers for Dy. manager IT , PNB. it would be a great help for me.
code for find determinent of amatrix
‘ C’ PROGRAME TO SHOW THE TYPE OF TRANGLE BY ACCEPTING IT’S LENGTH .
What is #define in c?