Wednesday, January 4, 2023

C Programming. Sum sequence is :- 1 + 1/2 + 1/3 + 1/4 ......n

 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

Selection Sort Using C programming.

Selection sort is a simple and efficient sorting algorithm that works by repeatedly selecting the smallest (or largest) element from the un...