Sum sequence is :-
1 + 1/2 + 1/3 + 1/4 ......n
#include<stdio.h>
int main(){
float s=0;
int i,n;
printf("Enter a number : ");
scanf("%d",&n);
for (i=1; i<=n; i++){
s=s+(1/(float)i);
}
printf("Sum = %f",s);
return 0;
}
No comments:
Post a Comment