| | |
C program for arrays
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
0
#12 Oct 29th, 2009
•
•
•
•
K here is what i've got. However the program immediatley termanates. Why? Also if you could take my program and edit it it would be heavily appreciated.
C Syntax (Toggle Plain Text)
void displayArray(int nArray[]) { int b; printf("%d",nArray[b]); }
Why would you want b for? And by the way it isn't initialized so you'll print random memory stuff there.
Anyways I strongly recommend you to throw all that code away, even if it's working, and write us a pseudocode of how you want your program to run, and we will work by there. If you don't know what pseudocode is try google it. Now is the best point to start for you in my opinion.
Seriously.
Last edited by neithan; Oct 29th, 2009 at 9:04 pm.
•
•
Join Date: Oct 2009
Posts: 23
Reputation:
Solved Threads: 0
0
#13 Oct 29th, 2009
•
•
•
•
Your code looks kind of crazy. I don't understand any of this, why would you need 6 variables just to create a simple array with that serie? I don't get it.
C Syntax (Toggle Plain Text)
void displayArray(int nArray[]) { int b; printf("%d",nArray[b]); }
Why would you want b for? And by the way it isn't initialized so you'll print random memory stuff there.
Anyways I strongly recommend you to throw all that code away, even if it's working, and write us a pseudocode of how you want your program to run, and we will work by there. If you don't know what pseudocode is try google it. Now is the best point to start for you in my opinion.
Seriously.
here i indented the program. Here is it reposted
C Syntax (Toggle Plain Text)
# include <stdio.h> # include "simpio.h" # include "genlib.h" # include "strlib.h" # define maxElements 500 void displayArray(int nArray[]) { int b; printf("%d",nArray[b]); } int main() { int a,b,c,d,e,f,g; int nArray[b]; printf("what is the max amount of 2's you want?"); a=GetInteger(); b=0; c=a; d=2; while(c!=0) { e=a; while(e!=0) { d=d*2; e=e-1; } if(e==0) { d=1; a=a-1; nArray[b]=d; displayArray(nArray); b=b+1; c=c-1; break; } else a=a-1; nArray[b]=d; displayArray(nArray); b=b+1; c=c-1; } getchar(); }
•
•
Join Date: Oct 2009
Posts: 23
Reputation:
Solved Threads: 0
0
#14 Oct 29th, 2009
HOw come this always terminates? Plz help and write out the problem and post the code that fixes it.
C Syntax (Toggle Plain Text)
# include <stdio.h> # include "simpio.h" # include "genlib.h" # define SIZE 500 void displayArray(int nArray[]) { int f; printf("%d ",nArray[f]); } main() { int a,b,c,d,e,f,g,h; int nArray[SIZE]; printf("what is the max amount of 2's you want?"); a=GetInteger(); b=a; c=a; e=0; f=0; h=1; for(d=0;d<=c;d++) { if(e==0) { d=1; nArray[f]=d; displayArray(nArray); f=f+1; } else g=f; while(g!=0) { h=2*h; g=g-1; } nArray[f]=d; displayArray(nArray); } getchar(); }
•
•
Join Date: Oct 2009
Posts: 23
Reputation:
Solved Threads: 0
0
#15 Oct 29th, 2009
alright i totally revamped it, but it still immidiatly terminates. Why. Help fix please
C Syntax (Toggle Plain Text)
# include <stdio.h> # include "simpio.h" # include "genlib.h" # define SIZE 500 void displayArray(int nArray[]) { int arraynum; printf("%d ",nArray[arraynum]); } main() { int amount,count,num1,num2,result,arraynum; int nArray[arraynum]; amount=GetInteger(); count=amount; num1=count; num2=num1; result=1; arraynum=0; while(num2!=0) { while(num1!=0) { result=result*2; num1=num1-1; } displayArray(nArray); arraynum=arraynum+1; num2=num2-1; } getchar(); }
0
#16 Oct 30th, 2009
•
•
•
•
alright i totally revamped it, but it still immidiatly terminates. Why. Help fix please
C Syntax (Toggle Plain Text)
# include <stdio.h> # include "simpio.h" # include "genlib.h" # define SIZE 500 void displayArray(int nArray[]) { int arraynum; printf("%d ",nArray[arraynum]); } main() { int amount,count,num1,num2,result,arraynum; int nArray[arraynum]; amount=GetInteger(); count=amount; num1=count; num2=num1; result=1; arraynum=0; while(num2!=0) { while(num1!=0) { result=result*2; num1=num1-1; } displayArray(nArray); arraynum=arraynum+1; num2=num2-1; } getchar(); }
Ok, you didn't pay attention to my first post trying to help you, so just answer this one.
Do you want us to fix your code or do you want to learn how to fix it by yourself?
Last edited by neithan; Oct 30th, 2009 at 6:49 am.
![]() |
Similar Threads
- Need Help with functions program (C++)
- Using functions and arrays to create a program for grades (C++)
- Please help me with arrays (C++)
- pls i need help in this simple program of arrays... (C)
- Program for tollbooth simulation needed (C++)
- Arrays (C++)
Other Threads in the C Forum
- Previous Thread: Problem with Structs
- Next Thread: Merge and Heap sort
Views: 574 | Replies: 15
| Thread Tools | Search this Thread |
Tag cloud for C
adobe ansi api array arrays bash binarysearch centimeter char character convert copyanyfile copypdffile createcopyoffile createprocess() csyntax directory drawing dynamic executable feet fflush file floatingpointvalidation fork frequency getlasterror getlogicaldrivestrin givemetehcodez global graphics gtkgcurlcompiling hardware highest homework i/o ide infiniteloop initialization interest intmain() kilometer lazy license linked linkedlist linux linuxsegmentationfault list match matrix meter microsoft multi mysql oddnumber odf open openwebfoundation pattern pause pdf pointer pointers posix power program programming pyramidusingturboccodes read recursion recv recvblocked repetition scheduling segmentationfault send shape single socketprogramming spoonfeeding stack standard strchr string strings structures student suggestions system test testautomation unix urboc user visualstudio voidmain() win32 win32api windows.h






