Tuesday, March 5, 2024

18.1!-2!+3!-4!+...n :—

 


18.1!-2!+3!-4!+...n :—


#include<stdio.h>

int main()

{

    int i,f,n,s,sum;

    printf("enter a value of n ");

    scanf("%d",&n);

    sum=0,f=1,s=-1;

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

    {

        s=s*-1;

        f=f*i;

        sum=sum+f*s;

    }

    printf("%d",sum);

    return 0;

}


No comments:

Post a Comment