কম্পিউটার

ভগ্নাংশ উপস্থাপনে সিরিজের প্রথম N পদ (0.25, 0.5, 0.75, …) মুদ্রণ করুন


ইনপুট N যা সংখ্যার সমতুল্য যেখানে সিরিজ প্রিন্ট করা উচিত

Input : N=5
Output : 0 ¼ ½ ¾ 1

অ্যালগরিদম

START
Step 1 -> declare start variables as int num , den, i, n
Step 2 -> input number in n
Step 3 -> Loop For from i to 0 and i<n and i++
   Outer If i%2=0
      Inner IF i%4=0
         Set num=i/4 and den=0
      End Outer IF
      Else
         Set num=i/2 and den=2
      End Else
   End Outer IF
   Else
      Set num = I and den = 4
   End Else
   If den != 0
      Print num and den
   End IF
   Else
      Print num
   End Else
Step 4 -> End For Loop
STOP

উদাহরণ

#include <stdio.h>
int main(int argc, char const *argv[]) {
   int num, den;
   int i, n;
   printf("Enter series limit\n");
   scanf("%d", &n); //Till where the series will be starting from zero
   for (i = 0; i < n; i++) {
      if (i%2==0) { //Checking the numerator is odd or even
         if(i%4==0) { //If the numerator divisible by 4 divide it
            num = i/4;
            den = 0;
         }
         else  {//if not divisible by 4 its even number divisible by 2
            num = i/2;
            den = 2;
         }
      }
      else { //Assigning numerator and denominator value if the number is odd
         num = i;
         den = 4;
      }
      if (den != 0) { //if denominator is not zero then print in fraaction form
         printf("%d/%d\n",num, den);
      }
      else //else print in a normal number form
      printf("%d\n", num);
   }
   return 0;
}

আউটপুট

যদি আমরা উপরের প্রোগ্রামটি রান করি তাহলে এটি নিম্নলিখিত আউটপুট তৈরি করবে

Enter series limit
5
0
1/4
1/2
3/4
1

  1. পান্ডাস সিরিজের আদর্শ বিচ্যুতি প্রিন্ট করুন

  2. একটি পান্ডাস সিরিজের গড় প্রিন্ট করুন

  3. পাইথনে প্রথম সিজিআই প্রোগ্রাম

  4. পাইথনে ভগ্নাংশ মডিউল