Given an int variable n that has been initialized to a
positive value and, in addition, int variables k and
total that have already been declared, use a do...while
loop to compute the sum of the cubes of the first n whole
numbers, and store this value in total . Thus if n equals
4, your code should put 1*1*1 + 2*2*2 + 3*3*3 + 4*4*4 into
total . Use no variables other than n , k , and total .




Answers were Sorted based on User's Feedback



Given an int variable n that has been initialized to a positive value and, in addition, int vari..

Answer / c.muruganandham

total=0;
k=1;
do
{
total=total+k*k*k;
k++;
}while(k<=n)

Is This Answer Correct ?    27 Yes 32 No

Given an int variable n that has been initialized to a positive value and, in addition, int vari..

Answer / sujeesh krishnan

#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
int n=3;
int k=1,total=0;
do
{
total=total+(pow(k,3));
k=k+1;
}
while(k<=n);
printf("%d",total);
getch();
return 0;
}

Is This Answer Correct ?    3 Yes 9 No

Given an int variable n that has been initialized to a positive value and, in addition, int vari..

Answer / sachin

total=0;
while(n>=1)
{
total+=n*n*n;
n--;
}

Is This Answer Correct ?    4 Yes 17 No



Post New Answer



More C C++ Errors Interview Questions

How to create a program that lists the capital country when told what the original country is? (Terribly sorry, I'm a novice programmer and would appreciate any help ;). Cheers, Alexxis

0 Answers  


What are the different types of errors in C and when they occur?

4 Answers  


Write down the difference between c. Loop and goto statement d. (!0) and (!1) e. (1= =! 1) and (1!=1) f. NULL and !NULL

0 Answers  


How to reverse a linked list without using array & -1? Thank you.

2 Answers   Satyam, Access,


Write a program to accept two strings of Odd lengths. Then take all odd characters from one string and even characters from the other and concatenate and produce a string.

1 Answers  






Display this kind of output on screen. 1 0 1 1 0 1 3. Display this kind of output on screen. 1 1 0 1 0 1 4. Display this kind of output on screen. 1 1 0 1 0 1 5.Display this kind of output on screen. 1 2 3 4 5 6 7 8 9 10

1 Answers  


what is exceptions?

5 Answers   Wipro, HCL,


what are the techniques for reducing the fragility of a memory bug?

1 Answers  


how tally is useful?

2 Answers  


WHAT WILL BE THE OUTPUT OF THE FOLLOWING QUESTION void main() { int x=4,y=3,z; z=x-- -y; printf("%d%d%d",x,y,z); }

25 Answers   HCL,


what is the large sustained error signal that eventually cause the controller output to drive to its limit

1 Answers   TCS,


#include<>stdio.h> #include<>conio.h> { printf("hello"); void main() getch(); } what the out put of this program and why ......plz clear my answer

10 Answers   Wipro,






Categories