Basic algebra formulas that you can revise anytime and anywhere

FORMULAS FOR BEGINNER (a+b) ^2= a^2+b^2+2ab (a+b) ^2= (a-b) ^2+4ab (a-b) ^2= a^2+b^2-2ab (a-b) ^2= (a+b) ^2-4ab a^2+b^2= (a+b) ^2-2ab a^2+b^2= (a-b) ^2+ 2ab a^2-b^2= (a+b) (a-b) (a+b+c) ^2= a^2+b^2+c^2+2(ab+bc+ac) (a-b-c) ^2= a^2+b^2+c^2-2(ab-bc+ac) (a+b) ^3= a^3+b^3+3ab(a+b) (a-b) ^3= a^3-b^3+3ab(a-b) a^3+b^3= (a+b) (a^2-ab+b^2) a^3-b^3= (a-b) (a^2+ab+b^2) a^4-b^4= (a^2-b^2) (a^2+b^2) = (a^2+b^2) (a+b) (a-b) a^5+b^5= (a+b) (a^4-a^3b+a^2b^2-ab^3+b^4) a^5-b^5= (a-b) (a^4+a^3b+a^2b^2+ab^3+b^4)

Sort related programming



Bubble sort

#include < stdio.h >

void bubble_sort(long [], long);

int main()
{
  long array[100], n, c, d, swap;

  printf("Enter number of elements\n");
  scanf("%ld", &n);

  printf("Enter %ld integers\n", n);

  for (c = 0; c < n; c++)
  scanf("%ld", &array[c]);

  bubble_sort(array, n);

  printf("Sorted list in ascending order:\n");

  for ( c = 0 ; c < n ; c++ )
  printf("%ld\n", array[c]);

  return 0;
}

void bubble_sort(long list[], long n)
{
  long c, d, t;

  for (c = 0 ; c < ( n - 1 ); c++)
  {
  for (d = 0 ; d < n - c - 1; d++)
  {
  if (list[d] > list[d+1])
  {

  t = list[d];
  list[d] = list[d+1];
  list[d+1] = t;
  }
  }
  }
}





Insertion sort

#include < stdio.h >

int main()
{
  int n, array[1000], c, d, t;

  printf("Enter number of elements\n");
  scanf("%d", &n);

  printf("Enter %d integers\n", n);

  for (c = 0; c < n; c++) {
  scanf("%d", &array[c]);
}

  for (c = 1 ; c < = n - 1; c++) {
  d = c;

  while ( d > 0 && array[d] < array[d-1]) {
  t = array[d];
  array[d] = array[d-1];
  array[d-1] = t;
  d--;
}
}

  printf("Sorted list in ascending order:\n");

  for (c = 0; c < = n - 1; c++) {
  printf("%d\n", array[c]);
}

  return 0;
}





Selection sort

#include < stdio.h >

int main()
{
  int array[100], n, c, d, position, swap;

  printf("Enter number of elements\n");
  scanf("%d", &n);

  printf("Enter %d integers\n", n);

  for ( c = 0 ; c < n ; c++ )
  scanf("%d", &array[c]);

  for ( c = 0 ; c < ( n - 1 ) ; c++ )
{
  position = c;

  for ( d = c + 1 ; d < n ; d++ )
{
  if ( array[position] > array[d] )
  position = d;
}
  if ( position != c )
{
  swap = array[c];
  array[c] = array[position];
  array[position] = swap;
}
}

  printf("Sorted list in ascending order:\n");
  for ( c = 0 ; c < n ; c++ )
  printf("%d\n", array[c]);

  return 0;
}





Print string

#include < stdio.h >

  int main()
{
  char array[100];

  printf("Enter a string\n");
  scanf("%s", array);

  printf("You entered the string %s\n",array);
  return 0;
}





String length

#include < stdio.h >
#include < string.h >

int main()
{
  char a[100];
  int length;
  printf("Enter a string to calculate it's length\n");
  gets(a);

  length = strlen(a);

  printf("Length of entered string is = %d\n",length);

  return 0;
}





Compare strings

#include < stdio.h >
#include < string.h >

int main()
{
  char a[100], b[100];

  printf("Enter the first string\n");
  gets(a);

  printf("Enter the second string\n");
  gets(b);

  if( strcmp(a,b) == 0 )
  printf("Entered strings are equal.\n");
  else
  printf("Entered strings are not equal.\n");

  return 0;
}





Concatenate strings

#include < stdio.h >
#include < string.h >

int main()
{
  char a[100], b[100];

  printf("Enter the first string\n");
  gets(a);

  printf("Enter the second string\n");
  gets(b);

  strcat(a,b);

  printf("String obtained on concatenation is %s\n",a);

  return 0;
}





Reverse string

#include < stdio.h >
#include < string.h >

  int main()
{
  char arr[100];

  printf("Enter a string to reverse\n");
  gets(arr);

  strrev(arr);

  printf("Reverse of entered string is \n%s\n",arr);

  return 0;
}



These are the Concept of C programming codes... We'll be glad if you share your valuable information with us regarding this topic, then it will be a golden oppertunity for all of us to improve ourselves and know more. Comment below!!

Comments

Popular posts from this blog

Are you willing to relocate or travel(HR QUESTION)

How to answer " why do you want to work at our company? "(HR QUESTION)