Showing posts with label Sum Sequence. Show all posts
Showing posts with label Sum Sequence. Show all posts

Wednesday, January 4, 2023

C Programming. Sum sequence :- 1-2+3-4+5-6+7.....n .

Sum sequence :- 1-2+3-4+5-6+7.....n 



#include<stdio.h>
int main(){
       int s=0;
       int i,n;
       printf("Enter a number : ");
       scanf("%d",&n);
       for (i=1; i<=n; i++){
              if(i%2==0){
                     s=s-i;
              }
              else{
                     s=s+i;
              }
       }
       printf("Sum = %d",s);
       return 0;
}

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;
}

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...