اكتب برنامج بلغة C لإيجاد مجموع المتسلسلة ادناه

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

اكتب برنامج بلغة C لإيجاد مجموع المتسلسلة ادناه :

[ 1-X^2/2!+X^4/4!- .........]

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

Input the Value of x :2
Input the number of terms : 5
                                                                                                              
the sum = -0.415873
Number of terms = 5
value of x = 2.000000

الأجوبة

طريقة 1 :

#include <stdio.h>
void main()
{
	float x,sum,t,d;
	int i,n;
	printf("Input the Value of x :");
	scanf("%f",&x);
	printf("Input the number of terms : ");
	scanf("%d",&n);
	sum =1; t = 1;
	for (i=1;i<n;i++)
	{
	  d = (2*i)*(2*i-1);
	  t = -t*x*x/d;
	  sum =sum+ t;
	}
	printf("\nthe sum = %f\nNumber of terms = %d\nvalue of x = %f\n",sum,n,x);
}

طريقة 2 :

#include <stdio.h>

void main()
{
	float x,s,t,num=1.00,fac=1.00;
	int i,n,pr,y=2,m=1;

	printf("Input the Value of x :");
	scanf("%f",&x);
	printf("Input the number of terms : ");
	scanf("%d",&n);
	s=1.00; t=1.00;

	for (i=1;i<n;i++)
	{
            for(pr=1;pr<=y;pr++)
                 {
                   fac=fac*pr;
                   num=num*x;

                 }   
          m=m*(-1);
          num=num*m;
          t=num/fac;
	  s=s+t;
          y=y+2;
          num=1.00; 
          fac=1.00;
          
	}
	printf("\nthe sum = %f\nNumber of terms = %d\nvalue of x = %f\n",s,n,x);
}
هل كان المحتوى مفيد؟

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

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