Hi I'm Hans Welcome to my Website...
Custom Search

Facebook

PUNP-nians

PUNP-nians

Latest topics

» PM.,Grade lang po
Fri Feb 18, 2011 10:21 pm by Evildarkwarrior_18

» GRADES for SEMI Finals
Mon Oct 25, 2010 2:26 am by amvou13

» BSIT 1 Computer Programming 1
Mon Oct 25, 2010 2:11 am by amvou13

» AIT 1 B Computer Programming 1
Mon Oct 25, 2010 2:09 am by amvou13

» AIT 1 A Computer Programming 1
Mon Oct 25, 2010 2:05 am by amvou13

» BSCS 2 Design Analysis of Algorithm
Mon Oct 25, 2010 2:00 am by amvou13

» ACT 1 Computer Hardware and Software Installation
Mon Oct 25, 2010 1:58 am by amvou13

» ACT 2 PC Troubleshooting
Mon Oct 25, 2010 1:51 am by amvou13

» BSCS 3 and BSIT 3 Web Development/Programming 1
Mon Oct 25, 2010 1:49 am by amvou13

ahm

Thu Aug 26, 2010 6:47 am by elyn

bakit ang mahal ng bbyaran
sa seminar...

dpat ndi na
nmen babayaran ung fair ng bus ehhh...
sagot na dpat ng skul kc studentd kme...

dhil jan madame
tuloy nde ppnta kht pa
required....
sna aman bawasan ung bayad... Surprised

bom bom bom

Donations

RSS feeds


Yahoo! 
MSN 
AOL 
Netvibes 
Bloglines 

Shopmotion


    C++ program that will sort n-numbers into ascending or descending order using array and loops

    Share

    amvou13
    Admin

    Posts: 84
    Join date: 2010-07-28
    Age: 27

    C++ program that will sort n-numbers into ascending or descending order using array and loops

    Post  amvou13 on Mon Oct 25, 2010 2:12 am

    Hi everyone,

    Just want to share my simple program that will sort n-numbers into ascending or descending order. Hope this will help C++ beginner programmers...



    #include<stdio.h>
    #include<conio.h>
    main()
    {
    //clrscr();

    int a[10], empa[10], num[10];
    int input, type;
    int i, j, emp;

    for(i=0;i<=10;i++)
    { a[i]=0;
    empa[i]=0;
    num[i]=0;
    }

    printf("How many numbers? ");
    scanf("%i",&input);

    printf("n[1] Ascendingn[2] Descending");
    printf("nnPlease choose: ");
    scanf("%i",&type);

    printf("n");
    //input in array
    for(i=0,j=0; i<input,j<input; i++,j++)
    {
    printf("number %i = ",i+1);
    scanf("%i",&a[i]);
    emp=j+1;
    num[j]=emp;
    empa[j]=num[j];
    empa[j]=a[i];
    }

    printf("n");

    if (type==1)
    {
    printf("nYou have chosen ascending order");
    //arrange in ascending order
    for(i=0; i<input; i++)
    {
    for(j=0; j<input; j++)
    {
    if(a[i]<a[j])
    {
    emp=a[j];
    a[j]=a[i];
    a[i]=emp;
    }
    }
    }

    }
    else
    {
    printf("nYou have chosen descending order");
    //arrange in descending order
    for(i=0; i<input; i++)
    {
    for(j=0; j<input; j++)
    {
    if(a[i]>a[j])
    {
    emp=a[j];
    a[j]=a[i];
    a[i]=emp;
    }
    }
    }

    }
    printf("nArrange Order:nn");


    for(i=0; i<input; i++)
    {
    for(j=0; j<input; j++)
    {
    if(a[i]==empa[j])
    {
    printf("Number %i = ",num[j]);
    }
    }
    printf("%in",a[i]);
    }


    getch();
    return 0;
    }


      Current date/time is Sat Aug 30, 2014 6:12 pm