Computer Science, asked by kardileshital88, 1 month ago

write a c program to print 10 numbers in descending and ascending order using for while do while loop​

Answers

Answered by devarchanc
0

C Programming

Question

Write a C program to print 10 numbers in descending and ascending order using for, while and do while loop​.

Explanation:

  • Using "for loop"

#include <stdio.h>

void main ()

{

int num[10];

int i, j, temp;

printf("Enter the 10 numbers \n");  

for (i = 0; i < 10 ; ++i)

 scanf("%d", &num[i]);

for (i = 0; i < 10; ++i)

{

 for (j = i + 1; j < 10; ++j)

  {

   if (num[i] < num[j])

   {

    temp = num[i];

    num[i] = num[j];

    num[j] = temp;

  }

 }

}

printf("The numbers arranged in descending order are given below\n");

for (i = 0; i < 10; ++i)

{

  printf("%d\t", num[i]);

}

printf("The numbers arranged in ascending order are given below\n");

for (i = 10; i > 0; i--)

{

  printf("%d\t", num[i]);

}

 }

  • Using while loop

#include <stdio.h>

void main ()

{

int num[10];

int i = 1, j, temp;

printf("Enter the 10 numbers \n");  

for (i = 0; i < 10 ; ++i)

 scanf("%d", &num[i]);

  while (i < 10)

  {

   

  • Using do while

Similar questions