Sort numbers based on the user input Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)Servo commands based on serial port inputScalability of running commands from user inputSort and display input numbersSumming user inputGet initials from name input by userCustom user input functionSimple Lotto GameGeneric Pairing Heap PerformanceHandling user input - follow-upScan the user input and then work with these letters

How do I automatically answer y in bash script?

What is the electric potential inside a point charge?

How can I protect witches in combat who wear limited clothing?

Keep going mode for require-package

What are the performance impacts of 'functional' Rust?

How is simplicity better than precision and clarity in prose?

Strange behaviour of Check

What was Bilhah and Zilpah's ancestry?

What did Darwin mean by 'squib' here?

Do working physicists consider Newtonian mechanics to be "falsified"?

Two different pronunciation of "понял"

Problem when applying foreach loop

What's the difference between (size_t)-1 and ~0?

I'm having difficulty getting my players to do stuff in a sandbox campaign

Windows 10: How to Lock (not sleep) laptop on lid close?

Classification of bundles, Postnikov towers, obstruction theory, local coefficients

How does modal jazz use chord progressions?

Why is "Captain Marvel" translated as male in Portugal?

How did passengers keep warm on sail ships?

Was credit for the black hole image misattributed?

I'm thinking of a number

Can smartphones with the same camera sensor have different image quality?

Limit for e and 1/e

Working around an AWS network ACL rule limit



Sort numbers based on the user input



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)Servo commands based on serial port inputScalability of running commands from user inputSort and display input numbersSumming user inputGet initials from name input by userCustom user input functionSimple Lotto GameGeneric Pairing Heap PerformanceHandling user input - follow-upScan the user input and then work with these letters



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0












$begingroup$


The purpose of the my program is to sort numbers based on the user input. Everything works perfectly, until user wants to input more than 6 data (inp = 5) and I am not sure why is it happening. Can you review it for best coding practices?



Code



#include <stdio.h>
#include <stdlib.h>

int size =0;

void ascSort(int a[size], int size, int temp)
for(int i=1; i< size; i++)
for(int j=i; j>0; j--)
if(a[j-1]>a[j])
temp = a[j-1];
a[j-1] = a[j];
a[j] = temp;





void descSort(int a[size], int size, int temp)
for(int i=1; i< size; i++)
for(int j=i; j>0; j--)
if(a[j-1]<a[j])
temp = a[j-1];
a[j-1] = a[j];
a[j] = temp;




int main()
char inpChar, isContinue='y';
int inp, temp=0;
int a[size];

do
printf("How many numbers would you like to sort?n");
fflush(stdin);
scanf("%d", &inp);
size = inp;

printf("%dn", size);

for(int i=0; i<size; i++)
//Below, I am printing 'size' for debugging purposes
printf("Type %d more numbers to sort ---- '%d'n", inp, size);
fflush(stdin);
scanf("%d", &a[i]);
inp--;

printf("Please input a for ascending order and d for descending ordern");
fflush(stdin);
scanf(" %c", &inpChar);

switch (inpChar)
case 'a':
ascSort(a, size, temp);
break;
case 'd':
descSort(a, size, temp);
break;
default: printf("Invalid charactern");


printf("Sorted Array: n" );
for(int i=0; i<size; i++)
printf("%dn", a[i]);

printf("Do you want to repeat? Type y/nn");
fflush(stdin);
scanf(" %c", &isContinue);
while(isContinue != 'n');











share|improve this question









New contributor




Gaous Muhammad Saklaen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$







  • 1




    $begingroup$
    Thanks a lot. Gonna do it now. Didn't know that before, by the way.
    $endgroup$
    – Gaous Muhammad Saklaen
    6 mins ago










  • $begingroup$
    You're very welcome!
    $endgroup$
    – Emma
    3 mins ago

















0












$begingroup$


The purpose of the my program is to sort numbers based on the user input. Everything works perfectly, until user wants to input more than 6 data (inp = 5) and I am not sure why is it happening. Can you review it for best coding practices?



Code



#include <stdio.h>
#include <stdlib.h>

int size =0;

void ascSort(int a[size], int size, int temp)
for(int i=1; i< size; i++)
for(int j=i; j>0; j--)
if(a[j-1]>a[j])
temp = a[j-1];
a[j-1] = a[j];
a[j] = temp;





void descSort(int a[size], int size, int temp)
for(int i=1; i< size; i++)
for(int j=i; j>0; j--)
if(a[j-1]<a[j])
temp = a[j-1];
a[j-1] = a[j];
a[j] = temp;




int main()
char inpChar, isContinue='y';
int inp, temp=0;
int a[size];

do
printf("How many numbers would you like to sort?n");
fflush(stdin);
scanf("%d", &inp);
size = inp;

printf("%dn", size);

for(int i=0; i<size; i++)
//Below, I am printing 'size' for debugging purposes
printf("Type %d more numbers to sort ---- '%d'n", inp, size);
fflush(stdin);
scanf("%d", &a[i]);
inp--;

printf("Please input a for ascending order and d for descending ordern");
fflush(stdin);
scanf(" %c", &inpChar);

switch (inpChar)
case 'a':
ascSort(a, size, temp);
break;
case 'd':
descSort(a, size, temp);
break;
default: printf("Invalid charactern");


printf("Sorted Array: n" );
for(int i=0; i<size; i++)
printf("%dn", a[i]);

printf("Do you want to repeat? Type y/nn");
fflush(stdin);
scanf(" %c", &isContinue);
while(isContinue != 'n');











share|improve this question









New contributor




Gaous Muhammad Saklaen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$







  • 1




    $begingroup$
    Thanks a lot. Gonna do it now. Didn't know that before, by the way.
    $endgroup$
    – Gaous Muhammad Saklaen
    6 mins ago










  • $begingroup$
    You're very welcome!
    $endgroup$
    – Emma
    3 mins ago













0












0








0


0



$begingroup$


The purpose of the my program is to sort numbers based on the user input. Everything works perfectly, until user wants to input more than 6 data (inp = 5) and I am not sure why is it happening. Can you review it for best coding practices?



Code



#include <stdio.h>
#include <stdlib.h>

int size =0;

void ascSort(int a[size], int size, int temp)
for(int i=1; i< size; i++)
for(int j=i; j>0; j--)
if(a[j-1]>a[j])
temp = a[j-1];
a[j-1] = a[j];
a[j] = temp;





void descSort(int a[size], int size, int temp)
for(int i=1; i< size; i++)
for(int j=i; j>0; j--)
if(a[j-1]<a[j])
temp = a[j-1];
a[j-1] = a[j];
a[j] = temp;




int main()
char inpChar, isContinue='y';
int inp, temp=0;
int a[size];

do
printf("How many numbers would you like to sort?n");
fflush(stdin);
scanf("%d", &inp);
size = inp;

printf("%dn", size);

for(int i=0; i<size; i++)
//Below, I am printing 'size' for debugging purposes
printf("Type %d more numbers to sort ---- '%d'n", inp, size);
fflush(stdin);
scanf("%d", &a[i]);
inp--;

printf("Please input a for ascending order and d for descending ordern");
fflush(stdin);
scanf(" %c", &inpChar);

switch (inpChar)
case 'a':
ascSort(a, size, temp);
break;
case 'd':
descSort(a, size, temp);
break;
default: printf("Invalid charactern");


printf("Sorted Array: n" );
for(int i=0; i<size; i++)
printf("%dn", a[i]);

printf("Do you want to repeat? Type y/nn");
fflush(stdin);
scanf(" %c", &isContinue);
while(isContinue != 'n');











share|improve this question









New contributor




Gaous Muhammad Saklaen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$




The purpose of the my program is to sort numbers based on the user input. Everything works perfectly, until user wants to input more than 6 data (inp = 5) and I am not sure why is it happening. Can you review it for best coding practices?



Code



#include <stdio.h>
#include <stdlib.h>

int size =0;

void ascSort(int a[size], int size, int temp)
for(int i=1; i< size; i++)
for(int j=i; j>0; j--)
if(a[j-1]>a[j])
temp = a[j-1];
a[j-1] = a[j];
a[j] = temp;





void descSort(int a[size], int size, int temp)
for(int i=1; i< size; i++)
for(int j=i; j>0; j--)
if(a[j-1]<a[j])
temp = a[j-1];
a[j-1] = a[j];
a[j] = temp;




int main()
char inpChar, isContinue='y';
int inp, temp=0;
int a[size];

do
printf("How many numbers would you like to sort?n");
fflush(stdin);
scanf("%d", &inp);
size = inp;

printf("%dn", size);

for(int i=0; i<size; i++)
//Below, I am printing 'size' for debugging purposes
printf("Type %d more numbers to sort ---- '%d'n", inp, size);
fflush(stdin);
scanf("%d", &a[i]);
inp--;

printf("Please input a for ascending order and d for descending ordern");
fflush(stdin);
scanf(" %c", &inpChar);

switch (inpChar)
case 'a':
ascSort(a, size, temp);
break;
case 'd':
descSort(a, size, temp);
break;
default: printf("Invalid charactern");


printf("Sorted Array: n" );
for(int i=0; i<size; i++)
printf("%dn", a[i]);

printf("Do you want to repeat? Type y/nn");
fflush(stdin);
scanf(" %c", &isContinue);
while(isContinue != 'n');








c






share|improve this question









New contributor




Gaous Muhammad Saklaen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Gaous Muhammad Saklaen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 10 mins ago









Emma

2021215




2021215






New contributor




Gaous Muhammad Saklaen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 43 mins ago









Gaous Muhammad SaklaenGaous Muhammad Saklaen

12




12




New contributor




Gaous Muhammad Saklaen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Gaous Muhammad Saklaen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Gaous Muhammad Saklaen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







  • 1




    $begingroup$
    Thanks a lot. Gonna do it now. Didn't know that before, by the way.
    $endgroup$
    – Gaous Muhammad Saklaen
    6 mins ago










  • $begingroup$
    You're very welcome!
    $endgroup$
    – Emma
    3 mins ago












  • 1




    $begingroup$
    Thanks a lot. Gonna do it now. Didn't know that before, by the way.
    $endgroup$
    – Gaous Muhammad Saklaen
    6 mins ago










  • $begingroup$
    You're very welcome!
    $endgroup$
    – Emma
    3 mins ago







1




1




$begingroup$
Thanks a lot. Gonna do it now. Didn't know that before, by the way.
$endgroup$
– Gaous Muhammad Saklaen
6 mins ago




$begingroup$
Thanks a lot. Gonna do it now. Didn't know that before, by the way.
$endgroup$
– Gaous Muhammad Saklaen
6 mins ago












$begingroup$
You're very welcome!
$endgroup$
– Emma
3 mins ago




$begingroup$
You're very welcome!
$endgroup$
– Emma
3 mins ago










0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "196"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);






Gaous Muhammad Saklaen is a new contributor. Be nice, and check out our Code of Conduct.









draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f217460%2fsort-numbers-based-on-the-user-input%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes








Gaous Muhammad Saklaen is a new contributor. Be nice, and check out our Code of Conduct.









draft saved

draft discarded


















Gaous Muhammad Saklaen is a new contributor. Be nice, and check out our Code of Conduct.












Gaous Muhammad Saklaen is a new contributor. Be nice, and check out our Code of Conduct.











Gaous Muhammad Saklaen is a new contributor. Be nice, and check out our Code of Conduct.














Thanks for contributing an answer to Code Review Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

Use MathJax to format equations. MathJax reference.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f217460%2fsort-numbers-based-on-the-user-input%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

名間水力發電廠 目录 沿革 設施 鄰近設施 註釋 外部連結 导航菜单23°50′10″N 120°42′41″E / 23.83611°N 120.71139°E / 23.83611; 120.7113923°50′10″N 120°42′41″E / 23.83611°N 120.71139°E / 23.83611; 120.71139計畫概要原始内容臺灣第一座BOT 模式開發的水力發電廠-名間水力電廠名間水力發電廠 水利署首件BOT案原始内容《小檔案》名間電廠 首座BOT水力發電廠原始内容名間電廠BOT - 經濟部水利署中區水資源局

格濟夫卡 參考資料 导航菜单51°3′40″N 34°2′21″E / 51.06111°N 34.03917°E / 51.06111; 34.03917ГезівкаПогода в селі 编辑或修订