marq

Dr. Charles Simonyi is the Father of Modern Microsoft Excel                                           JavaScript was originally developed by Brendan Eich of Netscape under the name Mocha, later LiveScript, and finally renamed to JavaScript.                                           The word "Biology" is firstly used by Lamarck and Treviranus                                           Hippocrates (460-370 bc) is known as father of medicine.                                           Galene, 130-200 is known as father of Experimental Physology                                           Aristotle (384-322 BC) is known as Father of Zoology because he wrote the construction and behavior of different animals in his book "Historia animalium"                                           Theophrastus(370-285 BC) is known as father of Botany because he wrote about 500 different plants in his book "Historia Plantarum".                                           John Resig is known as Father of Jquery -                                          HTML is a markup language which is use to design web pages. It was invented in 1990 by Tim Berners-Lee.                                                                The Google was founded by Larry Page and Sergey Brin.                                                                Rasmus Lerdorf was the original creator of PHP. It was first released in 1995.                                                               Facebook was founded by Mark Zuckerberg                                                               Bjarne Stroustrup, creator of C++.                                                                Dennis Ritchie creator of C                                                                                                                              James Gosling, also known as the "Father of Java"                                          At 11.44%, Bihar is India's fastest growing state                                          Father of HTML -Tim Berners Lee                                          orkut was created by Orkut Büyükkökten, a Turkish software engineer                    Photoshop: It came about after Thomas Knoll, a PhD student at the University of Michigan created a program to display grayscale images on a monochrome monitor which at the time was called 'Display'.

c program to reverse an array



c program to reverse an array :- This program reverses the array elements. For example if a is an array of integers with three elements
such that
a[0] = 1
a[1] = 2
a[2] = 3
then on reversing the array will be
a[0] = 3
a[1] = 2
a[0] = 1
Given below is the c code to reverse an array .

C programming code

#include <stdio.h>
 
int main()
{
   int n, c, d, a[100], b[100];
 
   printf("Enter the number of elements in array\n");
   scanf("%d", &n);
 
   printf("Enter the array elements\n");
 
   for (c = 0; c < n ; c++)
      scanf("%d", &a[c]);
 
   /*
    * Copying elements into array b starting from end of array a
    */
 
   for (c = n - 1, d = 0; c >= 0; c--, d++)
      b[d] = a[c];
 
   /*
    * Copying reversed array into original.
    * Here we are modifying original array, this is optional.
    */
 
   for (c = 0; c < n; c++)
      a[c] = b[c];
 
   printf("Reverse array is\n");
 
   for (c = 0; c < n; c++)
      printf("%d\n", a[c]);
 
   return 0;
}
Output of program:
reverse array

Reverse array by swapping(without using additional memory)

#include <stdio.h>
 
int main() {
  int array[100], n, c, t, end;
 
  scanf("%d", &n);
  end = n - 1;
 
  for (c = 0; c < n; c++) {
    scanf("%d", &array[c]);
  }
 
  for (c = 0; c < n/2; c++) {
    t          = array[c];
    array[c]   = array[end];
    array[end] = t;
 
    end--;
  }
 
  printf("Reversed array elements are:\n");
 
  for (c = 0; c < n; c++) {
    printf("%d\n", array[c]);
  }
 
  return 0;
}

c program to reverse an array using pointers

#include<stdio.h>
#include<stdlib.h>
 
void reverse_array(int*, int);
 
main()
{
   int n, c, *pointer;
 
   scanf("%d",&n);
 
   pointer = (int*)malloc(sizeof(int)*n);
 
   if( pointer == NULL )
      exit(EXIT_FAILURE);
 
   for ( c = 0 ; c < n ; c++ )
      scanf("%d",(pointer+c));
 
   reverse_array(pointer, n);
 
   printf("Original array on reversal is\n");
 
   for ( c = 0 ; c < n ; c++ )
      printf("%d\n",*(pointer+c));
 
   free(pointer);
 
   return 0;
}
 
void reverse_array(int *pointer, int n)
{
   int *s, c, d;
 
   s = (int*)malloc(sizeof(int)*n);
 
   if( s == NULL )
      exit(EXIT_FAILURE);
 
   for ( c = n - 1, d = 0 ; c >= 0 ; c--, d++ )
      *(s+d) = *(pointer+c);
 
   for ( c = 0 ; c < n ; c++ )
      *(pointer+c) = *(s+c);
 
   free(s);
}


No comments:

Post a Comment