1. Question:Sum of GP series in c programming language 

    Answer
    #include<stdio.h>
    #include<math.h>
    
    int main(){
    
        float a,r,i,tn;
        int n;
        float sum=0;
    
        printf("Enter the first number of the G.P. series: ");
        scanf("%f",&a);
    
        printf("Enter the total numbers in the G.P. series: ");
        scanf("%d",&n);
    
        printf("Enter the common ratio of G.P. series: ");
        scanf("%f",&r);
    
        sum = (a*(1 - pow(r,n+1)))/(1-r);
           tn = a * (1 -pow(r,n-1));
    
        printf("tn term of G.P.: %f",tn);
        printf("\nSum of the G.P.: %f",sum);
    
        return 0;
    }
    Sample output: Enter the first number of the G.P. series: 1 Enter the total numbers in the G.P. series: 5 Enter the common ratio of G.P. series: 2 tn term of G.P. : 16.000000 Sum of the G.P. : 63.000000






    1. Report
  2. Question:Sum of infinite GP series in c programming language 

    Answer
    #include<stdio.h>
    
    int main(){
    
        float a,r;
        float sum=0;
    
        printf("Enter the first number of the G.P. series: ");
        scanf("%f",&a);
    
        printf("Enter the common ratio of G.P. series: ");
        scanf("%f",&r);
    
        if(1 > r)
             sum = a/(1-r);
        else
             sum = a/(r-1);
    
        printf("\nSum of the infinite G.P. series: %f",sum);
    
        return 0;
    }
    Sample output: Enter the first number of the G.P. series: 1 Enter the common ratio of G.P. series: .5 Sum of the infinite G.P. series: 2.000000 Enter the first number of the G.P. series: 5 Enter the common ratio of G.P. series: 2 Sum of the infinite G.P. series: 5.000000






    1. Report
  3. Question:Source code of simple bubble sort implementation using array ascending order in c programming language 

    Answer
    #include<stdio.h>
    int main(){
    
      int s,temp,i,j,a[20];
    
      printf("Enter total numbers of elements: ");
      scanf("%d",&s);
    
      printf("Enter %d elements: ",s);
      for(i=0;i<s;i++)
          scanf("%d",&a[i]);
    
      //Bubble sorting algorithm
      for(i=s-2;i>=0;i--){
          for(j=0;j<=i;j++){
               if(a[j]>a[j+1]){
                   temp=a[j];
                  a[j]=a[j+1];
                  a[j+1]=temp;
               }
          }
      }
    
      printf("After sorting: ");
      for(i=0;i<s;i++)
          printf(" %d",a[i]);
    
      return 0;
    }
    Sample Output: Enter total numbers of elements: 5 Enter 5 elements: 6 2 0 11 9 After sorting: 0 2 6 9 11






    1. Report
  4. Question:Source code of simple insertion sort implementation using array in ascending order in c programming language 

    Answer
    #include<stdio.h>
    int main(){
    
      int i,j,s,temp,a[20];
    
      printf("Enter total elements: ");
      scanf("%d",&s);
    
      printf("Enter %d elements: ",s);
      for(i=0;i<s;i++)
          scanf("%d",&a[i]);
    
      for(i=1;i<s;i++){
          temp=a[i];
          j=i-1;
          while((temp<a[j])&&(j>=0)){
          a[j+1]=a[j];
              j=j-1;
          }
          a[j+1]=temp;
      }
    
      printf("After sorting: ");
      for(i=0;i<s;i++)
          printf(" %d",a[i]);
    
      return 0;
    }
    Sample Output: Enter total elements: 5 Enter 5 elements: 3 7 9 0 2 After sorting: 0 2 3 7 9






    1. Report
  5. Question:Source code of simple Selection sort implementation using array ascending order in c programming language 

    Answer
    #include<stdio.h>
    int main(){
    
      int s,i,j,temp,a[20];
    
      printf("Enter total elements: ");
      scanf("%d",&s);
    
      printf("Enter %d elements: ",s);
      for(i=0;i<s;i++)
          scanf("%d",&a[i]);
    
      for(i=0;i<s;i++){
          for(j=i+1;j<s;j++){
               if(a[i]>a[j]){
                   temp=a[i];
                  a[i]=a[j];
                  a[j]=temp;
               }
          }
      }
    
      printf("After sorting is: ");
      for(i=0;i<s;i++)
          printf(" %d",a[i]);
    
      return 0;
    }
    Sample Output: Enter total elements: 5 Enter 5 elements: 4 5 0 21 7 The array after sorting is: 0 4 5 7 21






    1. Report
Copyright © 2025. Powered by Intellect Software Ltd