![]() |
|
|||||||
| Programmer's Corner Discussion forum for all aspects of programming and software engineering. Any software programming language welcome: C, C++, C#, Fortran, Java, Matlab, etc. |
|
|
|
Thread Tools | Display Modes |
|
#11
|
|||
|
|||
|
both are same even if you put curly brackets or not
|
|
#12
|
||||
|
||||
|
Quote:
Cool thanks. Now I can do that in mips assembly pretty easily.
__________________
"The gift of mental power comes from God, if we concentrate our minds on that truth,we become in tune with this great power" Nikola Tesla Science is nothing more than our feeble attempt to understand the mysteries of God. When we succeed, and claim to understand everything there is to know, we show our foolishness. Thank you to all the people who worked on the All About Circuits ebook. It is one of the best electronics books out there. I'm an EE student at the University of Pittsburgh |
|
#13
|
|||
|
|||
|
Hi this should give you a better idea of how this works
I've rewritten the code for you so that it makes more sense then you can see what it does and hopefully get a better understanding #include <stdio.h> // declare global functions int find( int a[], int n, int x) ; int Array[] = { 1,3,5,4,10} ; // define the function in full here int find( int a[], int n, int x) { int i = -1 ; for (i=0; i!=n; i++) { if(a[i]==x){ printf("Match found %d at index X = %d \n \n ",i,x); return i; } // end if }// end for if (i == -1 ) { printf("\n No Match found \n") ; } return i; }// end function void main() { char ch =' '; int x = 0; int n = 0 ; int match = 0 ; int j = 0 ; int flag = 1 ; printf("Enter q to quit or r to run \n\n"); while(flag ==1){ ch = getchar(); // get user input if(ch == 'r') { printf(" Enter a value for x please followed by enter\n ") ; // prompt the user for input scanf ("%d",&n); printf("Enter a value for n please in the range of 0 to 5 followed by return\n"); scanf ("%d",&x); // get user input match = find(Array,n,x); // simply return our value here printf("\n Array contents were \n"); for( j = 0 ; j < 5 ; j ++) { printf(" %d " ,Array[j]); } printf("\n\n q to quit or r to run\n\n"); } if (ch =='q') { flag = 0 ; } } // end while printf("\n User typed q \n **** Quitting program **** \n" ); }// end main method |
|
| Bookmarks |
| Tags |
| question, simple, syntax |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Parallel Wiring Very Simple Question | turzel09 | General Electronics Chat | 5 | 06-22-2009 07:30 PM |
| simple Thevinin question | Musab | Homework Help | 7 | 05-30-2009 08:48 PM |
| A simple question for confirmation | FND | General Electronics Chat | 11 | 04-03-2009 09:02 PM |
| A simple question about diodes. | farmosh203 | Homework Help | 5 | 01-29-2008 05:27 AM |
| Very simple question, voltage divider | Alvin | General Electronics Chat | 16 | 01-24-2008 05:10 PM |