Skip to content
Home » C Programs » Ascending Order in C Using If-Else

Ascending Order in C Using If-Else

Program to sorting numbers in c. This program will sort the array elements in the ascending order in output. Putting numbers in ascending order means starting with the smallest and working your way up to the highest

Sorting in C Program

Sorting is the process of putting items in ascending (or descending) order.

When people realised how important it was to find information quickly, they coined the term sorting.

The method of organising integers from smallest to largest from left to right is known as ascending order in mathematics.

It can also refer to organising letters or words from A to Z in alphabetical order.

Ascending means “up,” hence ascending order indicates that the numbers are increasing.

Temp Variable in C

A temporary variable is a variable in computer programming that has a brief lifetime and is used to retain data that will be removed quickly or before it can be stored in a more permanent memory location.

It’s commonly stated as a local variable, or a variable with local scope, because it’s short-lived.

A temp variable is a temporary variable that can be used in a C program to swap two numbers or temporarily assign any value.

For Loop Definition in C

In the C programming language, the for loop is used to iterate statements or parts of a program numerous times.

It is commonly used to traverse data structures such as an array and a linked list.

A for-loop, or simply for loop, is a control flow statement in computer science that specifies iteration and allows code to be executed repeatedly.

While while-loops increment and test a loop variable, for-loops can be regarded of as short hands for while-loops.

Ascending Order in C Using If-Else

//Ascending Order in C Using If-Else
#include<stdio.h>
void main()
{
int i,j,n,a[100],temp;
printf("Enter the number of elements\n");
scanf("%d",&n) ;
printf("Enter the elements\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
printf("After Ascending order\n");
for(i=0;i<n;i++)
{
printf("%d ",a[i]);
}
}

Output of ascending order in c using if else

Enter the number of elements

5

Enter the elements

54 1 67 89 54

After Ascending order 1 54 54 67 89