C Program to convert binary todecimal number

Description

Input:
1010
Ouput:
10

Solution

#include <stdio.h>
 
int main()
{
	int binary_val, decimal_val = 0, base = 1, rem;
 	printf("Enter a Binary Number:");
    	scanf("%d", &binary_val); 
    	while (binary_val > 0)
    	{
        	rem = binary_val % 10;
        	decimal_val = decimal_val + rem * base;
        	binary_val = binary_val / 10 ;
        	base = base * 2;
    	}
    	printf("Equivalent Decimal number is %d", decimal_val);
    	return 0;
}

Explanation

yet to be updated



Interesting Pattern Programs: for more Patterns

Input:
5
Output:
*
**
***
****
*****
****
***
**
*Solution
Input:
5
Output:
    *
   ***
  *****
 *******
*********
 *******
  *****
   ***
    *Solution
Input:
5
Output:
*        *
**      **
***    ***
****  ****
**********Solution
Input:
5
Output:
*       *
**     **
***   ***
**** ****
*********Solution
Input:
5
Output:
*       *
**     **
***   ***
**** ****
*********
**** ****
***   ***
**     **
*       *Solution
Input:
5
Output:
*********
 *******
  *****
   ***
    *
   ***
  *****
 *******
*********Solution