| | |
C program for arrays
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Oct 2009
Posts: 23
Reputation:
Solved Threads: 0
hi im trying to write a C program that produces an array like this
1,2,4,8,16...
Basically i produce an array with with the power of 2 starting at 0 and going up to n. Here is my current code: However the array dosent show. What is the problem?
# include <stdio.h>
# include "simpio.h"
# include "genlib.h"
# include "strlib.h"
# define maxElements 500
main()
{
int a,b,c,d,e,f,g;
int nArray[maxElements];
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;
printf("yo");
}
if(e==0)
{
d=1;
a=a-1;
nArray[b]=d;
b=b+1;
c=c-1;
break;
}
else
a=a-1;
nArray[b]=d;
b=b+1;
c=c-1;
}
getchar();
}
1,2,4,8,16...
Basically i produce an array with with the power of 2 starting at 0 and going up to n. Here is my current code: However the array dosent show. What is the problem?
# include <stdio.h>
# include "simpio.h"
# include "genlib.h"
# include "strlib.h"
# define maxElements 500
main()
{
int a,b,c,d,e,f,g;
int nArray[maxElements];
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;
printf("yo");
}
if(e==0)
{
d=1;
a=a-1;
nArray[b]=d;
b=b+1;
c=c-1;
break;
}
else
a=a-1;
nArray[b]=d;
b=b+1;
c=c-1;
}
getchar();
}
0
#6 Oct 28th, 2009
The array isnt being output because you dont include that line in your program. You have to print the array when your done filling it.
To use code tags click the code button above the box in which you type your reply.
To use code tags click the code button above the box in which you type your reply.
Last edited by Grn Xtrm; Oct 28th, 2009 at 6:35 pm.
Check out my new band URL on facebook. I'm the bass player. :) Become a fan and leave comments if you like.
URL on facebook!
URL on facebook!
-7
#9 Oct 28th, 2009
something like this:
C Syntax (Toggle Plain Text)
int array[10]; int i; for(i = 0; i < 10; i++) { printf("%d\n", array[i]); }
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Oct 2009
Posts: 23
Reputation:
Solved Threads: 0
0
#10 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)
# 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]); } 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(); }
![]() |
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
| Thread Tools | Search this Thread |
#include adobe ansi api array arrays asterisks binarysearch calculate centimeter changingto char convert copyimagefile cprogramme creafecopyofanytypeoffileinc csyntax database directory dynamic fflush file fork forloop framework frequency getlasterror givemetehcodez grade graphics gtkgcurlcompiling hacking hardware highest histogram inches include incrementoperators input iso kernel km linked linkedlist linux linuxsegmentationfault list lists locate logical_drives looping loopinsideloop. lowest match matrix microsoft motherboard multi mysql number opendocumentformat opensource owf pattern pdf performance pointer posix probleminc process program programming radix recursion recv repetition research reversing scanf scripting segmentationfault sequential shape socket socketprograming stack standard string strings systemcall testing threads turboc unix user variable voidmain() wab windows.h windowsapi






