c program to manipulate x=1+3+5+...+n using recursion

Answers were Sorted based on User's Feedback



c program to manipulate x=1+3+5+...+n using recursion..

Answer / boni ravi

#include<stdio.h>
#include<conio.h>
main()
{
int i,n;
int x=0;
clrscr();
printf("enter n value");
scanf("%d",&n);
for(i=1;i<=n;i=i+2)
{
x=i+x;
}
printf("output is%d",x);
}

Is This Answer Correct ?    9 Yes 10 No

c program to manipulate x=1+3+5+...+n using recursion..

Answer / naresh m

main()
{
int sum=0,i;
int p,n;
printf("enter value for n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
p=(i*2-1);
sum=sum+p;
}
printf("sum is %d",sum);
}

Is This Answer Correct ?    2 Yes 5 No

Post New Answer

More C Interview Questions

How can I do serial ("comm") port I/O?

0 Answers   Celstream,


Can you assign a different address to an array tag?

0 Answers  


c programming of binary addition of two binary numbers

4 Answers  


What is the explanation for the dangling pointer in c?

0 Answers  


what is the defrenece between structure and union

5 Answers   Aloha Technology,






What are categories used for in c?

0 Answers  


What is calloc()?

0 Answers   Adobe,


How do shell structures work?

0 Answers  


how to TOGGLE Nth bit of variable in a MACRO

1 Answers   NDS,


which of the function operator cannot be over loaded a) <= b)?: c)== d)*

10 Answers   Cisco, CTS, Google, HCL, HP,


Write a program, where i have a grid with many cells, how many paths are possible from one point to other desired points.

0 Answers   Expedia,


How pointer is different from array?

0 Answers  


Categories