Illustrate it
summing the series 2+4+6+......to n terms using
(i) while loop (ii) do-while loop
Answers were Sorted based on User's Feedback
Answer / 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 |
Answer / srujitha
// while loop
int main()
{
int n = 3,sum = 0,i = 2, count = 0;
while(n > count)
{
sum = sum + i;
i = i+2;
count++;
}
printf("SUM = %d ",sum);
}
// do while loop
int main()
{
int n = 3,sum = 0,i = 2, count = 0;
do
{
sum = sum + i;
i = i+2;
count++;
}
while(n > count);
printf("SUM = %d ",sum);
}
Is This Answer Correct ? | 0 Yes | 0 No |
Are global variables static in c?
Blade logic interview question. 1st round is a written tests with 15 multiple questions from c and c++. All are simple basic question. Like int main () { Int i=65; Return printf(ā%cā, i); } 2nd and 3rd round is technical interview. The position for which I was interview was core UNIX and c. Yes it is for system programming. The company has product name blade server. For their server they are creating their own command for their purpose. Example cd command. We can implement it in a c program by using the chdir() function. So the question asks related to PID, fork, pipe, shared memory, signal. Write a program in c which will act as cp command.
1 Answers BladeLogic, Infosys,
an algorithem for the implementation of circular doubly linked list
When should the const modifier be used?
can u write a program in C, which does not use = (eqaul)or any arithmatic assignment(like -=,+=,*= etc) operator to swap to number?
what is function pointer?
what is the differnce between AF_INET and PF_INET?
5 Answers Systems Plus, Wipro,
What does do in c?
What will be the outcome of the following conditional statement if the value of variable s is 10?
how to find sum of digits in C?
What does volatile do?
main() { int a[3][4] ={1,2,3,4,5,6,7,8,9,10,11,12} ; int i, j , k=99 ; for(i=0;i<3;i++) for(j=0;j<4;j++) if(a[i][j] < k) k = a[i][j]; printf("%d", k); }
4 Answers Vector, Wipro, Zoho,