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

What is the output of the program given below #include<stdio.h> main() { char i=0; for(;i>=0;i++) ; printf("%d\n",i); }

21 Answers   ADITI, Student, TCS,


Q.1 write aprogram to stack using linklist o insert 40 items? Q.2 write a program to implement circular queue with help of linklist?

0 Answers   TCS,


What is methods in c?

0 Answers  


how to execute a program using if else condition and the output should enter number and the number is odd only...

0 Answers  


How can I write a function analogous to scanf?

0 Answers  


To find whether a number is even or odd without using any conditional operator??

12 Answers   College School Exams Tests, IBM,


What is the difference between array and structure in c?

0 Answers  


Explain what is the difference between the expression '++a' and 'a++'?

0 Answers  


# define prod(a,b)=a*b main() { int x=2; int y=3; printf("%d",prod(x+2,y-10)); } the output of the program is a.8 b.6 c.7 d.none

7 Answers   Microsoft, TCS,


Write the program with at least two functions to solve the following problem. The members of the board of a small university are considering voting for a pay increase for their 5 faculty members. They are considering a pay increase of 8%. Write a program that will prompt for and accept the current salary for each of the faculty members, then calculate and display their individual pay increases. At the end of the program, print the total faculty payroll before and after the pay increase, and the total pay increase involved.

1 Answers  


the maximum value that an integer constant can have is a) -32767 b) 32767 c) 1.701e+38 d) -1.7014e+38

1 Answers  


program to find out date after adding 31 days to a date in the month of febraury also consider the leap year

0 Answers  


Categories