1. Question:Write a program (wap) to delete an element at desired position from an array in c language 

    Answer
    #include<stdio.h>
    int main(){
      int a[50],i,pos,size;
      printf("\nEnter size of the array: ");
      scanf("%d",&size);
    
      printf("\nEnter %d elements in to the array: ",size);
      for(i=0;i<size;i++)
                scanf("%d",&a[i]);
    
      printf("\nEnter position where to delete: ");
      scanf("%d",&pos);
    
      i=0;
      while(i!=pos-1)
                i++;
      while(i<10){
                a[i]=a[i+1];
                i++;
      }
    
      size--;
      for(i=0;i<size;i++)
                printf(" %d",a[i]);
    
      return 0;
    }






    1. Report
  2. Question:How to insert or add an element in the array at specific or desired posting by using c programming language? 

    Answer
    #include<stdio.h>
    int main(){
    int a[50],size,num,i,pos,temp;
    printf("\nEnter size of the array: ");
    scanf("%d",&size);
    printf("\nEnter %d elements in to the array: ",size);
    for(i=0;iscanf("%d",&a[i]);
    printf("\nEnter position and number to insert: ");
    scanf("%d %d",&pos,&num);
    i=0;
    while(i!=pos-1)
    i++;
    temp=size++;
    while(i{
    a[temp]=a[temp-1];
    temp--;
    }
    a[i]=num;
    for(i=0;iprintf(" %d",a[i]);
    return 0;
    }






    1. Report
  3. Question:C code to find largest and smallest number in an array 

    Answer
    #include<stdio.h>
    int main(){
      int a[50],size,i,big,small;
    
      printf("\nEnter the size of the array: ");
      scanf("%d",&size);
      printf("\nEnter %d elements in to the array: ", size);
      for(i=0;i<size;i++)
          scanf("%d",&a[i]);
    
      big=a[0];
      for(i=1;i<size;i++){
          if(big<a[i])
               big=a[i];
      }
      printf("Largest element: %d",big);
     
      small=a[0];
      for(i=1;i<size;i++){
          if(small>a[i])
               small=a[i];
      }
      printf("Smallest element: %d",small);
    
      return 0;
    }
    Sample Output: Enter the size of the array: 4 Enter 4 elements in to the array: 2 7 8 1 Largest element: 8 Smallest element: 1






    1. Report
  4. 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
  5. 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
Copyright © 2025. Powered by Intellect Software Ltd