How to sort Names in alphabetical order

Thread Starter

Parth786

Joined Jun 19, 2017
642
For example if there are four names Johan, Dav, Wendy and Smith ..shorting Dav, Johan, Smith Wendy.

How to sort names in alphabetical order (c programming )

I am looking help to build flow chart. I have no idea how to do it but I tried . I made flow chart which get input number means how many name user want to sort then it check the number that the user enters for the number of names against the legal number (at least 1 but no more than 4, in this case) and if the number is not legal, print an error message and ask again .

upload_2017-10-31_18-14-22.png
 

MrChips

Joined Oct 2, 2009
34,737
Before you attempt to sort names in alphabetical order, try sorting numbers.

For example, sort the following numbers in ascending order:
5 34 6 12 0 1 6 9 45 11 6 9 2 15 22 3 18 37 8

Be aware that there are more than one algorithm for sorting.

See if you can devise your own sort algorithm. After you have done that, research various sort algorithms such as "bubble sort".
 

Thread Starter

Parth786

Joined Jun 19, 2017
642
Before you attempt to sort names in alphabetical order, try sorting numbers.

For example, sort the following numbers in ascending order:
5 34 6 12 0 1 6 9 45 11 6 9 2 15 22 3 18 37 8

Be aware that there are more than one algorithm for sorting.

See if you can devise your own sort algorithm. After you have done that, research various sort algorithms such as "bubble sort".
C:
#include <stdio.h>

int main(void)
{
    int a[20], i = 0, j = 0, n, t;

    printf ("\n Pramot user to Enter Element: ");
    scanf ("%d", &n);
    printf ("\n");

    for (i = 0; i < n; i++)
    {
        printf ("\n Enter the %dth element: ", (i+1));
        scanf ("%d", &a[i]);
    }

    for (j = 0 ; j <(n-1); j++)
    {
        for ( i = 0 ; i <(n-1) ; i++)
        {
            if (a[i+1] < a[i])
            {
                t = a[i];
                a[i] = a[i + 1];
                a[i + 1] = t;
            }
        }
    }

    printf ("\n Ascending order: ");
    for (i=0 ; i<n ; i++)
    {
        printf (" %d", a[i]);
    }

    
      return 0;
}
Result :
Pramot user to Enter Element: 19

Enter the 1th element: 5
Enter the 2th element: 34
Enter the 3th element: 6
Enter the 4th element: 12
Enter the 5th element: 0
Enter the 6th element: 1
Enter the 7th element: 6
Enter the 8th element: 9
Enter the 9th element: 45
Enter the 10th element: 11
Enter the 11th element: 6
Enter the 12th element: 9
Enter the 13th element: 2
Enter the 14th element: 15
Enter the 15th element: 22
Enter the 16th element: 3
Enter the 17th element: 18
Enter the 18th element: 37
Enter the 19th element: 8

Ascending order: 0 1 2 3 5 6 6 6 8 9 9 11 12 15 18 22 34 37 45
 

MrChips

Joined Oct 2, 2009
34,737
I can copy the same program straight off the internet.
Did I learn anything except how to use google?

Code:
#include<stdio.h>

int main()
{
  int a[20], n, i, j, temp;
  printf ("Enter the size of array: ");
  scan f("%d",&n);
  printf ("Enter the array elements: ");
  for (i=0;i<n;++i)
    scanf ("%d",&a[i]);
  for (i=1;i<n;++i)
   for (j=0;j<(n-i);++j)
    if (a[j]>a[j+1])
    {
      temp=a[j];
      a[j]=a[j+1];
      a[j+1]=temp;
     }
printf("\n Ascending order: ");
for (i=0;i<n;++i)
  printf("%d ",a[i]);

return 0;
}
 

JohnInTX

Joined Jun 26, 2012
4,787
I can copy the same program straight off the internet.
Did I learn anything except how to use google?
Or how to post on multiple forums?
http://www.electro-tech-online.com/threads/how-to-arrange-names-in-alphabetical-order.152156/

In fact, I see by a simple search of ETO that most of the stuff that @Parth786 asks on AAC he also asks on ETO at the same time. The list includes such recent AAC topics as DS1307, IoT, function parameters, storing user input, loops and conditional statements, keypad scanning and the simple calculator. Now I understand, Parth, why you frequently just stop working in a thread after AAC members spend a lot of time trying to help you.

You spend lots of time looking for canned solutions from the internet, cross-posting the same questions on several forums and trying to sort out all of the different answers. I'm wondering if that time was instead spent actually studying C, basic programming topics and reading some of that code to understand it in detail you might be better off.

Good luck.
 
Last edited:

Thread Starter

Parth786

Joined Jun 19, 2017
642
Or how to post on multiple forums?
http://www.electro-tech-online.com/threads/how-to-arrange-names-in-alphabetical-order.152156/

In fact, I see by a simple search of ETO that most of the stuff that @Parth786 asks on AAC he also asks on ETO at the same time. The list includes such recent AAC topics as DS1307, IoT, function parameters, storing user input, loops and conditional statements, keypad scanning and the simple calculator.

Now I understand, Parth, why you frequently just stop working in a thread after AAC members spend a lot of time trying to help you
As I have told you earlier that I want to learn embedded programming. I want to make future in embedded system I am interested to make project on internet of things. I have made many effort for this. That's why you are seeing all of my threads

I have completed all the thread on this forum expect for just two part Keypad and I2C programming.
I have been written program for LED blinking , controlling LED using Switch, controlling LED using Push button, message
display on screen but after my many efforts I couldn't write program for keypad interfacing

Did you remember this thread
https://forum.allaboutcircuits.com/threads/matrix-keypad-row-and-column-scanning-process.141566/

you said that there is no need to create a new thread.you can continue from old thread. I did what you said I started with old

https://forum.allaboutcircuits.com/threads/keypad-interfacing-using-8051.137828/
But I did not get any answer. I have not stopped working. I stopped working on two topics keypad and I2C Programming. I thought I should read it myself after that I should post specific problem I did exactly this I read about the logic of keypad but I could not write program
but I couldn't find find any help. after this I had not any other way. that's why I have stooped working on it right now
I can copy the same program straight off the internet.
Did I learn anything except how to use google?
Where is your flow chart?
I have two reason to not make flow chart first I don't have full access of software to use maximum element so I can use only limited element. and If I make flow chart it take more then half hour to make it. so I had already program I had tested that program on My PC and I understand how does it work. so that's the reason i posted program directly
You spend lots of time looking for canned solutions from the internet, cross-posting the same questions on several forums and trying to sort out all of the different answers. I'm wondering if that time was instead spent actually studying C, basic programming topics and reading some of that code to understand it in detail you might be better off..
I accepted I have asked question on another forum but my purpose was not to exchange each other's answer.

Have you seen flow charts and code. that is mine. I have created flow chart myself. I have written program myself I have not copied flow chart and program from anywhere
https://forum.allaboutcircuits.com/threads/toggle-led-with-push-button.141078/
https://forum.allaboutcircuits.com/threads/does-my-flow-chart-match-with-program.140942/
and so many

I am giving much attention to study c programming. I have studied printf ,scanf statement, variable deceleration and initialization. data type and type of data type. Function and type of function. Loops (while, for) and control statement (if else , switch case) enum and structure. I am facing problem with some operator I am trying to improve my understanding. I know there is lot to learn but I think it is enough to start for embedded programming. Is not it enough to start embedded programming ?

I am trying to practice much as possible. My learning method is that I write many program and compile them. I try to solve many question myself and when I don't understand I post directly on forum

you can take me in two way. first a person who always use code from internet never want to understand advice which has given. never want to work hard, never want to spend some time on searching on internet. who create thread after thread at same topics

Another way, a person who is taking effort to learn but struggling with some issues in embedded programming

Note: Please don't take it personally. You all are doing wonderful work. Helping someone is great things in life. I don't want to hurt anyone. I know that the advice you give me is for my good. I still want someone to help me to learn keypad programming

Thanks
Parth
 
Last edited:

MrChips

Joined Oct 2, 2009
34,737
I am sure that you have heard the story about fish.
We can give you fish to feed for a day or you can learn how to fish and feed for a lifetime.

You need to learn how to fish. We can only teach you so much. You have to start learning on your own.

So what if it takes one hour or one day to draw a flow chart? That is where the answer lies. You will not learn by trying to understand code that someone else wrote. The solution is not in writing code. The solution is in arriving at algorithms all on your own. If you cannot solve problems on your own you will be going nowhere.
 

spinnaker

Joined Oct 29, 2009
7,830
I am sure that you have heard the story about fish.
We can give you fish to feed for a day or you can learn how to fish and feed for a lifetime.

You need to learn how to fish. We can only teach you so much. You have to start learning on your own.

So what if it takes one hour or one day to draw a flow chart? That is where the answer lies. You will not learn by trying to understand code that someone else wrote. The solution is not in writing code. The solution is in arriving at algorithms all on your own. If you cannot solve problems on your own you will be going nowhere.

I completely disagree that you will not learn from other people's code. I do that all the time. What is important that you understand what is written rather than do a cut and paste.
 

Thread Starter

Parth786

Joined Jun 19, 2017
642
That is where the answer lies.
This is really disappointed statement.
I have two reason to not make flow chart first I don't have full access of software to use maximum element so I can use only limited element. and If I make flow chart it take more then half hour to make it. so I had already program I had tested that program on My PC and I understand how does it work. so that's the reason i posted program directly
Did you see what was my first reason. I have clearly mentioned why I didn't make flow chart. the software that I use to make flow chart does not allow me to draw big flow chart. I can search for another software and I can draw but I didn't do that,I did what I thought better
 

Thread Starter

Parth786

Joined Jun 19, 2017
642

philba

Joined Aug 17, 2017
959
I'd like to point out that many if not most software developers never use a flowchart. It's not a bad tool for teaching program flow but there are many other ways to think through program structure. And, frankly, it doesn't encourage good program structuring.

A lot of people use pseudocode which is easy to think of as sloppy coding because it ignores syntactic and other mundane aspects of coding. There is no one kind, it's all pretty informal. I generally use a pseudocode that looks similar to the language I will be writing in. The advantage of pseudocode over flowcharts is it makes structured programming more obvious.

For example,
Code:
get first value
max = value
while there are more input values
    get value
    if max is less than value
        then max = value
end while
print max
This gives the essence of program flow. It allows me to see program structure while not worrying about compiler level details which come later. One could take the pseudocode to the next level and detail out things like arrays, indexes and counters but a programmer with a little experience would go directly to code. Note: I often will leave out things like "end while" because indentation shows nested structures.
 
Top