code:
series: 1/1+1/2+1/3+….+1/N
#include<stdio.h> int main() { int N,i; float sum; printf("Enter N:"); scanf("%d",&N); sum=0; i=1; do{ sum=sum+1/(float)i; i++; }while(i<=N); printf("Sum of series: %f",sum); return 0; }
series: 1/1-1/2+1/3-1/4+1/5….1/N
code:
#include<stdio.h> int main() { int i,N,sign; float sum; printf("Enter value of N:"); scanf("%d",&N); sum=0; sign=1; do{ sum=sum+(1.0/(float)i)*sign; i++; sign=sign*(-1); }while(i<=N); printf("Sum=%f",sum); return 0; }
Series: 1^2/1!+2^2/2!+3^2/3!+4^2/4!+…..+N^2/N!
code:
#include<stdio.h> int main(){ int i, N, factorial; float sum; printf("Enter N:"); scanf("%d",&N); for(sum=0,i=1,factorial=1;i<N;i++,factorial=factorial*i){ sum=sum+(i*i)/(float)factorial; } printf("%f",sum); return 0; }
Series: 1^2/1!+3^2/2!+5^2/5!+….N^2/N!
code:
#include<stdio.h> int main(){ int i, N, x,factorial; float sum; printf("Enter number of terms N:"); scanf("%d",&N); for(sum=0,i=1,factorial=1,x=1;i<=N;i++,factorial=factorial*(x-1)*x){ sum=sum+(x*x)/(float)factorial; x=x+2; } printf("%f",sum); return 0; }
program to find summation of squares of all numbers from 5 to 25
series: 25+36+49+…..+625=?
code:
#include<stdio.h> int main(){ int sum,i; sum=0; for(i=5;i<=25;i++) { sum=sum+(i*i); } printf("%d",sum); return 0; }