Hi to all C enthusiasts,
Greetings!
My name is Alexander, a C enthusiast, 17-year-old, and live in Bacolod City, Negros Occidental Philippines. I have given my brief info and this is my first time to post here. My problem is, I have coded an output like this:
I tried it with this code..Code:Enter num1: 1 Enter num2: 1 Enter num3: 3 Enter num4: 5 Enter num5: 3 Number 1 appeared 2x Number 3 appeared 2x Number 5 appeared 1x
Please anyone, evaluate this problem and post me your responses so that it will help enhance my understanding in arrays and loops.Code:#include <stdio.h> #include <conio.h> void main() { int num[5] = {0}; int x, y, temp; clrscr(); for(x = 0; x <= 4; x++) { printf("Enter num%d: ", x+1); scanf("%d", &num[x]); } printf("\n"); for(x = 0; x <= 3; x++) { for(y = x + 1; y <= 3; y++) { if(num[x] > num[y]) { temp = num[x]; num[x] = num[y]; num[y] = temp; } printf("\n"); int h = 0; x = 0; y = 1; while(x <= 4) { h = 1; printf("Number %d ", num[x]); while(num[x] == num[y]) { y++; h++; x++; } printf("appeared %dx\n", h); if(h == 1) { x++; y++; } else { x = y; y++; } } } } getch(); } But the Output is: Enter num1: 1 Enter num2: 1 Enter num3: 3 Enter num4: 5 Enter num5: 3 Number 1 appeared 2x Number 3 appeared 1x Number 5 appeared 1x Number 3 appeared 1x
Thank you in advance..
Cordially Yours,
Alexander Daguob
Student, BSCOE - I, AMACC - B



LinkBack URL
About LinkBacks


