Under linux environment can u please provide a c code for
computing sum of series 1-2+3-4+5......n terms and
-1+2-3+4-5...n terms..
Answers were Sorted based on User's Feedback
Answer / sudhanshu_kmr
#include<stdio.h>
int main()
{
int i,n,sum=0;
printf("\n Enter the n: " );
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(i%2==0) /* for series is -1 +2 -3.......*/
sum= sum+i;
else
sum = sum-i;
}
printf(" Sum of %d terms is %d \n",n,sum);
return 0;
}
/* For series 1 - 2 +3 ....
then use
for(i=1;i<=n;i++)
{
if(i%2==0)
sum= sum -i;
else
sum = sum +i;
}
*/
Is This Answer Correct ? | 5 Yes | 1 No |
Answer / sai prasad raju
I will not tell u.
Why should i tell?
off
Is This Answer Correct ? | 1 Yes | 1 No |
What are segment and offset addresses?
void main() { static int i; while(i<=10) (i>2)?i++:i--; printf(“%d”, i); }
Find your day from your DOB?
15 Answers Accenture, Microsoft,
What is the problem with the following code segment? while ((fgets(receiving array,50,file_ptr)) != EOF) ;
Write a routine to implement the polymarker function
main() { int i=5; printf(“%d”,i=++i ==6); }
create a login program that ask username and password. if you input username or password 3 times wrong, the program will terminate else the program will prompt a message "congratulations"
write a program in c to merge two array
You are given any character string. Find the number of sets of vowels that come in the order of aeiou in the given string. For eg., let the given string be DIPLOMATIC. The answer returned must be "The number of sets is 2" and "The sets are "IO and AI". Vowels that form a singleton set must be neglected. Try to post the program executable in gcc or g++ or in java.
Give a oneline C expression to test whether a number is a power of 2?
25 Answers EA Electronic Arts, Google, Motorola,
Program to find the largest sum of contiguous integers in the array. O(n)
Is the following statement a declaration/definition. Find what does it mean? int (*x)[10];