Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

 Illustrate it 
 summing the series 2+4+6+......to n terms using 
(i) while loop (ii) do-while loop

Answer Posted / raju kalyadapu

i). using while-loop

int main()
{
int sum=0,n,i=0,j=2;
printf("Enter 2+4+6+...n upto nth term:");
scanf("%d",&n);
while(i++<n)
{
j=2*i;
sum=sum+i*2;
}
getch();
return 0;
}

ii). using do-while loop

int main()
{
int sum=0,n,i=0,j=2;
printf("Enter 2+4+6+...n upto nth term:");
scanf("%d",&n);

do 
{
j=2*i;
sum=sum+i*2;
} while(i++<n);
printf("
Sum of the Series 2+4+6+----%d is:%d",j,sum);

}

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

how much salary u want ? why u join in our company? your domain is core sector why u prefer software ?

1921


what do you mean by inline function in C?

1008


What is the time and space complexities of merge sort and when is it preferred over quick sort?

1013


Explain the difference between structs and unions in c?

959


What is the best way to comment out a section of code that contains comments?

1263


Explain what are bus errors, memory faults, and core dumps?

1223


Why doesn't C support function overloading?

2611


How can you convert integers to binary or hexadecimal?

979


Why c language?

1006


What are header files? What are their uses?

1123


What is a far pointer in c?

990


What is getche() function?

987


How can I invoke another program (a standalone executable, or an operating system command) from within a c program?

1131


Is flag a keyword in c?

1109


WRITE A PROGRAM TO MERGE TWO SORTED ARRAY USING MERGE SORT TECHNIQUE..

1988