Skip to main content

Featured

C Pattern Programs: Square Number and Alphabet Patterns Explained

πŸ”· Square Star Pattern πŸ“‹ Copy Code #include <stdio.h> int main() { int num; printf("Enter the number:\n"); scanf("%d", &num); for(int i = 1; i <= num; i++) { for(int j = 1; j <= num; j++) { printf("* ");//keep"* " } printf("\n"); } return 0; } πŸ”· Reverse Square Alphabet Pattern (Column-wise) πŸ“‹ Copy Code #include <stdio.h> int main() { int num; printf("Enter the number:\n"); scanf("%d", &num); for(int i = num; i >= 1; i--) { for(int j = num; j >= 1; j--) { printf("%c ", j + 64);//%c for Character and 64 will be ASIIC VALUE } printf("\n"); } return 0; } πŸ”· Reverse Square Alphabet Pattern (Row-wise) πŸ“‹ Copy Code #include <stdio.h> int main() { int num; ...

Binary to Decimal Conversion in C

Binary to Decimal Conversion in C

✅ Binary to Decimal Conversion in C

#include<stdio.h>
int main( )
{
    int num, decimal = 0, remainder, j = 1;
    printf("Enter binary number:\n");
    scanf("%d", &num);
    while(num != 0)
    {
        remainder = num % 10;
        decimal = decimal + remainder * j;
        j = j * 2;
        num = num / 10;
    }
    printf("The decimal value is %d\n", decimal);
}
  

πŸ“˜ Explanation:

This program converts a binary number (input as an integer) into its decimal equivalent.
- It extracts each digit (right to left) using modulus and multiplies it by powers of 2.
- The value is added to a `decimal` variable.
- `%d` is used in printf to display the result in decimal format.

🧾 Sample Output:

Enter binary number:
1010
The decimal value is 10
  

πŸ”‘ Keywords:

Binary to Decimal, C Program for Number Conversion, Beginner C Code, scanf printf usage, while loop example, base-2 to base-10

πŸ“Œ Hashtags:

#CProgramming #BinaryToDecimal #BeginnerCode #NumberConversion #whileLoop #scanf #printf #LogicInC

Comments

Popular Posts

πŸŒ™