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
What is the hardest programming language?
When should a type cast be used?
How macro execution is faster than function ?
What is the difference between int main and void main?
Do character constants represent numerical values?
Read N characters in to an array . Use functions to do all problems and pass the address of array to function. 1. Print only the alphabets . If in upper case print in lower case vice versa. 2. Enter alphanumeric characters and form 2 array alphaets and digits.Also print the count of each array. 3. Find the count of a certain character. 4. Print the positions where a certain character occured. 5. Print the characters between successive array elements. 6. Find the largest and smallest charcter. How many times it each one occured. 7. Enter a certain range. Print out the array elements which occured between these range. 8. Reverse a character array without using another array. 9. Reverse an array region. 10. Replace a the array elements with it next character . Use a after z. 11. Code the array element with certain character as first alphabet. 12. Duplicate all the vowels in a character array. What is the new count. 13. Delete the vowels in a character array. What is the new array count. 14. Print the count of all characters in the array. 15. Enter n alphabets and store a upto tht charcter in array.What is the array count? 16. Sort a character array. 17. Merge 2 character arrays largearray,smallarray. 18. Find the pair with largest number of characters in between. 19. Find the numerical value of a charcter array. 20. Store n numeral characters in an arrray. Insert another numeral character in a certain position. 21. Insert a character in a sorted array. 22. Merge 2 sorted arrays in sorted fashion. 23. Duplicate the least occuring character. 24. Write a menu driven program to circular right/left shift an array of n elements. 25. Is the character array palindrome? if not make it palindrome. 26. Concatenate the first n charaters to the end of the string. 27. Print all n group of chracters which are palindrome. 28. Concatneate the reverse of last n characters to the array.
What functions are used in dynamic memory allocation in c?
How main function is called in c?
the real constant in c can be expressed in which of the following forms a) fractional form only b) exponential form only c) ascii form only d) both a and b
Given two strings S1 and S2. Delete from S2 all those characters which occur in S1 also and finally create a clean S2 with the relevant characters deleted.
which is conditional construct a) if statement b) switch statement c) while/for d) goto
What is the difference between functions getch() and getche()?
What is the difference between specifying a constant variable like with constant keyword and #define it? i.e what is the difference between CONSTANT FLOAT A=1.25 and #define A 1.25
What is extern keyword in c?
which is an algorithm for sorting in a growing Lexicographic order