Tuesday, March 5, 2024

20. a-a²+a³-a⁴... :—

20. a-a²+a³-a⁴... :—


#include<stdio.h>

int main()

{

    int i,n,a,s,sum;

    printf("enter value of n and a ");

    scanf("%d%d",&n,&a);

    sum=0,s=-1;

    for(i=1;i<=n;i++)

    {

        s=s*-1;

        sum=sum+pow(a,i)*s;

    }

    printf("%d",sum);

    return 0;

}


No comments:

Post a Comment