-->
Showing posts with label ..... Show all posts
Showing posts with label ..... Show all posts

program to get sum of (2x3)/5+(4x5)/7+(6x7)/9+,.... to nth term.

//program to get sum of (2x3)/5+(4x5)/7+(6x7)/9+,....           to nth term.
#include<stdio.h>
#include<conio.h>
void main()
{
   float i,n,k=2,m=3,p=5,sum=0;
      printf("enter  positive number for 'n'\n");
  scanf("%f",&n);
  for(i=1;i<=n;i++)
    {               
          sum=sum+(k*m)/p;
           k=k+2;
           m=m+2;
          p=p+2;        }
  printf("the sum=%f",sum);
getch();
}
-------------------------------------------------------------------------------------------------------------------------------------------------
logics in mind:
->enter a number for range for which you want to get sum, say 'n'.
->let a variable 'sum' with initial value '0'
->we get sum using formula sum=sum+(k*m)/p because in terms (2x3)/5+(4x5)/7+(6x7)/9+,...     ,
        the first value is k(2),second is m(3) and third is p(5).the values in second and all other terms are changing 
       by +2 so
        we put
          k=k+2;
           m=m+2;
          p=p+2; inside loop.
->at last we display final sum.

program to get 1+1,1+2,1+3,1+4,1+5,.... to nth term.

//program to get of 1+1,1+2,1+3,1+4,1+5,....           to nth term.
#include<stdio.h>
#include<conio.h>
void main()
{
   int i,n,k=1;
      printf("enter  positive number for 'n'\n");
  scanf("%d",&n);
  for(i=1;i<=n;i++)
    {               
         printf("%d+%d,",k,i);
        }
  
getch();
}
--------------------------------------------------------------------------------------------------------------------------------------
logics in mind:
->enter a number for range for which you want to get/print , say 'n'.
->let a variable k=1 with initial value '1'. We take this because first term has value '1'.
->Now we display each of the term using special format as shown above using printf.
->For first term we take variable k then we put characters '+' and ten 'i' because its value is changing 
  as the loop changes. We get that term.

program to get sum of 1+1,1+2,1+3,1+4,1+5,.... to nth term.

//program to get sum of 1+1,1+2,1+3,1+4,1+5,....           to nth term.
#include<stdio.h>
#include<conio.h>
void main()
{
   float i,n,k=1,sum=0;
      printf("enter  positive number for 'n'\n");
  scanf("%f",&n);
  for(i=1;i<=n;i++)
    {               
          sum=sum+(k+i);
        }
  printf("the sum=%f",sum);
getch();
}
--------------------------------------------------------------------------------------------------------------------------------------
logics in mind:
->enter a number for range for which you want to get sum, say 'n'.
->let a variable sum=0 with initial value '0'
->we get sum using formula sum=sum+k+i because in terms 1+1,1+2,1+3,1+4,1+5,....        ,the first value is same 
 and second value is changing so for first, k is working and for second, 'i' is working
->at last we display final sum.