Write a code to get the summation of the following series: 1 + 3 + 5 + 7 + ………… + 2n-1 terms - C PROGRAMMING LANGUAGE @

C PROGRAMMING LANGUAGE @

LEARN TODAY LEAD TOMORROW

Tuesday, June 13, 2017

Write a code to get the summation of the following series: 1 + 3 + 5 + 7 + ………… + 2n-1 terms

 /*Write a code to get the summation of the following series:
1 + 3 + 5 + 7 + ………… + 2n-1 terms */
                                       
Algorithm:
procedure()
sum=0;
for i=1 to n;
sum=sum+2*i-1
end procedure;

source code:
#include<stdio.h>
int main()
{
int i,n,sum=0;
printf("Enter the number: ");
scanf("%d",&n); //assign the value of n is 10
for(i=1;i<=n;i++)
{
sum=sum+2*i-1;
}
printf("Sum is %d.\n",sum);
}

output:
sum is 100.
 

No comments:

Post a Comment