Write a program for Sorting of Numbers using Functions & Pointer?

#include<stdio.h> #include<conio.h> void sort(int  * ,int); void main() { int a[10], i, n; printf(“enter how many ...

#include<stdio.h>
#include<conio.h>
void sort(int *,int);
void main()
{
int a[10], i, n;
printf(“enter how many elements”);
scanf(“%d”, &n);
printf(“enter elements”);
for(i=0; i<n;i++)
scanf(“%d”, &a[i]);
sort(a,n);
printf(“sorted elements are \n”);
for(i=0, i<n; i++)
printf(“%4d”, a[i]);
getch();
}

void sort(int *a, int n)
       {
            int i, j, t;
            for(i=0;i<n–1;i++)
              {
                 for(j=i+1;j<n;j++)
                     {
                        if(a[i]>a[j])
                              {
                                    t=a[i];
                                    a[i] =a[j];
                                    a[j]=t;
                                }
                        }
                 }

       }           

Related

Write A Program to read the order of matrix and read elements into 2 dimentional array and display the elements in matrix format

#include<stdio.h> #include<conio.h> void main ( ) { int x[10][10],i,j,m,n; clrscr ( ); printf (“enter order of matrix”); scanf ("%d%d”,&n,&m); for ( i =0; < n; i++) ...

Write A Program to scan two dimensional array & print only even numbers

#include<stdio.h> #include<conio.h> void main ( ) { int a [10] [10], i, j, r, c , f = 0; printf (“enter number of rows and columns”); scanf ( "%d%d”, & r, &c); printf (“...

Write a Program for calculating Sum of n numbers using recursion

#include<stdio.h> #include<conio.h> int sum ( int n); void main ( ) { int n , s; printf (“enter a number”); scanf ("%d", & n); s = sum ( n); printf (“\n sum of numbers is ...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item