Computer Concept & Programming In C - Unit IV - 11

/* Q.22 Write a program in C to accept 10 integers and print the in the reverse order.*/                                                                          (AKTU. 2008 - 09)
Ans.
#include<stdio.h>
#include<conio.h>
void main()
{
 int i;            /*loop counter*/
 long integers[10];
 clrscr();

 /* Taking input */

 printf("\nEnter the 10 integers ");
 for( i = 0; i < 10; i++)
    {
      printf("\nInteger no  %d  ",i);
      scanf("%ld",&integers[i]);
      printf("\n");
    }

 /*  Printing the input numbers in
     reverse order                 */

 printf("\n The numbers in the reverse order\n");
 for( i = 9; i >= 0; i--)
    {
      printf("\nInteger no  %d = %ld ",i, integers[i]);
      printf("\n");
    }
 printf("\nPress any key to exit ");
 getch();
 }


/* Q.23 What is a pointer ? Write a C program to swap the values of two variables using pointers */
/* A pointer variable is a variable which stores the address of another variable of same data type. */                                                             (AKTU. 2008 - 09)
Related Questions -
Q. What do mean by pointers ? How pointer variables are initialized ? Write a program in C to swap the values of any two integer variables using pointers.     (AKTU. 2010 - 11)
Q. What do you mean by parameter passing mechanism ? Explain. Write a function to swap the values of two variables.                                                       (AKTU. 2012 - 13)
Ans.
#include<stdio.h>
#include<conio.h>
void main()
{
  int *a, *b, *temp;
  clrscr();
  printf("\nEnter the 1-st value to be swapped\n");
  scanf("%d",a);
  printf("\nEnter the 2-nd value to be swapped\n");
  scanf("%d",b);

  /* swapping  variables*/
  *temp = *a;
  *a = *b;
  *b = *temp;

  /* printing swapped values */
  printf("\n After swapping ");
  printf("\n 1-st value  = %d", *a);
  printf("\n 2-nd value = %d ", *b);
  printf("\n Press any key to exit");
  getch();
 }