//program to get sum of 1+1,1+2,1+3,1+4,1+5,.... to nth term.
#include<stdio.h>
#include<stdio.h>
#include<conio.h>
void main()
{
float i,n,k=1,sum=0;
{
float i,n,k=1,sum=0;
printf("enter positive number for 'n'\n");
scanf("%f",&n);
scanf("%f",&n);
for(i=1;i<=n;i++)
{
{
sum=sum+(k+i);
}
}
printf("the sum=%f",sum);
getch();
}
--------------------------------------------------------------------------------------------------------------------------------------
logics in mind:
->enter a number for range for which you want to get sum, say 'n'.
}
--------------------------------------------------------------------------------------------------------------------------------------
logics in mind:
->enter a number for range for which you want to get sum, say 'n'.
->let a variable sum=0 with initial value '0'
->we get sum using formula sum=sum+k+i because in terms 1+1,1+2,1+3,1+4,1+5,.... ,the first value is same
and second value is changing so for first, k is working and for second, 'i' is working
->at last we display final sum.
No comments:
Post a Comment