Saturday, July 24, 2021

Numbers series and their sum

N terms of Natural numbers series and their sum ( 1^2+2^2 + 3^2+4^2+5^2 + 6^2 ..... n^2)

--------------------------------------------------------------------------------------------------- 

#include <stdio.h>

int main()

{

   int i,n,sum=0;

   printf("Input the number of terms in the series: \n");

   scanf("%d",&n);

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

   {

      sum+=(i)*(i);  //main logic series generation

   }

   printf("\nSum of Series upto %d terms : %d \n",n,sum);

  return 0;

}


------------------------------------------------------------------------------------------------

N terms of even numbers series and their sum ( 2^2 + 4^2 + 6^2 ..... n^2)

--------------------------------------------------------------------------------------------------- 

#include <stdio.h>

int main()

{

   int i,n,sum=0;

   printf("Input the number of terms in the series: \n");

   scanf("%d",&n);

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

   {

      sum+=(2i)*(2i);  //main logic even no's generation

   }

   printf("\nSum of Series upto %d terms : %d \n",n,sum);

  return 0;

}

--------------------------------------------------------------------------------------------------

N terms of odd numbers series and their sum ( 1^2 + 3^2 + 5^2+7^2 ..... n^2)

-----------------------------------------------------------------------------------------------

#include <stdio.h>

int main()

{

   int i,n,sum=0;

   printf("Input the number of terms in the series: \n");

   scanf("%d",&n);

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

   {

      sum+=(2i-1)*(2i-1);  //main logic odd number generation

   }

   printf("\nSum of Series upto %d terms : %d \n",n,sum);

  return 0;

}

1 comment:

  1. Understanding number series and their sum is essential for solving a wide range of mathematical problems. Whether you're working on simple arithmetic sequences or more complex series, mastering the concept can make calculations faster and easier. For better performance when working with coding or mathematical algorithms, consider using tools like Openssh Windows for smooth and secure connections.

    ReplyDelete