Write a program in C language to input any ten numbers. Now sort them in ascending order and print them.
#include <stdio.h>
int main() {
int arr[10], i, j, temp;
// Input 10 numbers
printf("Enter 10 numbers:\n");
for (i = 0; i < 10; i++) {
scanf("%d", &arr[i]);
}
// Sort the array in ascending order using bubble sort algorithm
for (i = 0; i < 9; i++) {
for (j = 0; j < 9 - i; j++) {
if (arr[j] > arr[j + 1]) {
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
// Print the sorted array
printf("Numbers in ascending order:\n");
for (i = 0; i < 10; i++) {
printf("%d\n", arr[i]);
}
return 0;
}
Netra Koirala
Computer Science Educator
Passionate computer science educator and author. Provides free study notes, practical guides, and tutorials for Class 9, 10, 11, 12, and B.Sc CSIT students in Nepal. Years of teaching experience in computer science fundamentals.
LinkedIn ProfileRelated Posts
Loading related posts…
Computer Science notes, tutorials, MCQs, and educational resources for Nepal students. Covering Class 9, SEE preparation, Class 11, Class 12, SLC, programming, DBMS, networking, HTML, JavaScript, PHP, OOP and more.
Featured Post
Grade 10 Computer Science: Specification Grid & Model Questions
Specification Grid & Model Questions of Computer Science | Grade 10 📚 Examination Resource Specification Grid & M...