Print output of : 1 - 2! / 2 + 3! / 3 - 4! / 4 + 5! / 5.........n | User given | C-Program

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

Tips:

1.Use nested loops.
2.Use if and else.

Code:

#include<stdio.h>

void main()

{
    int i,j,x,a,b=0;

    printf("Enter the range:\n");

    scanf("%d",&x);

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

    {
        if(i%2==0 && x!=i)

            printf("%d!/%d+ ",i,i);

        else if(i%2!=0 && x!=i)

            printf("%d!/%d- ",i,i);

        else

            printf("%d!/%d= ",i,i);

        a=1;

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

            a=a*j;

            if(i%2==0)

                a=-a/i;

            else

                a=a/i;

            b=b+a;
    }

    printf("%d",b);
 }

Output: 

Comments

Popular posts from this blog

TOP 10 PROGRAMMING LANGAUAGES COMMING 2021 | ARTICLE

Write a C-program to swap two number:

Print Fibonacci Series using Recursion | C program :