Write a program for the following series:
1*3*5-2*4*6+3*5*7-4*6*8+.................up to nterms

Answer Posted / sri k. hari

/* Author : Sri K. Hari
Description : program for series
1*3*5-2*4*6+3*5*7-4*6*8...........upto n terms
*/

#include<stdio.h>
#include<conio.h>

void main()
{
int n,i,res,finres;
char opt ;
clrscr () ;
do
{
res = 0 ;
finres = 0 ;
printf ( " \n Enter the last number " ) ;
scanf("%d",&n);

for ( i = 1 ; i <= n ;i++ )
{
res = ( i * (i+2) * (i+4) ) ;

if ( (i%2) == 0 )
finres = finres - res ;
else
finres = finres + res ;
}
printf ( " \n the result is : %d ", finres) ;
printf ( "Do you want to continue (Y/N)" ) ;
scanf ( "%s",&opt) ;
}while ( (opt == 'y' ) || (opt == 'Y' ) ) ;
}

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the process to generate random numbers in c programming language?

607


What is hashing in c language?

611


What does 3 mean in texting?

609


please send me the code for multiplying sparse matrix using c

1723


Which is more efficient, a switch statement or an if else chain?

578






Explain the bubble sort algorithm.

639


Explain Basic concepts of C language?

643


What is the purpose of the statement: strcat (S2, S1)?

638


explain what is a newline escape sequence?

683


What are the types of data structures in c?

596


What is character constants?

711


how to print electricity bill according to following charges first 100 units -1rs per unit for next 200 units-1.50 rs per unit without using conditions

2719


Why array is used in c?

549


What is meant by initialization and how we initialize a variable?

583


What is the need of structure in c?

563