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
Why shouldn’t I start variable names with underscores?
How do I get a null pointer in my programs?
What are the complete rules for header file searching?
What does c in a circle mean?
What was noalias and what ever happened to it?
What is s or c?
How can I call fortran?
Is it better to use malloc() or calloc()?
What is extern keyword in c?
What do you mean by dynamic memory allocation in c?
Explain how can you determine the size of an allocated portion of memory?
Is flag a keyword in c?
Explain pointers in c programming?
Tell me about low level programming languages.
What does %d do in c?