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 |
Write a program that reads a dynamic array of 40 integers and displays only even integers
C statement to copy a string without using loop and library function..
String copy logic in one line.
#include<stdio.h> main() { int a[2][2][2] = { {10,2,3,4}, {5,6,7,8} }; int *p,*q; p=&a[2][2][2]; *q=***a; printf("%d..%d",*p,*q); }
What is the hidden bug with the following statement? assert(val++ != 0);
write a program in c language to get the value of arroy keys pressed and display the message which arrow key is pressed?
main() { int a=2,*f1,*f2; f1=f2=&a; *f2+=*f2+=a+=2.5; printf("\n%d %d %d",a,*f1,*f2); }
main() { unsigned int i=10; while(i-->=0) printf("%u ",i); }
/*what is the output for*/ void main() { int r; printf("Naveen"); r=printf(); getch(); }
#include<conio.h> main() { int x,y=2,z,a; if(x=y%2) z=2; a=2; printf("%d %d ",z,x); }
main() { int i = 3; for (;i++=0;) printf(ā%dā,i); }
Predict the Output: int main() { int *p=(int *)2000; scanf("%d",2000); printf("%d",*p); return 0; } if input is 20 ,what will be print