View Single Post
Old 09-09-2007, 10:23 PM   #70 (permalink)
Quiz_Master
* Teh Flirt King *
 
Quiz_Master's Avatar
 
Join Date: Dec 2005
Location: Originally From : Ratlam M.P., Currently in: Hyderabad
Posts: 972
Default Re: Post ur C/C++ Programs Here

Honestly Speaking this is going to be my fevorite thread ever on Digit forum...
BookMarked...
[Its very usefull for a BCA 3rd Sem student of a small town and thats me.. ]

OK, let me post my Today's Homework here..hehe...

Write a C Program to sort numbers of an Array using Bubble Sort Method.

Code:
#include <stdio.h>
#define MAX 10
void swap(int *x,int *y)
{
   int temp;
   temp = *x;
   *x = *y;
   *y = temp;
}
void bsort(int list[], int n)
{
   int i,j;
   for(i=0;i<(n-1);i++)
      for(j=0;j<(n-(i+1));j++)
             if(list[j] > list[j+1])
                    swap(&list[j],&list[j+1]);
}
void readlist(int list[],int n)
{
   int i;
   printf("Enter the elements\n");
   for(i=0;i<n;i++)
       scanf("%d",&list[i]);
}

void printlist(int list[],int n)
{
   int i;
   printf("The elements of the list are: \n");
   for(i=0;i<n;i++)
      printf("%d\t",list[i]);
}

void main()
{
   int list[MAX], n;
   printf("Enter the number of elements in the list max = 10\n");
   scanf("%d",&n);
   readlist(list,n);
   printf("The list before sorting is:\n");
   printlist(list,n);
   bsort(list,n);
   printf("The list after sorting is:\n");
   printlist(list,n);
}
Quote:
Originally Posted by Intel_Gigacore
^ theres nothing in Hint
There IS..
Just Highlight the post.
__________________
World is just a Quizzical Reality : Quiz_Master//Ashwin :D

Blog: http://ashwinsaxena.com/blog - Tech, Life and Other Things.

Last edited by Quiz_Master; 09-09-2007 at 10:23 PM. Reason: Automerged Doublepost
Quiz_Master is offline