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

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

What is string length in c?

605


Describe how arrays can be passed to a user defined function

776


How do we print only part of a string in c?

579


What is difference between array and pointer in c?

534


main use of recursive function a) processing speed high b) reduce program length/reduce repeated statements c) if you do not, use iterative methods like, for, while or do-while d) all the above

612






What is the modulus operator?

730


Explain enumerated types in c language?

602


What are the differences between Structures and Arrays?

603


What are qualifiers in c?

571


Can we replace the struct function in tree syntax with a union?

774


how to make a scientific calculater ?

1561


Can include files be nested?

623


What is data types?

636


What is a 'null pointer assignment' error? Explain what are bus errors, memory faults, and core dumps?

727


What is a example of a variable?

551