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 |
Give a one-line C expression to test whether a number is a power of 2.
How to use power function under linux environment.eg : for(i=1;i<=n;i++){ pow(-1,i-1)} since it alerts undefined reference to 'pow'.
main() { int i=5,j=10; i=i&=j&&10; printf("%d %d",i,j); }
main() { char *p="GOOD"; char a[ ]="GOOD"; printf("\n sizeof(p) = %d, sizeof(*p) = %d, strlen(p) = %d", sizeof(p), sizeof(*p), strlen(p)); printf("\n sizeof(a) = %d, strlen(a) = %d", sizeof(a), strlen(a)); }
Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned long in decimal.
6 Answers Fusion Systems GmbH,
main() { int a=10,*j; void *k; j=k=&a; j++; k++; printf("\n %u %u ",j,k); }
How can i find first 5 natural Numbers without using any loop in c language????????
main() { int i; float *pf; pf = (float *)&i; *pf = 100.00; printf("\n %d", i); } a. Runtime error. b. 100 c. Some Integer not 100 d. None of the above
main() { int i = 3; for (;i++=0;) printf(“%d”,i); }
main() { void swap(); int x=10,y=8; swap(&x,&y); printf("x=%d y=%d",x,y); } void swap(int *a, int *b) { *a ^= *b, *b ^= *a, *a ^= *b; }
void main() { int *mptr, *cptr; mptr = (int*)malloc(sizeof(int)); printf(“%d”,*mptr); int *cptr = (int*)calloc(sizeof(int),1); printf(“%d”,*cptr); }
main() { char str1[] = {‘s’,’o’,’m’,’e’}; char str2[] = {‘s’,’o’,’m’,’e’,’\0’}; while (strcmp(str1,str2)) printf(“Strings are not equal\n”); }