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 3:21 pm by Evildarkwarrior_18

» GRADES for SEMI Finals
Sun Oct 24, 2010 8:26 pm by amvou13

» BSIT 1 Computer Programming 1
Sun Oct 24, 2010 8:11 pm by amvou13

» AIT 1 B Computer Programming 1
Sun Oct 24, 2010 8:09 pm by amvou13

» AIT 1 A Computer Programming 1
Sun Oct 24, 2010 8:05 pm by amvou13

» BSCS 2 Design Analysis of Algorithm
Sun Oct 24, 2010 8:00 pm by amvou13

» ACT 1 Computer Hardware and Software Installation
Sun Oct 24, 2010 7:58 pm by amvou13

» ACT 2 PC Troubleshooting
Sun Oct 24, 2010 7:51 pm by amvou13

» BSCS 3 and BSIT 3 Web Development/Programming 1
Sun Oct 24, 2010 7:49 pm by amvou13

ahm

Thu Aug 26, 2010 12: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 Sun Oct 24, 2010 6:12 pm

    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 Nov 01, 2014 6:52 am