اكتب برنامج بلغة C لعرض عدد n من المتسلسلة التوافقية ومجموعها

  • برمجة
  • برمجة سي c

اكتب برنامج بلغة C لعرض عدد n من المتسلسلة التوافقية ومجموعها

1 + 1/2 + 1/3 + 1/4 + 1/5 ... 1/n

الخرج المتوقع :

Input the number of terms : 5
                                                                                                                                                                                        
1/1 + 1/2 + 1/3 + 1/4 + 1/5
Sum of Series upto 5 terms : 2.283334

الأجوبة

/*Write a program in C to display the n terms of harmonic series and their sum. Go to the editor
1 + 1/2 + 1/3 + 1/4 + 1/5 ... 1/n terms
*/

#include <stdio.h>
void main()
{
   int i,n;
   float s=0.0;
   printf("Input the number of terms : ");
   scanf("%d",&n);
   printf("\n\n");
   for(i=1;i<=n;i++)
   {
       if(i<n)
       {
     printf("1/%d + ",i);
     s+=1/(float)i;
       }
     if(i==n)
     {
     printf("1/%d ",i);
     s+=1/(float)i;
     }
     }
        printf("\nSum of Series upto %d terms : %f \n",n,s);
}
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...