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; ...

Armstrong Number Check in C

Armstrong Number in C

✅ Armstrong Number Check in C

#include<stdio.h>
int main( )
{
    int num, remainder, temp, sum = 0;
    printf("Enter the number:\n");
    scanf("%d", &num);
    temp = num;
    while (num > 0)
    {
        remainder = num % 10;
        sum = sum + (remainder * remainder * remainder);
        num = num / 10;
    }
    if (temp == sum)
    {
        printf("%d is armstrong:\n", temp);
    }
    else
    {
        printf("%d is not armstrong:\n", temp);
    }
}
  

πŸ“˜ Explanation:

An Armstrong number (also known as a narcissistic number) is a number that is equal to the sum of the cubes of its digits.

  • The user is prompted to enter an integer.
  • Each digit is separated using modulus (%) and divided out using division (/).
  • The cube of each digit is added to a sum.
  • Finally, if sum == original number, it is an Armstrong number.

Example: 153 → 1³ + 5³ + 3³ = 1 + 125 + 27 = 153 ✔️

πŸ’» Sample Output:

Enter the number:
153
153 is armstrong:
  

πŸ”‘ Keywords:

Armstrong number in C, C Armstrong program, digit cube sum, Armstrong logic in C, C programming for beginners, Armstrong check using while loop, C interview coding question, temp and remainder in C

πŸ“Œ Hashtags:

#CProgramming #ArmstrongNumber #BeginnerCPrograms #DigitExtraction #WhileLoopInC #CCodeForInterview #TechBlog #CodeWithMe

Comments

Popular Posts

πŸŒ™