Skip to main content

Featured

Mastering Hollow Square Patterns in C: Stars, Numbers, Alphabets & Binary

πŸ”’ C Program to Print Hollow Continuous Number Square πŸ“„ Source Code: #include <stdio.h> int main() { int num, k = 0; printf("Enter the number:\n"); scanf("%d", &num); for(int i = 1; i <= num; i++) { for(int j = 1; j <= num; j++) { if(i == 1 || i == num || j == 1 || j == num) { // k increments sequentially only along the borders printf("%d ", k++); } else { printf(" "); } } printf("\n"); } return 0; } πŸ“‹ Copy Code πŸ’» Expected Output (Input: 5): Enter the number: 5 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 πŸ”’ C Program to Print Standard Hollow Binary Row Square πŸ“„ Source Code (Fixed Specifier): #include <stdio.h> int main() { ...

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

πŸŒ™