The number of required [n x 1] multiplexer to implement one [m x 1] multiplexer.

 /******************************************************************************

This is a program to find the number of required (m x 1) multiplexer to implement one (n x 1) multiplexer. And m is always even, otherwise we are wasting the bit(s).
If your m is odd then increase it by one.

*******************************************************************************/

#include <stdio.h>


int main()

{

    int n, m, x, y = 0;

    printf("This is a program to find the number of required (m x 1) multiplexer to implement one (n x 1) multiplexer. And m is always even, otherwise, we are wasting the bit(s). If your m is odd then increase it by one.\n");

    printf("Enter the value of n:\t");

    scanf("%d", &n);

    printf("Enter the value of m:\t");

    scanf("%d", &m);

    if(n>m){

        x = n;

        while(x > m){

            //If x is odd then we need an another multiplexer.

            if( x%2 == 0 ){

            x = x/m;

            y = y + x;

            }

            else{

            x = x/m;

            y = y + x + 1;    

            }

        }

        printf("%d", y+1);

    }

    else

        printf("1");


    return 0;

}


Comments

Popular posts from this blog

My very 1st contest! | Problem - 1 | Beginner level | C language | CodeChef

Implementing linked list in C language