কম্পিউটার

আর্মস্ট্রং নম্বরের জন্য সি প্রোগ্রাম


আমাদের একটি টাস্ক দেওয়া হয়েছে যেখানে আমাদের ব্যবহারকারীর দ্বারা প্রবেশ করা একটি নম্বর পরীক্ষা করতে হবে, তা আর্মস্ট্রং হোক বা না হোক৷

একটি আর্মস্ট্রং সংখ্যা হল যখন সমস্ত অঙ্কের যোগফল সংখ্যার সংখ্যা দ্বারা বা আমরা বলতে পারি n সংখ্যার ক্রম, অঙ্কের সমান হয়৷

তাই নিচে একটি সহজ উপস্থাপনা দেওয়া হল কিভাবে আর্মস্ট্রং নম্বর −

খুঁজে বের করতে হয়

আর্মস্ট্রং নম্বরের জন্য সি প্রোগ্রাম

সূত্র -

wxyz…. = pow(w, n) +pow(x, n) + pow(y, n) + pow(z, n) + …..

অ্যালগরিদম

START
Step 1-> Declare a function to find the value after power operation on the number
   int power(int a, int b)
      Loop while b>0
         Assign power =power * a
         Decrement b by 1
      End loop
      Return power
End
Step 2-> Declare a function to count the order of a number
   int count(int n)
      Declare and set i as 0
      Loop while n!=0
         Increment i by 1
         Divide n/10 and store back in n
      End loop
   Return i
End
Step 3-> Declare a function to check number is prime or not
   int armstrong(int n)
      Declare x and call function count(n) and assign the result to x
      Declare rem = 0 and m=0 set with zero
      Loop While n
         Set rem = n %10
         Set m = m + power(rem, x)
         Set n as n/ 10
      End Loop
   Return m;
End
Step 4-> Declare main
   int main(int argc, char const *argv[])
      Declare and set n = 1634
      Call function Armstrong and check if the value is equal
         Print “it is armstrong number
      End if
      Else
         Print number isn't an armstrong number
   End
STOP

উদাহরণ

#include <stdio.h>
int power(int a, int b){
   int power =1;
   while(b>0){
      power *= a;
      b--;
   }
   return power;
}
int count(int n){
   int i=0;
   while(n!=0){
      i++;
      n = n/10;
   }
   return i;
}
int armstrong(int n){
   int x = count(n);
   int rem = 0, m=0;
   while(n){
      rem = n %10;
      m += power(rem, x);
      n /= 10;
   }
   return m;
}
int main(int argc, char const *argv[]){
   int n = 1634;
   if(n == armstrong(n)){
      printf("%d is an armstrong number \n",n);
   }
   else
      printf("%d isn't an armstrong number \n",n);
   return 0;
}

আউটপুট

1634 is an armstrong number

  1. ম্যাট্রিক্স বিয়োগের জন্য সি প্রোগ্রাম

  2. আয়তক্ষেত্রের ক্ষেত্রফল এবং পরিধির জন্য সি প্রোগ্রাম

  3. প্রথম n প্রাকৃতিক সংখ্যার ঘনক্ষেত্রের যোগফলের জন্য C প্রোগ্রাম?

  4. ফিবোনাচি সংখ্যার জন্য পাইথন প্রোগ্রাম