WELCOME TO GTU MATERIAL

GTU MATERIAL PROVIDE YOU ALL TYPE OF EDUCATION MATERIAL | DOWNLOAD FREE MATERIAL | ALL TYPE OF EDUCATION SOFTWARES | EXAM ALERTS | EBOOKS | EXAM PAPERS | TIME TABLE | ALL TYPE OF SYLLABUS | MBA | MCA | ENGINEERING | BE | FREE MATERIAL PROVEDE

SHARE YOUR MATERIAL ALSO.. PLEASE SEND ME YOUR MATERIAL WHO SHARE WITH PEOPLE WE PUBLISH IN GTU MATERIAL WITH YOU NAME.. PLEASE SEND US YOUR NAME, COLLEGE NAME, AND STREAM SO THAT WE CAN PUBLISH WITH YOUR NAME..

THANKS YOU SO MUCH.....

Showing posts with label GTU MCA 1ST SEMESTER. Show all posts
Showing posts with label GTU MCA 1ST SEMESTER. Show all posts

Wednesday, 17 August 2011

GTU MCA MATERIAL | C LANGUAGE | Preprocessor


Preprocessor:
vIt is a program that processes source program before it is passed to the complier.
vPreprocessor commands often known as directives.
vPreprocessor directives begin with a # symbol.
vThe directives can be placed anywhere in a program but generally it is beginning of a
     Program before main () or particular function.
vThese directives can be divided into 3 categories.
    1) Mecro substitution directive
    2) File inclusion directive
    3) Complier control directive
1) Macro substitution directive
   vMacro substitution is a process where an identifier in a program is replaced by a    
         predefined string composed of one or more token.
  vExample:
         #define a 25
Main ()
           {
                        Int i;
                        For (i=1;i<=a;i++)
                        {
                                    Printf(“%d”,i);
                        }
                        getch();
            }
   vThis # define a 25 statement is called “macro definition” or just a
       “macro”.
   va is often called “macro templates” and 5 is their “macro 
       expansion”.                             
  vWhen we compile the program it is check by the preprocessor for
       any macro definition before the source code passes to the    
        complier.
   vWe can use capital letter fot macro template this makes it easy for programmer to pick
       out all the macro template when reading through the program.
   vMacro template and its macro expansion are sepatated by blanks or tabs.
   vRemember that a macro definition is never to be terminated by a semicolon.
   vIt is not necessary that you can declare macro before the main function you can declare  
        anywhere in the program.
For Example:
main()
{
            #define pf printf
            pf(“Jay Swaminarayan”);
            getch();             
}

v #define directive is many a times used to define operators.
    #define AND &&
    #define    OR    ||

  2) File inclusion directive

v An external file containing functions or macro definitions can be included as a part of a program so that we need not rewrite those functions or macro definitions. This is achieved by the preprocessor directive.
For example:  #include “filename”

Where filename is the name of the file containing the required definitions or functions. At this point, the preprocessor inserts the entire contents of filename into the source code of the program. When the filename is included within the double quotation marks, the search for the file is made first in the current directory and then in the standard directories.
For example:-
                                                #include<filename>
Without double quotation marks. In this case, the file is searched only in the standard directories.
        
            Nesting of included files is allowed. That is, an include file can included file can include other files. However, a file cannot include itself.
             If an included file is not found, an error is reported and compilation is terminated.
             We can make use of a definition of function contained in any of these files by including them in the program as shown below:
                                                #include<stdio.h>
                                                #include<conio.h>

3) COMPILER CONTORL DIRECTIVES: -


1)      You have included a file containing some macro definitions. It is not known whether a particular macro (say, test) has been defined in that header file. However, you want to be certain that test is define (or not defined).
2)      Suppose a customer has two different type of computer and you are required to write a program that will run on both the system.
                                    One solution to these problems is to develop different programs to suit the needs of different situations. Another method is develop a single. Comprehensive program that includes all optional codes and then directs the compiler to skip over certain parts of source code when they are not required. Fortunately, the c preprocessor offers a feature known as conditional compilation. Which can be used to ‘switch’ on or off a particular line or group of lines in a program.

Situation 1

                     This situation refers to the conditional definition of a macro. We want ensure that the macro TEST is always defined. irrespective of whether it has been defined in the header file or not. This can be achieved as follows:
                                    #include           “DEFINE.H”
                                    #ifndef                       TEST
                                    #define                        TEST   1
                                    #endif
                                    ….
                                    ….
                     DEFINE.H is the header file that is supposed to contain the definition of TEST macro. The directive.
                                    #ifndef            TEST
                     Searches for the definition of TEST in the header file and if not defined, then all the lines between the #ifndef and the corresponding #endif directive are left ‘active’ in the program.
That is, the preprocessor directive
                                    #define     TEST
is processed.

GTU MCA MATERIAL | FOP IMPORTANT QUESTIONS | FOP ASSIGNMENT.


1.What is the purpose of a header file? Is the use of a header file absolutely necessary?
2. Why and when do we use #include directive?
3. Why and when do we use #define directive?
4. Why do we need to use comment in program?
5. Describe the basic data types in C.
6. What is ASCII? How common is its use?
7. Describe the different types of operators.
8. What is the difference between prefix and postfix of – and ++ operators?
9. Describe the use of the conditional operator to form a conditional expression.
10. What are formatted input and output statements in C? Give suitable example.  
11. Find the errors, if any
/* A simple program
int main()
{
/* Does nothing*/
}
12. Find the errors, if any
#include(stdio.h)
void main(void)
{
printf(“Hello C”);
}
13.Find the errors, if any
Include <math.h>
main{}
(
FLOAT  X;
X = 2.5 ;
Y = exp(x) ;
Print(x,y);
)
14. Find the output of the program :
#include<stdio.h>
void main()
{
int x=3,y=5,z=7,w;
w=x%y + y%x - z%x - x %z;
printf(“%d\n”,w);
w=x/z + y/z + (x+y)/z;
printf(“%d”,w);
}
15.Find the output of the program :
#include<stdio.h>
void main()
{
int x=3,y=5,z=7,w=9;
w += x + y -( z -= w );
printf(“w=% d, z=%d\n”,w,z);
w += x -= y %= z;
printf(“w=%d, y=%d, z=%d”,w,y,z);
}
16. Find the output of the program :
#include<stdio.h>
void main()
{
int x=3,y=5;
x = y++ + x++;
y = ++y + ++x;
printf(“x=% d, y=%d”,x,y);
}

Tuesday, 9 August 2011

SYLLABUS | GTU MCA - 1 - 2 SEMESTER SYLLABUS | DOWNLOAD GTU MCA REVISED SYLLABUS SEM - I - II

GTU new MCA Program effective from academic year 2011-12

Sem -I,II (Revised -  29/07/2011)

Friday, 18 February 2011

GTU C PROGRAMS | HEAP SORT PROGRAM

C:
-------------------------------------------------------------------------
/* HEAP SORT */
/* HEAP.C */
# include<stdio.h>
void  heap_sort(int *, int );
void create_heap(int *, int);
void display(int *, int);
/*  Definition of the function */
void create_heap(int list[], int n )
{
 int k, j, i, temp;
 for(k = 2 ; k <= n;  ++k)
 {
  i = k ;
  temp = list[k];
  j = i / 2 ;
  while((i > 1) && (temp > list[j]))
  {
   list[i] = list[j];
   i = j ;
   j = i / 2 ;
   if ( j < 1 )
    j = 1 ;
  }
  list[i] = temp ;
 }
}
/* End of heap creation function */
/* Definition of the function */
void heap_sort(int list[], int n)
{
 int k, temp, value, j, i, p;
 int step = 1;
 for(k = n ; k >= 2; --k)
 {
  temp = list[1] ;
  list[1] = list[k];
  list[k] = temp ;
  i = 1 ;
  value = list[1];
  j = 2 ;
  if((j+1) < k)
   if(list[j+1] > list[j])
    j ++;
  while((j <= ( k-1)) && (list[j] > value))
  {
   list[i] = list[j];
   i = j ;
   j = 2*i ;
   if((j+1) < k)
    if(list[j+1] > list[j])
     j++;
    else
     if( j > n)
      j = n ;
   list[i] = value;
  } /* end of while statement */
  printf("\n Step = %d ", step);
  step++;
  for(p = 1; p <= n; p++)
   printf(" %d", list[p]);
 } /* end for loop */
}
/* Display function */
void display(int list[], int n)
{
 int i;
 for(i = 1 ; i <= n; ++ i)
 {
  printf("  %d", list[i]);
 }
}
/* Function main */
void main()
{
 int list[]={ 0,10,23,64,21,74,95,2,59,44,87,55};
 int i, size = 11 ;
 clrscr();
/* printf("\n Size of the list: %d", size);
 for(i = 1 ; i <= size ; ++i)
 {
  list[i] = rand() % 100;
 }*/
 printf("\n Entered list is as follows:\n");
 display(list, size);
 create_heap(list, size);
 printf("\n Heap\n");
 display(list, size);
 printf("\n\n");
 heap_sort(list,size);
 printf("\n\n Sorted list is as follows :\n\n");
 display(list,size);
 getch();
}

--------------------------------------------------------------------------
C++ :
--------------------------------------------------------------------------
  // HEAP SORT
  // HEAP.CPP
  # include<iostream.h>
  class heap_s
    {
 private:
 public:
    void  heap_sort(int *, int );
    void create_heap(int *, int);
    void display(int *, int);
    };

 //  definition of the function
  void heap_s :: create_heap(int list[], int n )
  {
    for( int k = 2 ; k <= n;  ++k)
       {
  int i = k ;
  int temp = list[k];
  int j = i / 2 ;
  while((i > 1) && (temp > list[j]))
     {
      list[i] = list[j];
      i = j ;
      j = i / 2 ;
      if ( j < 1 )
        j = 1 ;
     }
     list[i] = temp ;
   }
       }
// end of heap creation function
// definition of the function
 void  heap_s :: heap_sort(int list[], int n)
 {
    for( int k = n ; k >= 2; --k)
      {
  int temp = list[1] ;
  list[1] = list[k];
  list[k] = temp ;
  int i = 1 ;
  int value = list[1];
  int j = 2 ;
  if((j+1) < k)
     if(list[j+1] > list[j])
        j ++;
         while((j <= ( k-1)) && (list[j] > value))
   {
    list[i] = list[j];
    i = j ;
    j = 2*i ;
     if((j+1) < k)
       if(list[j+1] > list[j])
         j++;
         else
         if( j > n)
         j = n ;
         list[i] = value;
         } // end of while statement
       cout<<"\n";
       for(int p=1; p<=n; p++)
       cout<<"  "<<list[p];
    } //end for loop
        }
  void heap_s :: display(int list[], int n)
      {
 for( int i = 1 ; i <= n; ++ i)
     {
       cout<<"  "<<list[i];
     }
       }
    void main()
  {
    heap_s sort;
    int list[100];
    int size ;
    cout<<"\n Input the size of the list :";
    cin>>size;

    for(int i = 1 ; i <= size ; ++i)
     {
       cout<<"\n Input values for :" <<i<< " : ";
       cin>>list[i];
     }
     cout<<"\n Entered list is as follows:\n";
     sort.display(list, size);
     sort.create_heap(list, size);
     cout<<"\n Heap\n";
     sort.display(list, size);
     sort.heap_sort(list,size);
     cout<<"\n Sorted list is as follows :\n";
     sort.display(list,size);
  }



GTU C PROGRAMS | SHELL SORT PROGRAM

C :
-------------------------------------------------------------------------
/* shell.c */
/* shell sort */
#include <stdio.h>
#include <stdlib.h>
void shell_sort(int array[], int size)
{
 int temp, gap, i, exchange_occurred;
 gap = size / 2;
 do {
  do {
   exchange_occurred = 0;
   for (i = 0; i < size - gap; i++)
    if (array[i] > array[i + gap])
    {
     temp = array[i];
     array[i] = array[i + gap];
     array[i + gap] = temp;
     exchange_occurred = 1;
    }
  } while (exchange_occurred);
 } while (gap == gap / 2);
}
void main(void)
{
 int values[50], i;
 printf("\n Unsorted list is as follows \n");
 for (i = 0; i < 50; i++)
 {
  values[i] = rand() % 100;
  printf(" %d", rand() %100);
 }
 shell_sort(values, 50);
 printf("\n Sorted list is as follows \n");
 for (i = 0; i < 50; i++)
  printf("%d ", values[i]);
}
-------------------------------------------------------------------------
C++
-------------------------------------------------------------------------
// SHELL SORTING
// SHELL.CPP
# include<iostream.h>
#include <stdio.h>
#include <stdlib.h>
   class shell
       {
 private:
  int temp, gap, i, swap;
 public:
  void shell_sort(int *, int );
  void display(int *, int);
       };
void shell :: shell_sort(int array[], int size)
   {
     gap = size / 2;
     int k =0;
   do {
    do {
      swap = 0;
      k++;
      for (i = 0; i < size - gap; i++)
       if (array[i] > array[i + gap])
        { 
          temp = array[i];
          array[i] = array[i + gap];
          array[i + gap] = temp;
   swap = 1;
 }
 for(int t=0;t<size; t++)
  cout<<" "<<array[t];
 cout<<"  Swap="<<swap;
 cout<<"\n";
    } while (swap);
   } while (gap = gap / 2);
  }
  void shell :: display(int list[], int n)
     {
       cout<<"\n Sorted list is as follows:\n";
       for( int i = 0; i < n; i++)
 cout<<"  " << list[i];
     }
   void main(void)
    {
    shell sort;
    int list[50];
    int number;
   cout<<"\n Input the number of elements in the list:";
   cin>>number;
   for (int i = 0; i < number; i++)
   {
      cout<<"\n Input the value for the "<< i+1<<" : ";
      cin>>list[i];
   }
   sort.shell_sort(list, number);
   sort.display(list,number);
 }

GTU C PROGRAMS | RADIX SORT PROGRAM

C :
--------------------------------------------------------------------------

/* RADIX SORT */
/* RADIX.C*/
# include<stdio.h>
# include<malloc.h>
# include<stdlib.h>
struct node
{
 int data ;
 struct node *next;
};
typedef struct node node1;
node1 *first;
node1 *pocket[100], *pocket1[100];
void create_node(node1 *, int);
void display(node1 *);
node1 *radix_sort(node1 *);
int large(node1 * );
int numdig(int );
int digit(int , int);
void update(int, node1 *);
node1 *Make_link(int, node1 *);
/* This function create nodes and take input data */
void  create_node(node1 *rec, int n)
{
 int i, j, k;
 for(i = 0 ; i< n; i++)
 {
  rec->next = (node1 *) malloc(sizeof(node1));
  printf("\n First node value: %d: ", i);
  scanf("%d", &rec->data);
  rec = rec->next;
 }
 rec->data = NULL;
 rec->next = NULL;
}
/* Output Function */
void  display(node1 *rec)
{
 while(rec != NULL)
 {
  printf(" %d", rec->data);
  rec= rec->next;
 }
}
/* This radix sort function */
node1 *radix_sort(node1 *rec)
{
 node1 *r, *nex;
 int poc = 0 ;
 int i, j, k;
 int larg = large(rec);
 int m = numdig(larg);
 /* These statements create pockets */
 for(k = 0 ; k < 10; k++)
 {
  pocket[k] = (node1 *)malloc(sizeof(node1));
  pocket1[k] = (node1 *)malloc(9*sizeof(node1));
 }
 /* These statements initialize pockets */
 for(j = 1; j <= m ; j++)
 {
  for(i = 0 ; i < 10 ; i++)
  {
   pocket[i] = NULL;
   pocket1[i] = NULL ;
  }
  r = rec ;
  while(r != NULL)
  {
   int dig = digit(r->data, j);
   nex = r->next ;
   update(dig,r);
   r = nex;
  }
  if(r!= NULL)
  {
   int dig = digit(r->data,j);
   update(dig,r);
  }
  while(pocket1[poc] == NULL)
   poc ++;
  rec = Make_link(poc, rec);
 }
 return(rec);
}
/* This function finds largest number in the list */
int large(node1 *rec)
{
 node1 *save ;
 int p = 0;
 save = rec ;
 while(save != NULL)
 {
  if(save ->data > p)
  {
   p = save->data;
  }
  save = save->next ;
 }
 printf("\n Largest element: %d", p);
 return(p);
}
/* This Function finds number digits in a number */
int numdig(int large)
{
 int temp = large ;
 int num = 0 ;
 while(temp != 0)
 {
  ++num ;
  temp = temp/10 ;
 }
 printf("\n  Number of digits of the number %d is %d\n", large, num);
 return(num);
}
/* This function scarve a number into digits */
int digit(int num, int j)
{
 int dig, i, k;
 int temp = num ;
 for(i = 0 ; i < j ; i++)
 {
  dig = temp % 10 ;
  temp = temp / 10 ;
 }
 printf("\n  %d digit of number  %d is %d", j, num, dig);
 return(dig);
}
/* This function updates the pockets value */
void  update(int dig, node1 *r)
{
 if(pocket[dig] == NULL)
 {
  pocket[dig] = r ;
  pocket1[dig] = r ;
 }
 else
 {
  pocket[dig]->next = r ;
  pocket[dig] = r ;
 }
 r->next = NULL;
}
/* This function create links between the nodes */
node1* Make_link(int poc , node1 *rec)
{
 int i, j, k;
 node1 *pointer;
 rec = pocket1[poc];
 for(i = poc +1 ; i< 10 ; i++)
 {
  pointer = pocket[i-1];
  if(pocket[i] != NULL)
   pointer->next= pocket1[i];
  else
   pocket[i] = pointer ;
 }
 return(rec);
}
/* Main function */
void  main()
{
 node1 *start, *pointer;
 int number;
 printf("\n Input the number of elements in the list:");
 scanf("%d", &number);
 start = (node1 *)malloc(sizeof(node1));
 create_node(start, number);
 printf("\n Given list is as follows \n");
 display(start);
 start = radix_sort(start);
 printf("\n Sorted list is as follows:\n");
 display (start);
}
-------------------------------------------------------------------------
C++

-------------------------------------------------------------------------
 // RADIX SORT
 // RADIX.CPP
#include<iostream.h>
#include<conio.h>
#include<malloc.h>
#include<stdlib.h>
struct node
{
 int data;
 struct node *next;
};
typedef struct node node1;
class radix
{
 public:
  node1 *first;
  node1 *pocket[100], *pocket1[100];
 public:
  void create_node(node1 *, int);
  void display(node1 *);
  node1 *radix_sort(node1 *);
  int large(node1 * );
  int numdig(int );
  int digit(int , int);
  void update(int, node1 *);
  node1 *Make_link(int, node1 *);
};
// This function create nodes and take input data
void radix :: create_node(node1 *rec, int n)
{
 for( int i = 1 ; i<= n; i++)
 {
  rec->next = (node1 *) malloc(sizeof(node1));
  cout<<"\n First node value:"<<i<<":";
  cin>>rec->data;
  rec = rec->next;
 }
 rec->next = NULL;
}
// Output Function
void radix ::  display(node1 * rec)
{
 while(rec)
 {
  cout<<"  "<<rec->data;
  rec= rec->next;
 }
 getch();
}
// This radix sort function
node1 * radix ::  radix_sort(node1 *rec)
{
 int larg = large(rec);
 int m = numdig(larg);
// These statements create pockets
 for(int k = 0 ; k < 10; k++)
 {
  pocket[k] = (node1 *)malloc(sizeof(node1));
  pocket1[k] = (node1 *)malloc(9*sizeof(node1));
 }
// These statements initialize pockets
 for(int j = 1; j <= m ; j++)
 {
  for(int i = 0 ; i < 10 ; i++)
  {
   pocket[i] = NULL;
   pocket1[i] = NULL ;
  }
  node1 *r = rec ;
  while(r != NULL)
  {
   int dig = digit(r->data, j);
   node1 *nex = r->next ;
   update(dig,r);
   r = nex;
  }
  if(r!= NULL)
  {
   int dig = digit(r->data,j);
   update(dig,r);
  }
  int poc = 0 ;
  while(pocket1[poc] == NULL)
   poc ++;
  rec = Make_link(poc, rec);
  cout<<"\n Newly ordered list:\n";
  display(rec);
 }
 return(rec);
}
// This function finds largest number in the list
int radix :: large(node1 *rec)
{
 node1 *save ;
 int p = 0;
 save = rec ;
 while(save != NULL)
 {
  if(save ->data > p)
   p = save->data;
  save = save->next ;
 }
 cout <<"\n Largest element:"<<p;
 return(p);
}
// This Function finds number digits in a number
int radix :: numdig(int large)
{
 int temp = large ;
 int num = 0 ;
 while(temp != 0)
 {
  ++num ;
  temp = temp/10 ;
 }
 cout <<"\n Number of digits of the number "<<large<<" is "<<num ;
 return(num);
}
// This function scarve a number into digits
int radix :: digit(int num, int j)
{
 int dig ;
 int temp = num ;
 for( int i = 0 ; i < j ; i++)
 {
  dig = temp % 10 ;
  temp = temp / 10 ;
 }
 cout<<"\n";
 cout <<j <<" digit of number "<<num <<" is "<<dig;
 getch();
 return(dig);
}
// This function updates the pockets value
void radix :: update(int dig, node1 *r)
{
 if(pocket[dig] == NULL)
 {
  pocket[dig] = r ;
  pocket1[dig] = r ;
 }
 else
 {
  pocket[dig]->next = r ;
  pocket[dig] = r ;
 }
 r->next = NULL;
}
// This function create links between the nodes
node1* radix :: Make_link(int poc , node1 *rec)
{
 node1 *pointer;
 rec = pocket1[poc];
 for(int i = poc +1 ; i< 10 ; i++)
 {
  pointer = pocket[i-1];
  if(pocket[i] != NULL)
   pointer->next= pocket1[i];
  else
   pocket[i] = pointer ;
 }
 return(rec);
}
// Main function
void  main()
{
 radix rad;
 node1 *start, *pointer;
 int number;
 cout<<"\n Input the elements of the list :\n";
 cout<<"\n Input the number of elements in the list:";
 cin>>number;
 start = (node1 *)malloc(sizeof(node1));
 rad.create_node(start, number);
 cout<<"\n Given list is as follows \n";
 rad.display(start);
 start = rad.radix_sort(start);
 cout<<"\n Sorted list is as follows:\n";
 rad.display (start);
}

GTU C PROGRAMS | QUICK SORT PROGRAM

C :

/* quick.c */
#include <stdio.h>
#include <stdlib.h>
void quick_sort(int array[], int first, int last)
{
 int temp, low, high, list_separator,i;
 low = first;
 high = last;
 list_separator = array[(first + last) / 2];
 do {
  while (array[low] < list_separator)
   low++;
  while (array[high] > list_separator)
   high--;
  if (low <= high)
  {
   temp = array[low];
   array[low++] = array[high];
   array[high--] = temp;
  }
 } while (low <= high);
 for (i = 0; i < 11; i++)
  printf("%d ", array[i]);
 printf("\n");
 getch();
 if (first < high)
  quick_sort(array, first, high);
 if (low < last)
  quick_sort(array, low, last);
}
void main(void)
{
 int values[]={10,23,64,21,74,95,2,59,44,87,55}, i;
 clrscr();
 for (i = 0; i < 11; i++)
  printf("%d ", values[i]);
 printf("\n");
/* printf("\n Unsorted list is as follows \n");
 for (i = 0; i < 20; i++)
 {
  values[i] = rand() % 100;
  printf(" %d", rand() %100);
 }*/
 quick_sort(values, 0, 10);
 printf("\n Sorted list as follows\n");
 for (i = 0; i < 11; i++)
  printf("%d ", values[i]);
 getch();
}

------------------------------------------------------------------

C++

  // QUICK SORT
  # include<iostream.h>
  # include <stdlib.h>
    class quick
       {
 private: int temp, low, high, pivot;
 public:
 void Q_sort(int *, int , int );
 void display(int *, int );
      };
// sorting function
void quick :: Q_sort(int array[], int first, int last)
 {
   low = first;
   high = last;
   pivot = array[(first + last) / 2];
   do {
     while (array[low] < pivot )
       low++;
     while (array[high] > pivot)
       high--;
     if (low <= high)
      {
 temp = array[low];
 array[low++] = array[high];
 array[high--] = temp;
      }
   } while (low <= high);
  if (first < high)
    Q_sort(array, first, high);
  if (low < last)
    Q_sort(array, low, last);
 }
   void quick :: display(int list[], int n)
     {
       cout<<"\n List after sorting the elements:\n";
       for( int i = 1 ; i <= n ; i++)
       {
  cout<<"  "<<list[i];
       }
     }
 void main(void)
  {
   quick sort;
   int list[100];
   int number ;
   cout<< "\n Input the number of elements in the list:";
   cin>> number;
   for ( int i = 1; i <= number; i++)
    {
     cout<<" Input the value for : "<< i <<" : ";
     cin>>list[i];
    }
  sort.Q_sort(list, 1, number);
  sort.display(list, number);
   }

GTU C PROGRAMS MATERIAL | BUBBLE SORT PROGRAM

C :

/* bubble.c */
#include <stdio.h>
#include <stdlib.h>
void bubble_sort(int array[], int size)
{
 int temp, i, j;
 for (i = 0; i < size; i++)
  for (j = 0; j < size; j++)
   if (array[i] < array[j])
   {
    temp = array[i];
    array[i] = array[j];
    array[j] = temp;
   }
}
void main(void)
{
 int values[30], i;
 printf("\n Unsorted list is as follows\n");
 for (i = 0; i < 10; i++)
 {
  values[i] = rand() % 100;
  printf(" %d", rand()%100);
 }
 bubble_sort(values, 10);
 printf("\n Sorted list is as follows\n");
 for (i = 0; i < 10; i++)
  printf("%d ", values[i]);
}

------------------------------------------------------------
C++

 // BUBBLE SORT
 # include<iostream.h>
 # include<conio.h>
     class bubble
      {
 private:
 public:
       void bubble_sort(int , int *); // prototype
       void display(int *, int);
      };
// definition of function
void bubble ::  bubble_sort(int n, int l[])
  {
      int limit = n - 1 ;
      int flag = 1 ;
   for(int j = 0 ; j< n - 1; j++)
   {
     for(int k = 0 ; k<  limit - j ; k++)
      {
        if(l[k] > l[k+1])
   {
    int  temp = l[k];
         l[k] = l[k+1];
         l[k+1] = temp ;
         flag = 0;
    }
        }
    if(flag)
       break ;
       else
        flag = 1;
     }
 }
      void bubble :: display(int list[], int number)
 {
   for( int i = 0 ; i < number ; i++)
   cout<<"  "<< list[i];
 }

 void main()
        {
  bubble sort;
  int number, key, list[200];
  clrscr();
  cout <<"Input the number of elements in the list:";
  cin >> number;
  cout <<"\n Number  of elements in the list is :"<<number;
  for(int i = 0 ; i < number; i++)
  {
  cout<<"\nInput the elements of the list : "<< i+1<<" : ";
  cin >> list[i];
  }
  cout<<"\n Entered list is as follows:\n";
  sort.display(list,number);
  sort.bubble_sort(number, list);
  cout<<"\n After sorting list is as  follows:\n";
  sort.display(list, number);
 }

GTU C PROGRAM | SELECTION SORT PROGRAME

C.........

/* select.c */
/* selection sort */
#include <stdio.h>
#include <stdlib.h>
void selection_sort(int array[], int size)
{
 int temp, current, j;
 for (current = 0; current < size; current++)
  for (j = current + 1; j < size; j++)
   if (array[current] > array[j])
   {
    temp = array[current];
    array[current] = array[j];
    array[j] = temp;
   }
}
void main(void)
{
 int values[30], i;
 clrscr();
 printf("\n Unsorted list is as follows \n");
 for (i = 0; i < 30; i++)
 {
  values[i] = rand() % 100;
  printf(" %d", rand() %100);
 }
 selection_sort(values, 30);
 printf("\n Sorted list is as follows \n");
 for (i = 0; i < 30; i++)
 printf("%d ", values[i]);
 getch();
}

----------------------------------------------------------------------------
C++.........

// SELECTION SORT
# include<iostream.h>
#include <stdio.h>
#include <stdlib.h>
 class selection
      {
       private:
  int temp, current, j;
       public:
  void selection_sort(int *, int);
  void display(int *, int );
 };
   void selection :: selection_sort(int array[], int size)
   {
   for (current = 0; current < size; current++)
    for (j = current + 1; j < size; j++)
      if (array[current] > array[j])
 {
   temp = array[current];
   array[current] = array[j];
   array[j] = temp;
 }
  }
     void selection :: display( int list[], int n)
       {
   cout<<"\n Sorted list is as follows :\n";
   for(int i = 0 ; i < n ; i++)
      {
        cout<<"  "<<list[i];
      }
 }
void main(void)
 {
   selection sort;
   int list[30];
   int number;
   cout<<"\n Input the number of the elements:";
   cin>>number;
   for (int i = 0; i < number; i++)
      {
 cout<<"\n Input the values for | "<<i+1<<" | ";
 cin>>list[i];
      }
       sort.selection_sort(list, number);
       sort.display(list, number);
    }

Friday, 26 November 2010

FOP MATERIAL | 100 - C language programms


‘C’ LANGUAGE PROGRAMMING PART

            PROG – 1   SIMPLE PROG TO DISPLAY YOUR NAME.

            #inlcude<stdio.h>
            #include<conio.h>
            void main()
{                     
            printf(“my name is chetan”);
            getch();
}         
           
            output : my name is chetan
           
            ------------------------------------------------------------------------------------------------------------------------------
            PROG 2 –TO FIND OUT THE REDIUS FOR CIRCLE

            #include <stdio.h>
#include <conio.h>
#define pi 3.14
void main()
{
            float r,a,cir;
            clrscr();
             printf(" Enter the Redius for circle");
            scanf("%f",&r);
             printf("\n\nArea of Circle is : %f",pi*r*r);
            printf("\n\n Circumference of the Circle is : %f",2*pi*r);
            getch();
}


OUTPUT : DEPEND ON THE VALUE YOU ENTER




PROG -3 /* Read an integer to sore hours & convert into days and hrs.*/

#include<stdio.h>
#include<conio.h>
void main()
{
int num,w,yr,d;
clrscr();
printf(" enter number: ");
scanf("%d",&num);
yr=num/365;
w=(num%365)/7;
d=(num%365)%7;
printf("\nYear is :=%d",yr);
printf("\nWeek is :=%d",w);
printf("\nDay is  := %d",d);
getch();
}
           
            OUTPUT : DEPENDS ON THE NUMBER YOU ENTER
            ------------------------------------------------------------------------------------------------------------------------------

PROG-  4 – TO FIND OUT TOTAL MARKS AND PERCENTAGE

#include<stdio.h>
#include<conio.h>
void main()
{
            int n1,n2,n3,n4,n5,tot,per;
            clrscr();
            printf("enter mark1  ");
            scanf("%d", &n1);
            printf("enter mark2  ");
            scanf("%d", &n2);
            printf("enter mark3  ");
            scanf("%d", &n3);
            printf("enter mark4  ");
            scanf("%d", &n4);
            printf("enter mark5  ");
            scanf("%d", &n5);
            tot=n1+n2+n3+n4+n5;
            per=tot/5;
            printf("the total marks from 500 is= %d", tot);
            printf("\n");
            printf("percent is= %d", per);
            getch();
}


output:
enter mark1  45
enter mark2  46
enter mark3  38
enter mark4  98
enter mark5  74
the total marks from 500 is= 301
percent is= 60
            ------------------------------------------------------------------------------------------------------------------------------

PROG-5 Prog for factorial recursion

#include<stdio.h>
#include<conio.h>
void main()

             {
            int res;
            res=rec(5);
            clrscr();
            printf("\n The fact recursion is  %d",res);
            getch();
            }
            int rec (int n)
            {
            int f=1;
            if (n==1)
            return(1);
            else
            f=n*rec(n-1);
            return (f);
             }

output:   The fact recursion is  120

------------------------------------------------------------------------------------------------------------------------------


Prog 6 prog for count salary

# include <stdio.h>
# include <conio.h>
void main()
{
            int bs,da,hra;
            clrscr();
            printf("Enter Basic Salary :");
            scanf("%d",&bs);
            if(bs<=1500)
            {
            da=bs*0.9;
            hra=bs*0.1;
            bs=bs+da+hra;
            }
            else if(bs>1500)
            {
            hra=500;
            da=bs*0.98;
            bs=bs+da+hra;
            }
            printf("TOTAL GROSS SALARY IS : %d",bs);
            getch();
}

output:
Enter Basic Salary :2000
TOTAL GROSS SALARY IS : 4459







Prog 7: prog for count persentage

#include<stdio.h>
#include<conio.h>
void main()
 {
            float n1,n2,n3;
            clrscr();

            printf("enter n1  ");
            scanf("%f", &n1);
            printf("enter n2  ");
            scanf("%f", &n2);
            printf("enter n3  ");
            scanf("%f", &n3);
            if (n1+n2>n3)
{
            printf("valid tringle");
}
            else if (n2+n3>n1)
            printf("valid tringle");
            else if(n3+n1>n2)
            printf("valid tringle");
            getch();
}


output
enter n1  3
enter n2  4
enter n3  5
valid tringle
------------------------------------------------------------------------------------------------------------------------------








Prog 8 :prog for leap year

 #include<stdio.h>
 #include<conio.h>
 void main()
 {

            int y,lp;
            clrscr();
            printf ("enter year   ");
 scanf("%d",&y);
            if (y%4==0)
{
            printf("leap year");
}         
            else
            printf("not leap year");
            getch();
}

output:
enter year   2004
leap year
------------------------------------------------------------------------------------------------------------------------------
                       
Prog 9 :TO FIND OUT MAXIMUM NUMBER

#include <stdio.h>
#include <conio.h>
            void main()
{
            int n1,n2,max;
            clrscr();
            printf("enter n1   ");
            scanf("%d", &n1);
            printf("enter n2   ");
            scanf("%d", &n2);
            if (n1 >= n2)
{
            max=n1;
            printf("the  max no is number %d",max);
}
            else
{
max=n2;
            printf("the max no is number %d", max);
}
            getch();
}


output:
enter n1   34
enter n2   32
the  max no is number 34
------------------------------------------------------------------------------------------------------------------------------

prog 10: prog for whether the number is odd or even.
           
# include <stdio.h>
# include <conio.h>
void main()
{
            int a;
            clrscr();
            printf("Enter no. :");
            scanf("%d",&a);
            if(a%2==0)
            {
            printf("no is even");
            }
            else
            {
            printf("no is odd");
            }
            getch();
}


OUTPUT : DEPEND ON THE NUMBER YOU ENTER


Prog11 : Prog to find total cost

#include<stdio.h>
#include<conio.h>
void main()
 {
            int qty;
            float price,cost,dis;
            clrscr();
            printf("enter qty   ");
            scanf("%d", &qty);
            printf("enter price   ");
            scanf("%f",&price);
            cost=price * qty;
            if (cost >= 1000)
{
dis= price * qty * 0.1;
            cost= (price*qty) - dis;
            printf("the total cost is  : %f", cost);
            }
            else
            {
            cost=price*qty;
            printf("%f", cost);
            }
            getch();
 }

OUTPUT : DEPEND ON THE QTY YOU ENTER
------------------------------------------------------------------------------------------------------------------------------

Prog 12 : This programme is to find middle value from given three values using  logical operators.

# include <stdio.h>
# include <conio.h>
main()
{
             int a,b,c;
             clrscr();
             printf("\n Enter the value of A : ");
             scanf("%d",&a);
             printf("\n Enter the value of B : ");
             scanf("%d",&b);
             printf("\n Enter the value of C : ");
             scanf("%d",&c);
             if (((a>b) && (a<c)) || ((a<b) && (a>c)))
            printf("\n Middle value is %d",a);
             if (((b>a) && (b<c)) || ((b<a) && (b>c)))
            printf("\n Middle value is %d",b);
             if (((c>a) && (c<b)) || ((c<a) && (c>b)))
            printf("\n Middle value is %d",c);
             getch();
             return 0;
}

OUTPUT : DIPLAY THE MIDDLE VALUE
------------------------------------------------------------------------------------------------------------------------------
PROG 13: TO FIND OUT SALARY + HRA +DA
#include<stdio.h>
#include<conio.h>
void main()
{
            int sal,da,hra;
            clrscr();
            printf("enter salary  ");
            scanf("%d",&sal);
            if (sal<=1500)
            {
            hra=sal*0.1;
            da= sal*0.9;
            }
            else
            {
            hra=500;
            da=sal*0.9;
            }
            printf("basic salary is = %d", sal,da,hra);
            printf("\n the total salary is = %d", sal+da+hra);
            getch();
}

OUTPUT : DISPLAY THE BASIC SALARY
Prog14 : prog  to count length of string

#include<stdio.h>
#include<conio.h>
void main()
            {         
     char arr[50];
            Int len1;
clrscr();
printf("enter the string  ",arr);
scanf("%s",arr);
gets(arr);
len1 = strlen (arr);
printf ("\n string = %s length = %d", arr,len1);
           getch();
           }

output:
enter the string  mayur
             string = mayur length = 5
            ------------------------------------------------------------------------------------------------------------------------------

prog 15 :prog for define capital,small or digit

#include<stdio.h>
#include<conio.h>
void main()
{
            char a;
            clrscr();
            printf ("enter any key   ");
            scanf ("%c", &a);
            if (a>=65 && a<=90)
{
            Printf("the result is capital alphbet %c", a);
}
            else if (a>=97 && a<=122)
            printf ("small alpha %c",a);
            else if (a>=48 && a<=57)
            printf ("digit %c",a);

            getch();
}

           
output
enter any key   G
the result is capital alphbet G
------------------------------------------------------------------------------------------------------------------------------

Prog 16 : prog for a counting string

#include<stdio.h>
#include<conio.h>
void main()
{
   char str[8];
   int j=0;
 strlen j();
              clrscr();
   printf("\n Enter the string   ");
   scanf("\n %s",str);
      j=strlen(str);
   printf("The length is %d",j);
               getch();
 }
           
 output
 Enter the string   abc
 The length is 3

------------------------------------------------------------------------------------------------------------------------------

Prog 17 : prog for whether the insurance is given or not
           
# include <stdio.h>
# include <conio.h>
# include <string.h>
void main()
{
            char st[6];
            char s[5];
            int a;
            clrscr();
            printf("Enter status: ");
            scanf("%s",&st);
            printf("Enter sex: ");
            scanf("%s",&s);
            printf("Enter age: ");
            scanf("%d",&a);
            if(strcmp(st,"u")==0 && strcmp(s,"m")==0 && a>=30 || strcmp(s,"f")==0 && a>=25)
            {
            printf("INSURANCE IS GIVEN");
            }
            else
            {
            printf("INSURANCE IS NOT GIVEN");
            }
            getch();
}

OUTPUT : DEPEND ON THE NUMBER YOU ENTER

------------------------------------------------------------------------------------------------------------------------------

Prog 18  :// This programme is to print the prime numbers.

# include <stdio.h>
# include <conio.h>
void main()
{
             int i,j,f=0;
             clrscr();
             for(i=2; i<=100; i++)
             {
            f=0;
            for(j=2; j<=i/2; j++)
            if (i%j==0)
            {
            f=1;
            break;
            }
             if(f==0)
             printf(" %d ",i);
             }
             getch();
             return 0;        
            ------------------------------------------------------------------------------------------------------------------------------

prog 18 :// This programme is to print the series 1,4,9,16,25..... upto 100

# include <stdio.h>
# include <conio.h>
main()
           
             int i;
             clrscr();
             for(i=1; i<=10; i++)
             printf("\t %d",i*i);
             getch();
             return 0;
            }
            ------------------------------------------------------------------------------------------------------------------------------

Prog 20 : // This programme is to print the series 0,3,8,15,24.... upto 99

# include <stdio.h>
# include <conio.h>
void main()
{
             int i;
             clrscr();
             for(i=1; i<=10; i++)
             printf("\t %d",i*i-1);
             getch();
             return 0;
}
------------------------------------------------------------------------------------------------------------------------------






Prog21 : // This programme is to print the series 100,98,96,94,92........ upto 2.

# include <stdio.h>
# include <conio.h>
void main()
{
            int i;
            clrscr();
            for(i=100; i>=2; i=i-2)
            printf("\t %d",i);
            getch();
            return 0;
}
------------------------------------------------------------------------------------------------------------------------------

Prog22 :// This programme is to print the series 2,4,6,8,10...... upto 100

# include <stdio.h>
# include <conio.h>
void main()
{
            int i;
            clrscr();
            for(i=2; i<=100; i=i+2)
            printf("\t %d",i);
            getch();
            return 0;
}



Prog22 :// This programme is to print 1 to 10 in decrement order

# include <stdio.h>
# include <conio.h>
void main()
{
            int i;
            clrscr();
            for (i=10; i>=1; i--)
            printf("\n %d",i);
            getch();
            return 0;
}
------------------------------------------------------------------------------------------------------------------------------
Prog23 : // This programme is to print 1 to 10 in increment order.
# include <stdio.h>
# include <conio.h>
main()
{
            int i;
            clrscr();
            for(i=1; i<=10; i++)
            printf("\n %d",i);
            getch();
            return 0;
}
------------------------------------------------------------------------------------------------------------------------------
Prog24 : // This programme is to print the series of Armstrong numbers

# include <stdio.h>
# include <conio.h>
# include <math.h>
void main()
{
             int i,j,sum=0;
             clrscr();
             for(i=1; i<=1000; i++)
             {
            sum=0;
            for(j=i; j!=0;)
             {
            sum=sum+pow((j%10),3);
            j=j/10;
             }
            if(sum==i)
             printf("\t%d",i);
            }
             getch();
             return 0;


Prog25 : // This programme is a chart of ASCII code

# include <stdio.h>
# include <conio.h>
void main()
{
             int i;
             clrscr();
             for(i=0; i<=255; i++)
             printf("%d-> %c ",i,i);
             getch();
             return 0;
}

            ------------------------------------------------------------------------------------------------------------------------------

Prog26 : find the no which div by 13 & 7

#include<stdio.h>
#include<conio.h>
void main()
{
            int num1,num2,res,i;
            clrscr();
            printf("Enter Value of Starting Range:->");
            scanf("%d",&num1);
            printf("Enter Value of Ending Range:->");
            scanf("%d",&num2);
            printf("\n\nList of Divisable nos. by 13 and 7 both\n\n");
            for(i=num1;i<=num2;i++)
            {
            if(i%91==0) // Because 13 * 7 = 91
            printf(" %d ",i);
            }
            getch();
}





Prog27 :prog for arrange space

#include<stdio.h>
#include<conio.h>
void main()
{
            int i,j,k,sp,s=0;
            clrscr();
            for (i=5; i>=1; i--)
            {
              for(j=1; j<=i; j++)
            printf("%d ",j);
              for(sp=1;sp<s;sp=sp+1)
             { printf ("  ");
             }
              s =s+2 ;
               for (k=i;k>=1;k--)
                 if(k!=5)
       printf("%d ",k);
              printf ("\n");
                   }
                getch();
}


output:

1 2 3 4 5 4 3 2 1
1 2 3 4   4 3 2 1
1 2 3       3 2 1
1 2           2 1
1               1
------------------------------------------------------------------------------------------------------------------------------








Prog28 : prog for numbers
           
#include<stdio.h>
#include<conio.h>
void main()
{
            int n=5;
            int i,j;
            clrscr();
            printf("%d",n);
            for (i=1; i<=n; i++)
            {
            for(j=1; j<=i; j++)
            printf("%d", j);
            printf ("\n");
            }
            getch();
}

output
1
12
123
1234
12345
------------------------------------------------------------------------------------------------------------------------------

Prog29 :Prog for displaying 1…10.
                       
# include <stdio.h>
# include <conio.h>
void main()
{
            int a[10],i,temp,j;
            clrscr();
            for(i=0;i<=9;i++)
            {
            printf("\n enter value one by one :");
            scanf("%d",&a[i]);
            }
            for(i=0;i<=9;i++)
            {
            for(j=0;j<=i;j++)
            {
            if(a[i]<a[j])
            {
            temp=a[i];
            a[i]=a[j];
            a[j]=temp;
            }
            }
            }
            for(i=0;i<=9;i++)
{
            printf("\n %d",a[i]);
            }
            getch();
}
                          OUTPUT
                           1
                           2
                           3
                           4
                           5
                           6
                           7
                           8
                           9
                           10
------------------------------------------------------------------------------------------------------------------------------
Prog30 : prog for numbers

#include<stdio.h>
#include<conio.h>
void main()
            {
            int n=5;
            int i,j;
            clrscr();
            printf("%d",n);
            for (i=1; i<=n; i++)
            {
            for(j=1; j<=i; j++)
            printf("%d", j);
            printf ("\n");
            }
getch();
}

output
1
12
123
1234
12345
------------------------------------------------------------------------------------------------------------------------------
Prog31 : prog for spiral numbers
           
#include<stdio.h>
#include<conio.h>
void main()
{
            int c=2,i,j,n,k;
clrscr();
printf("enter no=  :");
 scanf("%d",&n);
 for (i=1; i<=n;i++)
             for(j=1;j<=n-i;j++)
             printf ("   ");
               for (k=j; k<=n;k++)
               {
            printf("%3d", c);
              }
            printf("\n");
              }
               getch();
            }






output
enter no=  :3

                        2
                 2  2
              2  2  2
------------------------------------------------------------------------------------------------------------------------------
Prog32 :prog for arrange space

#include<stdio.h>
#include<conio.h>
void main()
{
            int i,j,k,sp,s=0;
            clrscr();
            for (i=5; i>=1; i--)
            {
              for(j=1; j<=i; j++)
            printf("%d ",j);
              for(sp=1;sp<s;sp=sp+1)
             { printf ("  ");
             }
              s =s+2 ;
               for (k=i;k>=1;k--)
  if(k!=5)
              printf("%d ",k);
              printf ("\n");
                   }
               getch();

output:
1 2 3 4 5 4 3 2 1
1 2 3 4   4 3 2 1
1 2 3       3 2 1
1 2           2 1
1               1





Prog33 :prog for finding a no whether it is prime or not

#include<stdio.h>
#include<conio.h>
void main()     
            {
            int i=2;
            int num;
            clrscr();
            printf("enter no :-");
            scanf ("%d", &num);
            while (i<=num-1)
            {
            if (num%i==0)
            {
            printf ("not a prime number");
            getch();
            break;
            }
            i++;
             }
            if (i==num)
            {
            printf ("is a prime number");
            getch();
            }
            }

output
enter no :-17
is a prime number
------------------------------------------------------------------------------------------------------------------------------










Prog34 : Prog for  displaying number

#include<stdio.h>
#include<conio.h>
void main()
{
            int no=1;
            int ans;
            clrscr();
            while (no<=100)
{

            if (no%2==0)
            printf ("\t%d", no);
            no++;
}         
            getch();
}
------------------------------------------------------------------------------------------------------------------------------
           
Prog35 : Prog to display the 1…..99
# include <stdio.h>
# include <conio.h>
void main()
{
            int i=1,j=0;
            clrscr();
            while(j<50)
            {
            if(i%2!=0)
            {
            printf("\t %d",i);
            j++;
            }
            i++;
            }
            printf("\n %d",j);
            getch();
}
           
              OUTPUT
               1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49
               51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95
               97 99
------------------------------------------------------------------------------------------------------------------------------
prog36 : // This programme is to print the series 1,3,5,7,9..... upto 99.

# include "stdio.h"
# include "conio.h"
void main()
{
             int i;
             clrscr();
             i=1;
             while(i<=99)
             {
            printf("\t %d",i);
            i=i+2;
             }
             getch();
             return 0;
}
------------------------------------------------------------------------------------------------------------------------------
Prog37 : // This programme is to get the number in reverse manner.
# include <stdio.h>
# include <conio.h>
void main()
{
             int i,j=0;
             clrscr();
             printf("Enter the number : ");
             scanf("%d",&i);
             while(i!=0)
            {
             j=j*10+(i%10);
             i=i/10;
            }
             printf("%d",j);
             getch();
             return 0;
}
            Prog38 : // This programme is to print the series 1,2,4,7,11..... upto 10 steps.

# include <stdio.h>
# include <conio.h>
void main()
{
   int i,v,incr;
   clrscr();
   i=1;
   v=1;
   incr=1;
   while(i<=10)
   {
              printf("\t %d",v);
              i++;
              v=v+incr;
              incr=incr+1;
   }
   getch();
   return 0;
}
------------------------------------------------------------------------------------------------------------------------------
prog39 : // This programme is to print  1 t0 10 in increment order using  Do-while statement.

# include <stdio.h>
# include <conio.h>
void main()
{
   int i;
   clrscr();
   i=1;
   do
   {
             printf("\n %d",i);
             i++;
            }
   while(i<=10);
   getch();
   return 0;
   }

prog 40 :  print the reverse no

#incldue<stdio.h>
#include<conio.h>                 
void main()
{
            int no,tmpno=1;
            unsigned rev=0;
            clrscr();
            printf("\nEnter number to reverse it:->");
            scanf("%d",&no);
            tmpno=no;
            while(no>0)
            {
            rev= rev*10 + no%10;
            no /= 10;
            }
            printf("\n The reverse no is :->%u",rev);
            getch();
}
------------------------------------------------------------------------------------------------------------------------------
prog41 : print the multiplication table

#include<stdio.h>
#include<conio.h>
void main()
{
            int row,column,y,n;
            clrscr();
            row=1;
            printf("\n Enter any no for multiplication no:->");
            scanf("%d",&n);
            printf("Multiplication Table\n");
            printf("--------------------------------\n");
            do
            {
            column =1;
            do
            {
            y=row*column;
            printf("%4d",y);
            column=column+1;
            }
            while(column<=n);
            printf("\n");
            row=row+1;
            }
            while(row<=n);
            getch();
}
------------------------------------------------------------------------------------------------------------------------------

Prog42 : prog for swith….case statement,

#include<stdio.h>
#include<conio.h>
void main()

            {
            int i=2;
            clrscr();
            switch (i)
            {
                        case 1:
                                    printf("this is one \n");
                                    break;
                        case 2:
                                    printf("this is two \n");
                        case 3:
                                    printf("this is three \n");
                                    break;
                        default:
                                    printf("this is default \n");
            }
            getch();
            }
------------------------------------------------------------------------------------------------------------------------------





Prog43 : prog for numbers

#include<stdio.h>
#include<conio.h>
            void main()
{
            int n1,n2;
            int res;
            char op;
            clrscr();
            printf("Enter the two number :\n");
            scanf("%d %d",&n1,&n2);
            printf(" Enter the operatpor : ");
            fflush(stdin);
            scanf("%c",&op);
            printf ("%d",calc (n1,n2,op) );
            getch();
     }
            int calc (int i, int j, char ch)
            {
               switch(ch)
               {
                  case '+'  : return(i+j);
                  case '-'  : return(i-j);
                  case '*'  : return(i*j);
                  case '/'  : return(i/j);
                }
              return (0);
            }
------------------------------------------------------------------------------------------------------------------------------

prog 44 : perform add mul sub div using switch   

#include<stdio.h>
#include<conio.h>
void main()
{
            int a,b,res;
            char ch;
            clrscr();
            printf("Enter value of a :->");
            scanf("%d",&a);
            printf("Enter value of b :->");
            scanf("%d",&b);
            printf("Enter Operation choice ");
            scanf(" %c",&ch);
            switch(ch)
       {
            case '+':
            printf("\nAddition is %d", a+b);
            break;
            case '-':
                        printf("\nSub is %d", a-b);
                        break;
            case '*':
                        printf("\nMul is %d", a*b);
                        break;
            case '/':
                        printf("\nDiv is %d", a/b);
                        break;
            default:
                        printf("\nSorry ... Pls.. Enter proper choice");
      }
            getch();

}
------------------------------------------------------------------------------------------------------------------------------
prog 45 :prog for finding a no whether it is prime or not

#include<stdio.h>
#include<conio.h>
void main()
            {
            int i=2;
            int num;
            clrscr();
            printf("enter no :-");
            scanf ("%d", &num);
            while (i<=num-1)
            {
            if (num%i==0)
            {                      printf ("not a prime number");
                                    getch();
                                    break;
            }
                        i++;
             }
            if (i==num)
            {
                        printf ("is a prime number");
                        getch();
            }
            }

output
enter no :-17
is a prime number
------------------------------------------------------------------------------------------------------------------------------
prog46 : Prog for numbers

#include<stdio.h>
#include<conio.h>
void main()
{
            int no=1;
            int ans;
            clrscr();
            while (no<=100)
{
            if (no%2==0)
            printf ("\t%d", no);
            no++;
}
            getch();
}
------------------------------------------------------------------------------------------------------------------------------








Prog47 : prog to display 1..3..5 up to 99.

# include <stdio.h>
# include <conio.h>
void main()
{
            int i=1,j=0;
            clrscr();
            while(j<50)
            {
            if(i%2!=0)
            {
            printf("\t %d",i);
            j++;
            }
            i++;
            }
            printf("\n %d",j);
            getch();
}
                                   OUTPUT
                           1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49
                           51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95
                           97 99
------------------------------------------------------------------------------------------------------------------------------

`           Prog48 : This programme is to print the series 1,3,5,7,9..... upto 99.

# include "stdio.h"
# include "conio.h"
voidmain()
{
             int i;
             clrscr();
             i=1;
             while(i<=99)
             {
                        printf("\t %d",i);
                        i=i+2;
             }
             getch();
             return 0;
}
------------------------------------------------------------------------------------------------------------------------------

Prog49 : // This programme is to get the number in reverse manner.
# include <stdio.h>
# include <conio.h>
main()
{
             int i,j=0;
             clrscr();
             printf("Enter the number : ");
             scanf("%d",&i);
             while(i!=0)
            {
             j=j*10+(i%10);
             i=i/10;
            }
             printf("%d",j);
             getch();
             return 0;
}
------------------------------------------------------------------------------------------------------------------------------

Prog50 : This programme is to print the series 1,2,4,7,11..... upto 10 steps

# include <stdio.h>
# include <conio.h>
void main()
{
   int i,v,incr;
   clrscr();
   i=1;
   v=1;
   incr=1;
   while(i<=10)
   {
              printf("\t %d",v);
              i++;
              v=v+incr;
             incr=incr+1;
             }
             getch();
             return 0;
             }
------------------------------------------------------------------------------------------------------------------------------
Prog51 :  This programme is to print  1 t0 10 in increment order using  Do-while statement.

# include <stdio.h>
# include <conio.h>
void main()
{
   int i;
   clrscr();
   i=1;
   do
   {
             printf("\n %d",i);
             i++;
   }
   while(i<=10);
   getch();
   return 0;  
}
------------------------------------------------------------------------------------------------------------------------------
prog52 :  print the reverse no

# include <stdio.h>
# include <conio.h>
void main()
{
            int no,tmpno=1;
            unsigned rev=0;
            clrscr();
            printf("\nEnter number to reverse it:->");
            scanf("%d",&no);
            tmpno=no;
            while(no>0)
            {
            rev= rev*10 + no%10;
            no /= 10;
            }
            printf("\n The reverse no is :->%u",rev);
            getch();
}
------------------------------------------------------------------------------------------------------------------------------
Prog53  print the multiplication table

#include<stdio.h>
#include<conio.h>
void main()
{
            int row,column,y,n;
            clrscr();
            row=1;
            printf("\n Enter any no for multiplication no:->");
            scanf("%d",&n);
            printf("Multiplication Table\n");
            printf("--------------------------------\n");
            do
            {
            column =1;
            do
            {
                        y=row*column;
                        printf("%4d",y);
                        column=column+1;
                        }
                        while(column<=n);
                        printf("\n");
                        row=row+1;
            }
            while(row<=n);
            getch();
}







Prog 54 : prog for counting avg of 10 marks

#include<stdio.h>
#include<conio.h>
void main()
{
            int marks[10];
            int i,sum=0;
            float avg;
            clrscr();
 for (i=0;i<10;i++)
            {
            printf ("\nEnter marks %d: ",i+1);
            scanf ("%d", &marks[i]);
            }
  for (i=0;i<10;i++)
             sum=sum+marks[i];
  avg=sum/10.0;

            printf("\n\n\n");
            printf("avg is %f",avg);
            getch();
}

output:
Enter marks 1: 12
Enter marks 2: 13
Enter marks 3: 14
Enter marks 4: 15
Enter marks 5: 16
Enter marks 6: 17
Enter marks 7: 18
Enter marks 8: 19
Enter marks 9: 11
Enter marks 10: 10
avg is 14.500000





prog55 : prog for displaying 10……1 .                  
# include <stdio.h>
# include <conio.h>
void main()
{
            int a[10],i,temp,j;
            clrscr();
            for(i=0;i<=9;i++)
            {
            printf("\n enter value one by one :");
            scanf("%d",&a[i]);
            }
            for(i=0;i<=9;i++)
            {
            for(j=0;j<=i;j++)
            {
            if(a[i]>a[j])
            {
            temp=a[i];
            a[i]=a[j];
            a[j]=temp;
            }
            }
            }
            for(i=0;i<=9;i++)
            {
            printf("\n %d",a[i]);
            }
            getch();
}
                           OUTPUT
                           10
                           9
                           8
                           7
                           6
                           5
                           4
                           3
                           2
                           1
Prog56 : // program for addition of two matrix

#include<stdio.h>
#include<conio.h>
void main()
{
            int a[3][3],b[3][3],c[3][3];
            int i,j,l,m;
            clrscr();
            printf("Enter the elements in the first matrix\n");
            for(i=0;i<3;i++)
            {
                        for(j=0;j<3;j++)
                        {
                                    scanf("%d",&a[i][j]);
                        }
            }
            printf("Enter the elements in the second matrix\n");
            for(l=0;l<3;l++)
            {
                        for(m=0;m<3;m++)
                        {
                                    scanf("%d",&b[l][m]);
                        }
            }

            printf("You have the following numbers into first matrix\n");
            for(i=0;i<3;i++)
            {
                        for(j=0;j<3;j++)
                        {
                                    printf("%d",a[i][j]);
                        }
                        printf("\n");
            }
            printf("\nThe Addition of the two matrix are\n");
            for(i=0;i<3;i++)
            {
               for(j=0;j<3;j++)
               {
                        c[i][j]=a[i][j]+b[i][j];
               }
            }
            for(i=0;i<3;i++)
            {
                        for(j=0;j<3;j++)
                        {
                                    printf("%d   ",c[i][j]);
                        }
                        printf("\n");
            }
getch();
}
------------------------------------------------------------------------------------------------------------------------------

Prog57 : prog for two dimention array
           
#include<stdio.h>
#include<conio.h>
void main()
{
   int arr[3] [4];
   int i,j;
   clrscr();
   for (i=0; i<3; i++)
            {
             for(j=0; j<4; j++)
               {
             printf ("\n Enter a no at[%d] [%d]  :", i,j);
             scanf ("%d", &arr [i][j]);
               }
             }
             for (i=0; i<3; i++)
               {
             printf ("\n The no at[%d][%d] is  :%d", i,j,arr[i][j]);

               }
            }





output

            Enter a no at[0] [0]  :12

            Enter a no at[0] [1]  :12

            Enter a no at[0] [2]  :13

            Enter a no at[0] [3]  :14

             Enter a no at[1] [0]  :14

              Enter a no at[1] [1]  :15

               Enter a no at[1] [2]  :14

            Enter a no at[1] [3]  :13

             Enter a no at[2] [0]  :16

              Enter a no at[2] [1]  :17

               Enter a no at[2] [2]  :18

            Enter a no at[2] [3]
  : 12
------------------------------------------------------------------------------------------------------------------------------

Prog58 : DEFINATION:-TO PRINT ARRAY IN THE ASENDING ORDER

#include<stdio.h>
#include<conio.h>
void main()
{
int arr[5];
int i,j,temp;
clrscr();
for(i=0;i<5;i++)           {
             printf("Enter the element [%d]:",i);
             scanf("%d",&arr[i]);
             }
for(i=0;i<5;i++)
{
            for(j=i+1;j<5;j++)
                        {
                        if(arr[j]<arr[i])
                                    {
                                                temp=arr[i];
                                                arr[i]=arr[j];
                                                arr[j]=temp;
                                     }
                         }
}
for(i=0;i<5;i++)
{
//printf("the ascending element [%d]:",i);
printf("\n\t %d",arr[i]);
}
getch();
}

OUTPUT
Enter the element [0]:5
Enter the element [1]:4
Enter the element [2]:2
Enter the element [3]:0
Enter the element [4]:1

                                    0
                                    1
                                    2
                                    4
                                    5








PROG 59 :TO PRINT THE AVERAGE OF THE ARRAY ELEMENT

#include<stdio.h>
#include<conio.h>
void main()
{
int stu[5];
int i,n,sum=0;
float Avg;
clrscr();
printf("How many marks are entered");
scanf("%d",&n);
            for(i=0;i<5;i++)
            {
            printf("\n Enter the value of student[i]");
            scanf("%d",&stu[i]);
            }
            for(i=0;i<5;i++)
            sum+=stu[i];

            printf("%f",sum/5.0);
            getch();
}

OUTPUT

Enter the value of student[i]5

Enter the value of student[i]6

Enter the value of student[i]7

Enter the value of student[i]8

Enter the value of student[i]9

7.000000




Prog60 : To find the maximum and minimum number using array.

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int num[5];
int i,max,min;
clrscr();
for(i=0;i<5;i++)
            {
            printf("Enter the value at [%d]:",i);
            scanf("%d",&num[i]);
            }
            max=num[0];
for(i=0;i<5;i++)
            {
            if(num[i]>max)
            max=num[i];
            }
            min=num[0];
for(i=0;i<5;i++)
            {
            if(num[i]<min)
            min=num[i];
            }
            printf("\n max value is %d",max);
            printf("\n\n min value is %d",min);
            getch();
}

OUTPUT
Enter the value at [0]:5
Enter the value at [1]:4
Enter the value at [2]:3
Enter the value at [3]:90
Enter the value at [4]:88
            max value is 90
 min value is 3

PROG61 : TO SERACH A CHARECTER IN THE ARRAY.

#include<stdio.h>
#include<conio.h>
#include<stdio.h>
void main()
{
char str[15];
char n;
int i=0,c=0;
clrscr();
              printf("\n\tEnter the string:  ");
              gets(str);
              printf("\n\tEnter search character:  ");
              scanf("%c",&n);
while(str[i])
{
if(str[i]==n)
            c++;
            i++;
}
printf("\n\tIn the string %d times are character are search ",c);
getch();
}

          OUTPUT
            Enter the string:  VIBHAKAR
            Enter search character:  A
            In the string 2 times are character are search
           
------------------------------------------------------------------------------------------------------------------------------

PROG 62 :Prog for binary search

# include <stdio.h>
# include <conio.h>
int SIZE=10;
void main()
{
            int i,j,m,tmp,n,s,a[10],f,l,yn=0;
            clrscr();
            fflush(stdin);
            for (i=0; i<SIZE; i++)
            {                     
printf ("Enter a[%d] element :",i);
            scanf("%d",&a[i]);
            }
            for (i=0; i<SIZE; i++)
            {
            for (j=i+1; j<SIZE; j++)
            {
            if (a[i]>a[j])
            {
            tmp=a[i];
            a[i]=a[j];
            a[j]=tmp;
            }
            }
            }
            printf ("Enter Element to be Found : ");
            scanf ("%d",&s);
            f=0;
            l=SIZE-1;
            while (f<=l)
            {
            m=(f+l)/2;
            if (s>a[m])
            f=m+1;
            else
            {
            if (s<a[m])
            l=m-1;
            else
            if(s==a[m])
            {
            yn=1;
            break;
            }
            }
            }
            if (yn==1)
            printf ("\n %d element is Found ",s);
            else
            printf ("\n %d element is NOT found",s);
            getch();
}

 OUTPUT
            Enter a[0] element :1
            Enter a[1] element :2
            Enter a[2] element :3
            Enter a[3] element :6
            Enter a[4] element :4
            Enter a[5] element :5
            Enter a[6] element :9
            Enter a[7] element :5
            Enter a[8] element :2
            Enter a[9] element :3
            Enter Element to be Found : 3
            3 element is Found
------------------------------------------------------------------------------------------------------------------------------
Prog 63 :prog for two dimention array

#include<stdio.h>
#include<conio.h>
void main()
{
             int i,j,temp,*ptr,*ptr1;
            clrscr();
             ptr = &i;
             ptr1 = &j;
            printf ("\n Enter number-1  :");
              scanf ("%d", &i);
             printf ("\n Enter number-2  :");
             scanf ("%d", &j);
              temp = *ptr;
            *ptr = *ptr1;
             *ptr1= temp;
             printf ("\n Number after swapping ");
             printf ("\n The first no is :%d", *ptr);
            printf ("\n The second no is :%d", *ptr1);      
            getch();
}

output
 Enter number-1  :13
 Enter number-2  :45
 Number after swapping
 The first no is :45
 The second no is :13
------------------------------------------------------------------------------------------------------------------------------

Prog 64 : prog for two dimention array

            #include<stdio.h>
#include<conio.h>
void main()
{
   int i,j,temp,*ptr,*ptr1;
   clrscr();
   ptr = &i;
   ptr1 = &j;
   printf ("\n Enter number-1  :");
   scanf ("%d", &i);
   printf ("\n Enter number-2  :");
   scanf ("%d", &j);
   temp = *ptr;
   *ptr = *ptr1;
   *ptr1= temp;
   printf ("\n Number after swapping ");
            printf ("\n The first no is :%d", *ptr);
            printf ("\n The second no is :%d", *ptr1);
             getch();
}

output
            Enter number-1  :13
            Enter number-2  :45
            Number after swapping
            The first no is :45
            The second no is :13



Prog 65 : prog for swaping using pointer

#include<stdio.h>
#include<conio.h>
#include<string.h>
            void main()
{
   char i,j,temp,*ptr,*ptr1;
   clrscr();
   ptr  =&i;
   ptr1 =&j;
   printf ("\n Enter string1  :");
            scanf ("%c",&i);
   fflush (stdin);
   printf ("\n Enter string2  :");
   scanf ("%c",&j);
   temp =*ptr;
  *ptr =*ptr1;
   *ptr1=temp;
   printf ("\n String after swapping ");
   printf ("\n The first string is :%c", *ptr);
            printf ("\n The second string is :%c",*ptr1);
            getch();
}

output
    Enter string1  :qwe
    Enter string2  :wer
    String after swapping
    The first string is :w
     The second string is :q











Prog 66 :prog for counting spaces,lines blanks,tabs
           
#include<stdio.h>
#include<conio.h>
void main()
{
            FILE *fp;
            char ch;
            int nol=0,not=0,nob=0,noc=0;
            fp=fopen("z:\search.c","r");
            clrscr();
               while(1)
               {
                  ch=fgetc(fp);

                  if (ch==EOF)
                  break;
                  noc++;
                  if (ch==' ')
                  nob++;
                  if (ch=='\n')
                  nol++;
                  if(ch=='\t')
                  not++;
               }
               fclose(fp);
               printf("\n Number of char = %d",noc);
               printf("\n Number of blanks = %d",nob);
               printf("\n Number of tabs = %d",not);
               printf("\n Number of lines = %d", nol);
               getch();
               return (1);
            }

------------------------------------------------------------------------------------------------------------------------------






Prog67 : prog for file handling

#include <stdio.h>
#include <conio.h>
void main()
{
  FILE *fp,*fc;
  char ch;
  clrscr();
  fp=fopen("z:\\abcd.txt","r");
  fc=fopen("z:\\ab.txt","w");
  if (fp==NULL)                     {
            puts ("can not find a file please try again");
            }
            else
            {
            while((ch=fgetc(fp))!=EOF)
            {
            fputc(fp);
            printf("%c",ch);
            }
            fclose(fp);
            fclose(fc);
            }
            getch();
            }
------------------------------------------------------------------------------------------------------------------------------

Prog 68 : Binary Tree Creation and Traversals  
           
#include <stdio.h>
#include <conio.h>
struct bTreeNode
{
 int data;
 struct bTreeNode *lChild;
 struct bTreeNode *rChild;
};


void main()
{
  struct bTreeNode *bt;
  int tot,no,i=1;
  clrscr();
  bt=NULL;
  printf("\n Specify no of items : ");
  scanf("%d",&tot);
             while(i<=tot)
  {
   printf("\n Enter Data:");
   scanf("%d",&no);
   insert(&bt,no);
   i++;
  }
  printf("\n Traversing tree in inOrder Traversal  :\n");
  inOrder(bt);
  printf("\n Traversing tree in preOrder Traversal  :\n");
  preOrder(bt);
  printf("\n Traversing tree in postOrder Traversal  :\n");
  postOrder(bt);
  getch();
}
Insert(struct bTreeNode **bRoot,int n){
 if (*bRoot == NULL)
 {
    *bRoot = malloc(sizeof(struct bTreeNode));
    (*bRoot)->lChild = NULL;
    (*bRoot)->data = n;
    (*bRoot)->rChild = NULL;
    return;
 }
 else
 {
            if (n < (*bRoot)->data)
             insert ( &((*bRoot)->lChild),n);
            else
            insert(&((*bRoot)->rChild),n);
 }
            return;
}
inOrder(struct bTreeNode *bRoot)
{
  if (bRoot!=NULL)
  {
     inOrder(bRoot->lChild);   
     printf("%4d",bRoot->data);
     inOrder(bRoot->rChild);
  }
  else   
    return;
}
preOrder(struct bTreeNode *bRoot)
{
  if (bRoot!=NULL)
  {
     printf("%4d",bRoot->data);
     preOrder(bRoot->lChild);
     preOrder(bRoot->rChild);
  }
  else
    return;
}

postOrder(struct bTreeNode *bRoot)
{
             if (bRoot!=NULL)
  {
             postOrder(bRoot->lChild);
             postOrder(bRoot->rChild);
            printf("%4d",bRoot->data);
             }
            else
             return;
}


------------------------------------------------------------------------------------------------------------------------------




prog 69 structure

#include<stdio.h>
#include<conio.h>
#nclude<stdlib.h>
struct raj
            {
   int code;
   char nm[30];
   struct raj *r;
 };
  typedef struct raj node;
            nt menu();
            oid add();
            oid del();
            oid view();
            ode *fst=NULL,*lst=NULL;

             void main()
           
            nt opt=1;
             clrscr();
            hile(opt!=0)
            {
            pt=menu();
            witch(opt)
           
             case 1: add();
            reak;
            ase 2: del();
            reak;
            ase 3: view();
           
             }
           
             int menu()
            {
            int choice;
            lrscr();
            printf("\n0...exit");
            printf("\n1....add");
            printf("\n2....del");
             printf("\n3....vie");
            rintf("\nwhat is your choice: ");
            scanf("%d",&choice);
             return(choice);
              }
             void add()
             {
            if(fst==NULL)           {
               fst=lst=(node*)malloc(sizeof(node));
               printf("\nenter the node:-  ");
               scanf("%d",&fst-> code);
               printf("enter name:-  ");
               fflush(stdin);
               gets(fst->nm);
               fst->r=NULL;
             }
             else
             {
              lst->r=(node*)malloc(sizeof(node));
              lst=lst->r;
              lst->r=NULL;

              printf("\nenter the code:-  ");
              scanf("%d",&lst->code);
              printf("\nenter the name :-  ");
              fflush(stdin);
              gets(lst->nm);
             }
             }
            void del()
                {
             node *dst;
             dst=fst;
              if(fst==NULL)
               {
                 printf("\nempty queue");
                 getch();
                 return;
               }
               fst=fst->r;
               printf("\ndeleted code is = %d",dst->code);
               free(dst);
               getch();
            }

             void view()
             {
                node *vpt;
                vpt=fst;
                if(vpt==NULL)
                {
                  printf("\n queue is not created ");
                  getch();
                  return;
                }
                 while(vpt!=NULL)
                {
                  printf("\ncode:- %d",vpt->code);
                  printf("\tname:- %s",vpt->nm);
                  vpt=vpt->r;
                }
                getch();
             }




prog 70 :"program of stack operation"

#include <stdio.h>
#include <conio.h>
struct stack
{
            int data;
            struct stack *prev;
};
struct stack *node;
void main()
{
            int ch,n;
            char c;
            clrscr();
            node=NULL;
            printf("\n 1. Push ");
            printf("\n 2. Pop ");
            printf("\n 3. Display");
            printf("\n 4. Exit");
            printf("\n Enter your choice (1-4): ");
            scanf("%d",&ch);
            while(ch>=1&&ch<=4)
            {
                        switch(ch)
                        {
                                    case 1:

                                                push(node);
                                                break;

                                    case 2:
                                                pop(node);
                                                break;

                                    case 3:
                                                disp(node);
                                                break;
                                    case 4:
                                                exit(0);
                        }
                        getch();
                        clrscr();
                        printf("\n 1. Push ");
                        printf("\n 2. Pop ");
                        printf("\n 3. Display");
                        printf("\n 4. Exit");
                        printf("\n Enter your choice (1-4): ");
                        scanf("%d",&ch);
            }
            getch();
}
push(struct stack *rec)
{
            struct stack *new1;
            new1=(struct stack *)malloc(sizeof(struct stack));
            printf("\nEnter element to push: ");
            scanf("%d",&new1->data);
            new1->prev=rec;
            node=new1;
            return (0);
}
pop(struct stack *rec)
{
            node=rec->prev;
            free(rec);
            return (0);
}
disp(struct stack *rec)
{
            while(rec)
            {
                        printf("\n%d",rec->data);
                        rec=rec->prev;
            }
                        return (0);
}




Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Grants For Single Moms