C/C++ Program to sort the integer array in ascending order, C/C++ Program for Bubble Sorting in Array, Program to enter 10 numbers & arrange them in ascending order.
Program
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,a[10],temp=0;
clrscr();
printf("Enter the 10 Numbers:\n");
for(i=0;i<10;i++)
{
scanf("%d", &a[i]);
}
for(i=0;i<10;i++)
{
for(j=0;j<9;j++)
{
if(a[j] > a[j+1])
{ temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
} } }
printf("Array in ascending order is:\n");
for(i=0;i<10;i++)
{
printf("%d ",a[i]);
}
getch();
}
Changes for C++
If you want to write the same program in c++ apply the following changes to the program.
1.) change the header file from "#include<stdio.h>" to "#include<iostream>.h"
2.) for input & output use "cout<<" & "cin>>" instead of "printf" & "scanf".
3.) don't use "% "symbol and "&" sign in "cin>>" statement.
No comments:
Post a Comment