aboutsummaryrefslogtreecommitdiff
path: root/tests/upload/line_search.sy
diff options
context:
space:
mode:
authorRichard Qin <richard.qin.001@gmail.com>2026-09-15 08:16:43 +0800
committerRichard Qin <richard.qin.001@gmail.com>2026-09-15 08:16:43 +0800
commit4022e5c95210631e4aceb08eaf9d9071aa5aefc4 (patch)
treea5922559836e45fb3459a3d070367912e1035b1a /tests/upload/line_search.sy
downloadrcc-master.tar.gz
rcc-master.tar.xz
Set up a git repoHEADmaster
Diffstat (limited to 'tests/upload/line_search.sy')
-rw-r--r--tests/upload/line_search.sy54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/upload/line_search.sy b/tests/upload/line_search.sy
new file mode 100644
index 0000000..84d1f51
--- /dev/null
+++ b/tests/upload/line_search.sy
@@ -0,0 +1,54 @@
+int MAX=1000;
+int intArray[1000];
+
+int find(int data){
+ int comparisons;
+ int index;
+ int i;
+
+ comparisons = 0;
+ index = -1;
+
+ i=0;
+ while(i<MAX){
+ // count the comparisons made
+ comparisons = comparisons + 1;
+ // if data found, break the loop
+ if(data == intArray[i]){
+ index = i;
+ break;
+ }
+ i=i+1;
+ }
+ putint(comparisons);
+ putch(10);
+ return index;
+}
+
+void display(){
+ int i;
+ i=0;
+ while(i<MAX){
+ putint(intArray[i]);
+ i=i+1;
+ }
+ putch(10);
+}
+
+int main(){
+ int i;
+ int location;
+ int QQQQ;
+
+ QQQQ=getint();
+ i=0;
+ while (i<MAX) {
+ intArray[i] = i;
+ i=i+1;
+ }
+ display();
+ location = find(QQQQ);
+ putint(location);
+ putch(10);
+ return 0;
+}