0
Why Scanf is not run properly ?
#include<stdio.h> void Bubble_Sort(char A[],int size) { int i,round; char temp; for(round=0;round<size;round++) { for(i=0;i<round-1;i++) { if(A[i]>A[i+1]) { temp=A[i]; A[i]=A[i+1]; A[i+1]=temp; } } } for(i=0;i<size;i++) { printf("%c\t",A[i]); } } main() { char A[100]; int i,size; printf("\nEnter Your Size Of Array"); scanf("%d",&size); for(i=0;i<size;i++) { scanf("%c",&A[i]); } Bubble_Sort(A,size); }
6 Respuestas
+ 4
It probably doesn't run right because when you scan for characters, spaces and new line characters ALSO count as characters. They're stored but not visible. Look at the spaces i give in the call to scanf(" %c ", &A[i]);
+ 1
works fine here w/ chars. idk what you're trying to do
//input:
3 a b c
//output:
Size: 3
Array values: a b c
https://code.sololearn.com/cgkjdo6n7Mk4/?ref=app
+ 1
Yeah, you'll have to look through my codes and make some changes for yourself though. Mine works fine, probably because i sort and display in different functions. If they are in functions at all
0
I just changed all the character variables to integer variables and made it scan for integers.
//input:
3 2 1 3
//output:
Size: 3
Array values: 1 2 3
https://code.sololearn.com/cLC12UjYhYL1/?ref=app
0
If we use char type value
Why Scanf is not run properly?
0
Input = 3 b d a
Output = a b d
i am thinking to do this !
can you do ??