اكتب برنامج c لمعرفة مجموع سلسلة .A.P

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

اكتب برنامج c لمعرفة مجموع سلسلة .A.P

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

Find out the sum of A.P. series :
 ----------------------------------------
Input  the starting number of the A.P. series: 1
Input the number of items for  the A.P. series: 10
Input  the common difference of A.P. series: 4
                                                                                                              
The Sum of the  A.P. series are :
1 + 5 + 9 + 13 + 17 + 21 + 25 + 29 + 33 + 37 = 190

الأجوبة

/*Write a c program to find out the sum of an A.P. series*/

#include <stdio.h>
#include <math.h>

void main(){

    int n1,df,n2,i,ln;
    int s1=0;

     printf("\n\n  Find out the sum of A.P. series :\n ");
     printf("----------------------------------------\n");


    printf("Input  the starting number of the A.P. series: ");
    scanf("%d",&n1);

    printf("Input the number of items for  the A.P. series: ");
    scanf("%d",&n2);

    printf("Input  the common difference of A.P. series: ");
    scanf("%d",&df);

    s1 = ( n2 * ( 2 * n1 + ( n2 -1 ) * df ) )/ 2;
    ln = n1 + (n2-1) * df;
    printf("\nThe Sum of the  A.P. series are : \n");

    for(i=n1;i<=ln; i= i + df ){
         if (i != ln)
             printf("%d + ",i);
         else
             printf("%d = %d \n\n",i,s1);
    }

}
هل كان المحتوى مفيد؟

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

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