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

write a c program to check weather a particluar bit is set or not?

5 Answers   IBM,


how to write a program which adds two numbers without using semicolon in c

2 Answers  


in b=6.6/a+(2*a+(3*c)/a*d)/(2/n); which operation will be performed first a) 6.6/a b) 2*a c) 3*c d) 2/n

1 Answers  


write a program in C to swap two variables

7 Answers   Attrabyte, Marlabs,


What are disadvantages of C language.

0 Answers   iNautix,






write a program for fibonaci series by using while loop in c?

2 Answers  


how can i write a program that prints out a box such that whenever i press any key8(coordinate number) on the keyboard, the box moves.

0 Answers  


how can write all 1to 100 prime numbers using for loop,if and break ?

2 Answers   TCS,


Is both getch() and getchar() functions are similar? if it is similar means why these two functions are used for same usage? if it is not similar means what is the difference?

1 Answers   Infosys,


Write a code of a general series where the next element is the sum of last k terms.

0 Answers   Aspiring Minds,


What is the purpose of scanf() and printf() functions?

0 Answers  


WAP to accept first name,middle name & last name of a student display its initials?

5 Answers   AITH, NIIT,


Categories