logo
Tags down

shadow

Fast formula to get the range a number is in, given a perfect binary subdivision?


By : Brooke
Date : September 16 2020, 09:00 PM
I wish did fix the issue. Mind the set of positive integers from 0 til L exclusive. For any positive integer n up to log2(K), can split the set in 2^n consecutive subsets of equal length. For example, for L = 256, n = 3, we'd get 2^3, or 8, subsets: {0..31}, {32..63}, {64..95}, {96..127}, {128..160}, {160..191}, {192..223}, {224..255}. , This works:
code :
#include <stdio.h>

typedef struct { int a, b; } pair;

pair f(int L, int n, int i) {
    int len = L / (1 << n);
    int a = i / len * len;
    return (pair) { a, a + len - 1 };
}

int main() {
    pair p = f(256, 3, 100);
    printf("%d %d\n", p.a, p.b);
}
#include <stdio.h>
#include <math.h>

typedef struct { double a, b; } paird;

paird fd(double L, double n, double i) {
    double len = L / pow(2, n);
    double a = 0, b;
    while (b = a + len, b < i) {
        a = b;
    }
    return (paird){ a, b };
}

int main() {
    paird p = fd(127, 7, 100);
    printf("%f %f\n", p.a, p.b); // (99.218750, 100.210938)
}


Share : facebook icon twitter icon

For an Excel Formula's variable taking a Range, input row number by the result of a formula


By : Nazeer
Date : March 29 2020, 07:55 AM
Hope this helps I'm trying to fill in this =SERIES function to populate a line plot in Excel 2007. , This can be done using INDEX to specify the range
code :
$BB$2:INDEX($BB:$BB,COUNTA($BB:$BB)+1)
OFFSET($BB$2,0,0,COUNTA($BB:$BB))
$BB$2:INDIRECT("BB"&COUNTA($BB:$BB)+1)

Calculate number of perfect squares in a given big range in C


By : Coronel Fernando Car
Date : March 29 2020, 07:55 AM
this one helps. If you just need to count how many perfect squares there are between 1..N all you need to do is: take a square root of N and get its integer value :)
Just think about it. For the range 1..10 the correct answer is 3 (1, 4, 9) which is, incidentally, the rounded-down sqrt(10). If you don't want to count 1 as a perfect square - fine, just don't count it.
code :
(int)sqrt(N) - (int)sqrt(M) - 1

Perfect Number Method w/ Range


By : Audi
Date : March 29 2020, 07:55 AM
hop of those help? You can't put an else statement inside and if statement unless there is another if statement there.
Here is the whole code. Also you weren't reading in all the numbers entered. The first for loop should be n1 <= endval; and not n1 < endval; so that it also checks the enval entered.
code :
    Scanner scanner = new Scanner(System.in);
    int counter = 0;

    System.out.println("\nPerfect Number Finder Program");

    System.out.print("\nEnter the start value: ");
    int starval = scanner.nextInt();
    System.out.print("Enter the end value:");
    int endval = scanner.nextInt();

    for (int n1 = starval; n1 <= endval; n1++) {
        int sum = 0;
        for (int n2 = 1; n2 < n1; n2++) {
            if (n1 % n2 == 0) {
                sum = sum + n2;
            }
        }

        if (sum == n1) {
            System.out.println(n1 + " is a perfect number");
             counter ++; //This will add one to the counter if this loop is enterd
            }
         if(n1 == endval){
            System.out.println("FINISHED!");
            break;
         }
    }
    //If the counter is 0 then it will display the message
    if(counter == 0){
        System.out.println("THERE IS NO PERFECT NUMBERS");
    }
}

Calculating the number of perfect squares, perfect cubes,etc in a given range?


By : LdoZ
Date : March 29 2020, 07:55 AM
wish of those help Float numbers calculations are not exact.
64**1/3 could have value like ~3.99999975, so floor gives 3. Or 4.000000016, so ceil gives 5 (I did not check real value). You must take numerical errors into account.

Not counting number of perfect numbers within a range?


By : nyron waite
Date : March 29 2020, 07:55 AM
I wish did fix the issue. I want to find the number of the perfect numbers in a range. This is what i have done so far. , Need to make sum=0 for every input. For e.g
code :
if(sum == i) {
      count++;
}
sum = 0; /* add this line here */
for(int i=x;i<=y;i++) {
        sum = 0; /* or make sum as 0 here  */
        for(int j=1; j<i; j++) { 
                if(i%j == 0) {
                        sum=sum+j;
                }
        }
        if(sum == i) {
                count++;
        }
}
Related Posts Related Posts :
  • Pointer to Pointer in c, getting unexpected value
  • "Permission denied" in open() function in C
  • How to assign an array of structs
  • Sort an Array of struct by a value of a field inside the struct
  • Implement stack with pointers in c
  • C program that goes through a string and flags for non-letters
  • C while statement in switch clause
  • Can we allocate memory for char * but return it as const char *?
  • How do Comma-separated expressions as condition in a for-loop work?
  • Sort Structs by the value of an attribute in it
  • How should I make users to put in the info that I want?
  • Are bitmask checks more efficient than comparing numbers?
  • Are the fast integer types faster when stored in the CPU registers?
  • Does realloc deallocate before trying to allocate new memory?
  • Failing to compile a 15+ year old MUD codebase written in C
  • opendir dont get content of buffer char * on C language?
  • Can we have '+' operator inside printf()?
  • Why scanf function do not accept escape sequences as an input?
  • Print strings of length of k from a and b
  • C problem with passing pointer to struct to function
  • Shall I use register class variables in modern C programs?
  • Can I specify conditions for the rand() function?
  • C fprintf and fscanf saving game state
  • Why can't I use more than two registers in inline asm?
  • A question of strstr() and fgets() in a demo from the book《Head First C》
  • the problem is from a algorithm problem I do recently,but I can't gain the right answer
  • Problem to access members in pointer struct located in another pointer struct
  • Check that all symbols defined in static library
  • Function will only properly work if I've printed the values of the attributes
  • Why my code is showing time limit exceeded
  • #define statement for address of memory
  • How to call a function from another .c file
  • Memory layout of C struct
  • Why should we use return statement when using a recursive call?
  • error: expected identifier or '(' before '=' token
  • Why is it not possible to exchange the position of array name and index in swift like C (a[i] == i[a])?
  • How can I allocate enough memory to store an entire text file in C?
  • Segmentation fault when I use afl fuzzer
  • What happens in the assembly output when we add "cc" to clobber list
  • What is the equivalent of Keil _at_ in gcc
  • Simple question about declaring an empty string in C
  • Heap-Overflow or Buffer-Overflow?
  • C: Why is &= better that =?
  • Create exactly 5 process with fork()
  • gcc compile function in ifdef
  • where is the memory leak in the code below?
  • Most efficient formula for unpacking 16-bit BCD? (e.g. 0x1234 to 0x01020304)
  • how to find which integer no is maximim out of given numbers
  • Difference between a VOID function with a string argument VS a function with a string argument that returns a char array
  • why the output of the following program different (random value) every time?
  • Why does this macro expression in C behave unexpectedly?
  • When is memory allocated and de-allocated static and dynamic memory in C?
  • In C, what happens if we left shift the bits out of range and again right shift the values in the same operation
  • why the following c program is giving segmentation error?
  • How can I run through all the characters of a string and check if they're all numbers in C?
  • adc frequency vs accuracy
  • why the output of following c program is 16 16 16?
  • Is it possible to declare a function in header file with unknown type that is specified only in file '.c'?
  • How to properly fscanf txt file in C
  • why use of %n in printf() is not printing the number of variable occurrence before %n In C?
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk