Friday, 21 August 2015

Write a C Program to Find Summation of 2D Array

#include<stdio.h>
#include<conio.h>

void main()

{
    int c[2][2],i,j;
    int a[2][2];
    int b[2][2];
    clrscr();


    for(i=0;i<2;i++)
    {

        printf("\n");
        for(j=0;j<2;j++)
        {
            printf("\na[%d][%d]=",i,j);
            scanf("%d",&a[i][j]);
        }

    }
        for(i=0;i<2;i++)
    {

        printf("\n");
        for(j=0;j<2;j++)
        {
            printf("\nb[%d][%d]=",i,j);
            scanf("%d",&b[i][j]);
        }

    }
        for(i=0;i<2;i++)
    {

        printf("\n");
        for(j=0;j<2;j++)
        {
            c[i][j]=a[i][j]+b[i][j];
            printf("\na[%d][%d]=%d",i,j,c[i][j]);

        }

    }


    getch();
}

Wednesday, 12 August 2015

Write a C Program To Implement Quick Sort

 Write a program to implement Quick sort.
/* program to sort elements of an array using Quick Sort */
#include<stdio.h>

void quicksort(int[ ],int,int);
void main( )
{
int low, high, pivot, t, n, i, j, a[10];
clrscr( );
printf("\nHow many elements you want to sort ? ");
scanf("%d",&n);
printf("\Enter elements for an array:");
for(i=0; i<n; i++)
scanf("%d",&a[i]);
low=0;
high=n-1;
quicksort(a,low,high);
printf("\After Sorting the elements are:");
for(i=0;i<n;i++)
printf("%d ",a[i]);
getch( );
}
void quicksort(int a[ ],int low,int high)
{
int pivot,t,i,j;
if(low<high)
{
pivot=a[low];
i=low+1;
j=high;
while(1)
{

while(pivot>a[i]&&i<=high)
i++;
while(pivot<a[j]&&j>=low)
j--;
if(i<j)
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
else
break;
}
a[low]=a[j];
a[j]=pivot;
quicksort(a,low,j-1);
quicksort(a,j+1,high);
}
}

Write a C program To Implement Selection Sort

 Write a program to explain selection sort. Which type of technique does it belong.
/* program to sort elements of an array using selection sort*/
#include<stdio.h>
void main( )
{
int i,j,t,n,min,a[10];
clrscr( );
printf("\n How many elements you want to sort? ");
scanf("%d",&n);
printf("\Enter elements for an array:");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
{
min=i;
for(j=i+1;j<n;j++)
if(a[j] > a[min])
{
min=j;
}
t=a[i];
a[i]=a[min];
a[min]=t;
} printf("\nAfter sorting the elements are:");
for(i=0;i<n;i++)
printf("%d ",a[i]);
getch( );
}

Write a C Program To implement Insertion Sort

 Write a program to explain insertion sort . Which type of technique does it belong.
(or)
Write a C-program for sorting integers in ascending order using insertion sort.
/*Program to sort elements of an array using insertion sort method*/
#include<stdio.h>
#include<conio.h>
void main( )
{
int a[10],i,j,k,n;
clrscr( );
printf("How many elements you want to sort?\n");
scanf("%d",&n);
printf("\nEnter the Elements into an array:\n");
for (i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=1;i<n;i++)
{
k=a[i];
for(j= i-1; j>=0 && k<a[j]; j--)
a[j+1]=a[j];

a[j+1]=k;
} printf("\n\n Elements after sorting: \n");
for(i=0;i<n;i++)
printf("%d\n", a[i]);
getch( );
}

Write a C Program To Implement Bubble Sort

/* bubble sort implementation */
#include<stdio.h>
#include<conio.h>
void main()
{
    int i,n,temp,j,arr[25];
    clrscr();
    printf("Enter the number of elements in the Array: ");
    scanf("%d",&n);
    printf("\nEnter the elements:\n\n");
    for(i=0 ; i<n ; i++)
    {
        printf(" Array[%d] = ",i);
        scanf("%d",&arr[i]);
    }   
    for(i=0 ; i<n ; i++)
    {
        for(j=0 ; j<n-i-1 ; j++)
        {
            if(arr[j]>arr[j+1]) //Swapping Condition is Checked
            {
                temp=arr[j];
                arr[j]=arr[j+1];
                arr[j+1]=temp;
            }
        }
    }
        printf("\nThe Sorted Array is:\n\n");
        for(i=0 ; i<n ; i++)
{
printf(" %4d",arr[i]);
}
getch();
}

Write a C Program To Implement Stack program using An Array For BCA , MCA . MScIT , Engineering

#include<stdio.h>
#include<conio.h>
int stack[10],top=-1; //global declaration
void push();  //declaring functions
void pop();
void display();
void main()
{
  int ch;
  printf(">>> StackOperations <<<\n\n");
  do
  {
      printf("\n 1.Push");
      printf("\n 2.Pop");
      printf("\n 3.Display");
      printf("\n 4.Exit");
      printf("\n Enter your choice: ");
      scanf("%d",&ch);
      if(ch==1)
        push();
      else if(ch==2)
        pop();
      else if(ch==3)
        display();
      else if(ch==4)
       printf("\n\nEnd Of program");
 
  }while(ch!=4);
}
//to push elements in a stack
void push()
{
  if(top>9)
    printf("\n Stack Overflow");
  else
  {
      top=top+1;
      printf("\n Enter a value: ");
      scanf("%d",&stack[top]);
  }
 
}
 
//to pop/delete stack elements
void pop()
{
  if(top==-1)
   printf("\n Stack Overflow. No Elements to pop");
  else
  {
      printf("%d is deleted..",stack[top]);
      top--;  
  }
}
 
//displaying stack elements
void display()
{
    int i;
    if(top==-1)
      printf("\n Stack underflow. No elements to display..");
    else
    {
        printf("\n The stack elements are: ");
        for(i=0;i<=top;i++)
        {
          printf("\t %d",stack[i]);
        }
 
    }
}

Write a C Program To Implement Queue program using An Array For BCA , MCA . MScIT , Engineering

#include<stdio.h>
#include<conio.h>
#define MAX 10
int queue[MAX],front=-1,rear=-1;
void insert_element();
void delete_element();
void display_queue();
 
 
int main()
{
  int option;
  printf(">>> c program to implement queue operations <<<");
  do
  {
   printf("\n\n 1.Insert an element");
   printf("\n 2.Delete an element");
   printf("\n 3.Display queue");
   printf("\n 4.Exit");
   printf("\n Enter your choice: ");
   scanf("%d",&option);
   switch(option)
   {
     case 1: insert_element();
              break;
     case 2: delete_element();
             break;
     case 3: display_queue();
             break;
     case 4: return 0;
   }
 
  }while(option!=4);
}
void insert_element()
{
  int num;
  printf("\n Enter the number to be inserted: ");
  scanf("%d",&num);
  if(front==0 && rear==MAX-1)
    printf("\n Queue OverFlow Occured");
  else if(front==-1&&rear==-1)
  {
      front=rear=0;
      queue[rear]=num;
 
  }
  else if(rear==MAX-1 && front!=0)
  {
    rear=0;
    queue[rear]=num;
  }
  else
  {
      rear++;
      queue[rear]=num;
  }
}
void delete_element()
{
  int element;
  if(front==-1)
  {
      printf("\n Underflow");
  }
  element=queue[front];
  if(front==rear)
     front=rear=-1;
  else
  {
    if(front==MAX-1)
      front=0;
    else
      front++;
       printf("\n The deleted element is: %d",element);
  }
 
}
void display_queue()
{
    int i;
    if(front==-1)
      printf("\n No elements to display");
    else
    {
      printf("\n The queue elements are:\n ");
      for(i=front;i<=rear;i++)
      {
          printf("\t %d",queue[i]);
      }
    }
}

Thursday, 23 July 2015

Write a C Program To Fine Minimum Element From An Array

#include <stdio.h>
 
int main()
{
  int array[100], maximum, size, c, location = 1;
 
  printf("Enter the number of elements in array\n");
  scanf("%d", &size);
 
  printf("Enter %d integers\n", size);
 
  for (c = 0; c < size; c++)
    scanf("%d", &array[c]);
 
  maximum = array[0];
 
  for (c = 1; c < size; c++)
  {
    if (array[c] < maximum)
    {
       maximum  = array[c];
       location = c+1;
    }
  }
 
  printf("Maximum element is present at location %d and it's value is %d.\n", location, maximum);
  return 0;
}

Write a C Program to FInd Maximum Element From An Array

#include <stdio.h>
 
int main()
{
  int array[100], maximum, size, c, location = 1;
 
  printf("Enter the number of elements in array\n");
  scanf("%d", &size);
 
  printf("Enter %d integers\n", size);
 
  for (c = 0; c < size; c++)
    scanf("%d", &array[c]);
 
  maximum = array[0];
 
  for (c = 1; c < size; c++)
  {
    if (array[c] > maximum)
    {
       maximum  = array[c];
       location = c+1;
    }
  }
 
  printf("Maximum element is present at location %d and it's value is %d.\n", location, maximum);
  return 0;
}

Write a C Program To print Summation of Two Number Using Pointer

#include <stdio.h>
 
int main()
{
   int first, second, *p, *q, sum;
 
   printf("Enter two integers to add\n");
   scanf("%d%d", &first, &second);
 
   p = &first;
   q = &second;
 
   sum = *p + *q;
 
   printf("Sum of entered numbers = %d\n",sum);
 
   return 0;
}

Tuesday, 21 July 2015

Write a C Program To Find Summation And Multiplication Of Inputed Array Elements

Write a C Program To Find Summation And Multiplication Of Inputed Array Elements
 
#include<stdio.h>
#include<conio.h>

void main()
{
    int i,no[5],n,sum,mul;

    clrscr();
    sum=0;
    mul=1;
    printf("Enter n:");
    scanf("%d",&n);

    for(i=0;i<n;i++)
    {
        printf("\nEnter No[%d]:",i);
        scanf("%d",&no[i]);
    }
    for(i=0;i<n;i++)
    {
    sum=sum+no[i];
    mul=mul*no[i];
    printf("\nValue of No[%d]:%d",i,no[i]);
    }
    printf("\nSum : %d",sum);
    printf("\n Multiplication =%d",mul);
    getch();
}

Write a C Program To Convert String in Lowercase Letter

Write a C Program to Convert String in Lowercase Letter

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

    char nm[10],anm[10];
    clrscr();

    printf("Enter nm:");
    fflush(stdin);
    scanf("%s",nm);

    printf("Lowercase:%s",strlwr(nm));

    getch();
}

Write a C Program To Convert String in Uppercase Letter

Write a C Program To Convert String in Uppercase Letter

WAY=1

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

    char nm[10],anm[10];
    clrscr();

    printf("Enter nm:");
    fflush(stdin);
    scanf("%s",nm);

    printf("Uppercase:%s",strupr(nm));

    getch();
}


WAY = 2

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

int main(void)
{
   char *string = "Hello", *ptr;
   clrscr();
   /* converts string to upper case characters */
   ptr = strupr(string);
   printf("%s\n", ptr);
   return 0;
}