Monday, May 24, 2010

Write a c program to multiply a 50 digit number with a 4 digit number using array?

sounds like you need to go back to MS DOS. representing a mathematical calculation like that in integer format will take up the whole screen. Otherwise start using powers and forget the writing of the program: use a calculator.

Write a c program to multiply a 50 digit number with a 4 digit number using array?
I am not in the habit of actually writing out solutions to what appears like homework, something like this isn't too hard. A couple arrays, a few loops and you can do it quite easily. Experiment.
Reply:Just do it in Python!


Using C++ what is the easiest way to write a recursive function to sort an array in ascending order?

I just googled for it and there's a recursive merge sort here.





void mergeSort(int numbers[], int temp[], int array_size)


{


m_sort(numbers, temp, 0, array_size - 1);


}








void m_sort(int numbers[], int temp[], int left, int right)


{


int mid;





if (right %26gt; left)


{


mid = (right + left) / 2;


m_sort(numbers, temp, left, mid);


m_sort(numbers, temp, mid+1, right);





merge(numbers, temp, left, mid+1, right);


}


}





void merge(int numbers[], int temp[], int left, int mid, int right)


{


int i, left_end, num_elements, tmp_pos;





left_end = mid - 1;


tmp_pos = left;


num_elements = right - left + 1;





while ((left %26lt;= left_end) %26amp;%26amp; (mid %26lt;= right))


{


if (numbers[left] %26lt;= numbers[mid])


{


temp[tmp_pos] = numbers[left];


tmp_pos = tmp_pos + 1;


left = left +1;


}


else


{


temp[tmp_pos] = numbers[mid];


tmp_pos = tmp_pos + 1;


mid = mid + 1;


}


}





while (left %26lt;= left_end)


{


temp[tmp_pos] = numbers[left];


left = left + 1;


tmp_pos = tmp_pos + 1;


}


while (mid %26lt;= right)


{


temp[tmp_pos] = numbers[mid];


mid = mid + 1;


tmp_pos = tmp_pos + 1;


}





for (i=0; i %26lt;= num_elements; i++)


{


numbers[right] = temp[right];


right = right - 1;


}


}

Using C++ what is the easiest way to write a recursive function to sort an array in ascending order?
1+1=2 Gitt it!!!???


How can I write a c_language program for finding the sum of second diameter of the array[4][3]???please help?

I have problem understanding your question. So if you have any problem with the program mail me at m_gopi_m@yahoo.co.in





/*


sum of elements in an array.


*/





#include%26lt;stdio.h%26gt;


#include%26lt;conio.h%26gt;





void main()


{


int i,j,sum[4];


int array[4][3]={


{1,1,1},{2,2,2},


{3,3,3},{4,4,4}


};


clrscr();


printf("\n\n Sum of the second dimension of the array is,\n");





for(i=0;i%26lt;4;i++)


{


printf("\n\n Dimension: %d",i+1);


printf("\n Elements:");





sum[i]=0;


for(j=0;j%26lt;3;j++)


{


sum[i]+=array[i][j];


printf(" %d",array[i][j]);


}


printf("\n Sum of elements: %d",sum[i]);


}


getch();


}

How can I write a c_language program for finding the sum of second diameter of the array[4][3]???please help?
mmaa try this link





http://www.google.co.uk/search?hl=en%26amp;q=H...


C++ program using an input file how do I place that information into an array?

The input file contains one column that is a string type and the other column that is a double type. I need to calculate the highest, the mid, and lowest value.

C++ program using an input file how do I place that information into an array?
Why do not you consult a C++ expert? Check http://k.aplis.net/

wedding florist

In turbo c... write a program that will search for the smallest value in an array of integers of length 10?

pls help asap. ty..

In turbo c... write a program that will search for the smallest value in an array of integers of length 10?
simple


void main()


{


int num[10];


int i,small=0;


//code input here


for(i=0;i%26lt;10;i++)


{


if(small%26gt;num[i])


small=num[i];


}


//output


printf("%d\n",small);


}
Reply:#include%26lt;conio.h%26gt;


#include%26lt;stdio.h%26gt;


void main()


{


int a[10],min,i;


printf("Enter 10 values:\n");


scanf("%d",%26amp;a[0]);


min=a[0]; // to make program applicable in all situation.


/*if we consider min=0 it is not applicable in negative and numbers hibher than zero. try this and u will find that i m right. */


for( i = 1;i%26lt;10;i++)


{


scanf("%d",%26amp;a[i]);


if(a[i]%26lt;min)


min=a[i];


}


printf("Minimum of ten numbers is:%d",min);


getch();


}


hope it helps.


bye.
Reply:#include %26lt;stdio.h%26gt;





int main()


{





int array[10] = {10, 52, 61, 1, 17, 31, 100, 84, 99, 63};


int smallest=0xffff, i;





//For turbo c (integer is 2 bytes) maximum value of int is 0xffff





for(i=0;i%26lt;10;i++) if(array[i]%26lt;smallest) smallest=array[i];





printf("Smallest = %d\n", smallest);





return 0;


}


If possibe how to "declare" an array using stack(assuming stack is a basic data type in 'c' language)

Hi !!your question is as absurd as asking me to declare a float in terms of a char.


Both array and stack are two different facets. yes, you can achieve the functionality of either using the other but to declare, just beats my mind.


More ppl could help you if you try to be a trifle more clear...!!!





Sorry ~Neo~

If possibe how to "declare" an array using stack(assuming stack is a basic data type in 'c' language)
i could google this and give you the answer, but i am lazy and you can do this yourself. google is great for these types of questions
Reply:Same syntax as any other data type I assume.





stack mystack[10];


A program in c language to find all positions of a number in a sorted array?

heres the code


the method is linear search and the values of n and the array elements are taken as input from the user ina separt functn. I can always help if u want the entire prog.


specify the array length.


complete the prog before complin.








# include%26lt;iostream.h%26gt;


# include%26lt;conio.h%26gt;


void main()


{int A[], data, n,ch=0,i;





while((i%26lt;n)%26amp;%26amp;(ch==0))


{if (data==A[i])


ch++;


else i++;


}


if (ch)


cout%26lt;%26lt;"position of the element is"%26lt;%26lt;(i+1);


else


cout%26lt;%26lt;"data not present"%26lt;%26lt;endl;





getch();


}


I need to know how to make a destructor in c++ in which the variables are stored in a character array.?

1) If the array is just a regular "Static" character array, then you can't delete it or "destroy" it because it's not dynamic and does not exist on the heap.





ex. char array[100];








2) If the array is a dynamic character array, then you delete it as follows:





char* array = new char[100];


delete [ ] array;





3) If the array is a dynamic pointer-to-character array (a dynamic array whose elements are not character but pointers to characters), then you you delete is as follows:





char** array = new char[100];


for(int i =0; i %26lt; 100; i++)


{


delete array[i];


}


delete [ ] array;

local florist

How the data in list-array that saved in memory when I use data structure by c++ languege whit not pointer?I n

If you mean STL list, (can you be more specific of what type of list?)





then you can prob. do something like





for(int i = 0; i %26lt; mylist.size(); i++)


{


cout%26lt;%26lt;mylist[i]%26lt;%26lt;endl;


}


C programming wrote a prog to find out max and min between integer array?

//


// Inputs:user


//


// Returns:Min, Max, Low to High Sort,


// High to Low Sort, Splitted array


//








#include %26lt;iostream%26gt;


#include %26lt;algorithm%26gt; // for C++ sort function


using namespace std;


const int SIZE = 10000;


void GetInputArray (int%26amp; userSize, int originalArray []); //Gets input array from user


void FindMinMax (int userSize, int%26amp; min, int%26amp; max, int originalArray []); //Determines min and max


void Sort (int userSize, int originalArray [], int lowSortedArray [], int highSortedArray []); //Sorts the arrays (H to L and L to H)


void SplitArrayProcessing (int userSize, int originalArray [], int lowSplitArray [], int highSplitArray []); //splits the array in half


int main ()








{


int originalArrayMain [SIZE];


int lowSortedArrayMain [SIZE];


int highSortedArrayMain [SIZE];


int lowSplitArrayMain [SIZE];


int highSplitArrayMain [SIZE];


int userSizeMain;


int minimum, maximum;





GetInputArray (userSizeMain, originalArrayMain);





if (userSizeMain %26gt; 0)








{


FindMinMax (userSizeMain, minimum, maximum, originalArrayMain);


Sort (userSizeMain, originalArrayMain, lowSortedArrayMain, highSortedArrayMain);


SplitArrayProcessing (userSizeMain, originalArrayMain, lowSplitArrayMain, highSplitArrayMain);





//outputs


cout %26lt;%26lt; "Min: " %26lt;%26lt; minimum %26lt;%26lt; endl; //minimum number in array


cout %26lt;%26lt; "Max: " %26lt;%26lt; maximum %26lt;%26lt; endl; //maximum number in array





cout %26lt;%26lt; "Low to High Sort: "; //low to high sorted array


for (int i = 0; i %26lt;= userSizeMain - 1; i++)








{


cout %26lt;%26lt; lowSortedArrayMain [i] %26lt;%26lt; " ";


}





cout %26lt;%26lt; endl %26lt;%26lt; "High to Low Sort: "; //high to low sorted array


for (int i = 0; i %26lt;= userSizeMain - 1; i++)








{


cout %26lt;%26lt; highSortedArrayMain [i] %26lt;%26lt; " ";


}


cout %26lt;%26lt; endl;


}


cout %26lt;%26lt; "First half split of array: "; //first half split of array


for (int i = 0; i %26lt;= ((userSizeMain/2) - 1); i++)








{


cout %26lt;%26lt; lowSplitArrayMain [i] %26lt;%26lt; " ";





}


cout %26lt;%26lt; endl;


cout %26lt;%26lt; "Second half split of array: "; // second half split of array


for (int i = 0; i %26lt; ((userSizeMain+1)/2); i++)








{


cout %26lt;%26lt; highSplitArrayMain [i] %26lt;%26lt; " ";


}


cout %26lt;%26lt; endl %26lt;%26lt; endl;


cout %26lt;%26lt; endl;


system("pause");


return 0;


};





void GetInputArray (int%26amp; userSize, int originalArray []) //Gets input array from user








{


cout %26lt;%26lt; "How many integers do you want to put into the array?: " %26lt;%26lt; endl;


cin %26gt;%26gt; userSize;


cout %26lt;%26lt; endl;





if (userSize %26gt; 0)








{


cout %26lt;%26lt; "Enter " %26lt;%26lt; userSize %26lt;%26lt; " integer(s) into the array (e.g. 5 88 4 etc):" %26lt;%26lt; endl;


for (int i = 0; i %26lt;= userSize - 1; i++)








{


cin %26gt;%26gt; originalArray [i];


}


cout %26lt;%26lt; endl;


}


else





{


cout %26lt;%26lt; "Invalid Entry!" %26lt;%26lt; endl;


}


}





void FindMinMax (int userSize, int%26amp; min, int%26amp; max, int originalArray [])








{


//find the mimimum number in the array


min = originalArray [0];


for (int i = 0; i %26lt;= userSize - 1; i++)








{


if (originalArray [i] %26lt;= min)








{


min = originalArray [i];


}


}


//find the maximum number in the array


max = originalArray [0];


for (int i = 0; i %26lt;= userSize - 1; i++)








{


if (originalArray [i] %26gt;= max)








{


max = originalArray [i];


}


}


}





void Sort (int userSize, int originalArray [], int lowSortedArray [], int highSortedArray [])








{


int j = (userSize - 1);





//copy contents of originalArray into lowSortedArray


for (int i = 0; i %26lt;= userSize - 1; i++)








{


lowSortedArray [i] = originalArray [i];


}





//sorts the lowSortedArray from low to high


sort (lowSortedArray, lowSortedArray + userSize);


//reverse copies the lowSortedArray to the highSortedArray (high to low sorted array)


for (int i = 0; i %26lt;= userSize - 1; i++)


{


if (j %26gt;= 0)








{


highSortedArray [j] = lowSortedArray [i];


j--;


}


}


}





void SplitArrayProcessing (int userSize, int originalArray [], int lowSplitArray [], int highSplitArray [])








{


int j = 0;


//splits the array in half


for (int i = 0; i %26lt;= userSize - 1; i++)








{


if (i %26lt; (userSize/2))








{


lowSplitArray [i] = originalArray [i];


}


else





{


highSplitArray [j] = originalArray [i];


j++;


}


}


}

C programming wrote a prog to find out max and min between integer array?
#include%26lt;stdio.h%26gt;


#include%26lt;conio.h%26gt;





#define n 10;





int n[10];





void main()


{


int i;


//to store the maximum and minimum numbers


int max,min;


(for i=0;i%26lt;n;i++)


{


//sorry, i cannot remember the printf scanf commands. ope u know them !!!


printf("Enter the"%d"th value",i);


scanf a[i];


}


//assigning the max and min to the 1st pos.of the array.


max=a[0];


min=a[1];


(for i=0;i%26lt;n;i++)


{


if(a[i]%26gt;max)


{


max=a[i];


}





if(a[i]%26lt;min)


{


min=a[i];


}


}





printf("The max is %d",max);


printf("Min is %d",min);





getch();





}





//sorry the printf scanf command may be wrong in syntax. please refer them.





//but the logic is the BEST!!!








GOOD LUCK!!!!!


Write a C program to implement a stack and a queue in a single array?

/* Program implements array as a stack. */





#include %26lt;stdio.h%26gt;


#include %26lt;conio.h%26gt;





#define MAX 10





struct stack


{


int arr[MAX] ;


int top ;


} ;





void initstack ( struct stack * ) ;


void push ( struct stack *, int item ) ;


int pop ( struct stack * ) ;





void main( )


{


struct stack s ;


int i ;





clrscr( ) ;





initstack ( %26amp;s ) ;





push ( %26amp;s, 11 ) ;


push ( %26amp;s, 23 ) ;


push ( %26amp;s, -8 ) ;


push ( %26amp;s, 16 ) ;


push ( %26amp;s, 27 ) ;


push ( %26amp;s, 14 ) ;


push ( %26amp;s, 20 ) ;


push ( %26amp;s, 39 ) ;


push ( %26amp;s, 2 ) ;


push ( %26amp;s, 15 ) ;


push ( %26amp;s, 7 ) ;





i = pop ( %26amp;s ) ;


printf ( "\n\nItem popped: %d", i ) ;





i = pop ( %26amp;s ) ;


printf ( "\nItem popped: %d", i ) ;





i = pop ( %26amp;s ) ;


printf ( "\nItem popped: %d", i ) ;





i = pop ( %26amp;s ) ;


printf ( "\nItem popped: %d", i ) ;





i = pop ( %26amp;s ) ;


printf ( "\nItem popped: %d", i ) ;





getch( ) ;


}





/* intializes the stack */


void initstack ( struct stack *s )


{


s -%26gt; top = -1 ;


}





/* adds an element to the stack */


void push ( struct stack *s, int item )


{


if ( s -%26gt; top == MAX - 1 )


{


printf ( "\nStack is full." ) ;


return ;


}


s -%26gt; top++ ;


s -%26gt; arr[s -%26gt;top] = item ;


}





/* removes an element from the stack */


int pop ( struct stack *s )


{


int data ;


if ( s -%26gt; top == -1 )


{


printf ( "\nStack is empty." ) ;


return NULL ;


}


data = s -%26gt; arr[s -%26gt; top] ;


s -%26gt; top-- ;


return data ;


}





______________________________________...





/* Program that implements queue as an array. */





#include %26lt;stdio.h%26gt;


#include %26lt;conio.h%26gt;





#define MAX 10





void addq ( int *, int, int *, int * ) ;


int delq ( int *, int *, int * ) ;





void main( )


{


int arr[MAX] ;


int front = -1, rear = -1, i ;





clrscr( ) ;





addq ( arr, 23, %26amp;front, %26amp;rear ) ;


addq ( arr, 9, %26amp;front, %26amp;rear ) ;


addq ( arr, 11, %26amp;front, %26amp;rear ) ;


addq ( arr, -10, %26amp;front, %26amp;rear ) ;


addq ( arr, 25, %26amp;front, %26amp;rear ) ;


addq ( arr, 16, %26amp;front, %26amp;rear ) ;


addq ( arr, 17, %26amp;front, %26amp;rear ) ;


addq ( arr, 22, %26amp;front, %26amp;rear ) ;


addq ( arr, 19, %26amp;front, %26amp;rear ) ;


addq ( arr, 30, %26amp;front, %26amp;rear ) ;


addq ( arr, 32, %26amp;front, %26amp;rear ) ;





i = delq ( arr, %26amp;front, %26amp;rear ) ;


printf ( "\nItem deleted: %d", i ) ;





i = delq ( arr, %26amp;front, %26amp;rear ) ;


printf ( "\nItem deleted: %d", i ) ;





i = delq ( arr, %26amp;front, %26amp;rear ) ;


printf ( "\nItem deleted: %d", i ) ;





getch( ) ;


}





/* adds an element to the queue */


void addq ( int *arr, int item, int *pfront, int *prear )


{


if ( *prear == MAX - 1 )


{


printf ( "\nQueue is full." ) ;


return ;


}





( *prear )++ ;


arr[*prear] = item ;





if ( *pfront == -1 )


*pfront = 0 ;


}





/* removes an element from the queue */


int delq ( int *arr, int *pfront, int *prear )


{


int data ;





if ( *pfront == -1 )


{


printf ( "\nQueue is Empty." ) ;


return NULL ;


}





data = arr[*pfront] ;


arr[*pfront] = 0 ;


if ( *pfront == *prear )


*pfront = *prear = -1 ;


else


( *pfront )++ ;





return data ;


}


Whow to create a c program which would accept 10 integers and store in an array?

Here is a simple implementation. It reads from command line arguments and does no error checking on its input...





void usage(int exitcode) {


printf("Usage:\n");


printf("./progname int1 int2 int3 ... int10\n\n");


exit(exitcode);


}





int main(int argc, char ** argv) {


int count = 0;


int * num = NULL;


if (argc != 11) usage(1);


num = malloc(10 * sizeof(int));


if (num == NULL) return 1;


for (count = 1; count %26lt;= 10; count++) {


num[count - 1] = atoi(argv[count]);


}





for (count = 0; count %26lt; 10; count++) {


printf("Integer at pos %d is %d\n", count + 1, num[count]);


}





free(num);


exit(0);


}

floral deliveries

C program for finding the largest number among the 'n' number of array. can any1 answer for this? pls soon

the program should be simple by using simple functions

C program for finding the largest number among the 'n' number of array. can any1 answer for this? pls soon
a[n]


large=a[0]


for(i=1;i%26lt;n;n++)


{


if(large%26lt;a[i])


{


large=a[i]


}


}


printf("largest no. is %d",large)


getrch()
Reply:but here is some error Report It

Reply:Use an If / else statement.


Question for C programming. [Find the average of the elements in the stuff array?]?

// Something like this, you may choose float instead of int


int average=0;


int count=20; // or however many elements in the stuff array


for (int i=0;i%26lt;count;i++)


average+=stuff[i];


average/=count;


Wat code/s in an array should i use to determine the lowest number in C?

sort.list





if min%26gt;1 then go to GO SUB





try this, good luck

Wat code/s in an array should i use to determine the lowest number in C?
#include%26lt;stdio.h%26gt;


#include%26lt;conio.h%26gt;


main()


{


int i,n,min;


int a[10];


clrscr();


printf("Enter the size of array = ");


scanf("%d",%26amp;n);


printf("Enter the elements of Array = ");


for(i=0;i%26lt;n;i++)


{


scanf("%d",%26amp;a[i]);


}





/* TO FIND THE LARGEST VALUE WITHIN AN ARRAY*/


min=a[0];


for(i=0;i%26lt;n;i++)


{


if(a[i] %26gt; min)


min=a[i];


}


printf(" Lowest value within an array = %d\n",min);


getch();


}


Write a C++(or JAVA) program for entering values in a 2-dimensional array as follows?

1--%26gt;2--%26gt;3


8--%26gt;9 4


7%26lt;--6%26lt;--5

Write a C++(or JAVA) program for entering values in a 2-dimensional array as follows?
int main() {


int m[4][4];





printf("\n Enter the values of the first row : ");


for(int j=1;j%26lt;=3;j++)


scanf("%d ",%26amp;m[1][j]) ;





printf("\n m[2][1]=");


scanf("%d",%26amp;m[2][1]);





printf("\n m[2][2]=");


scanf("%d",%26amp;m[2][2]);





printf("\n m[2][3]=");


scanf("%d",%26amp;m[2][3]);





printf("\n Enter the values of the third row : ");





for(int j=3; j%26gt;0; j--)


scanf("%d ",%26amp;m[3][j]) ;


return 0;


}











P.S: rewrite it using the first zero index

buy flowers

Write a c program to display ur name, without using semi colon,quotes, array?

is it possible to do. if so write the program for me

Write a c program to display ur name, without using semi colon,quotes, array?
Sounds like you want us to do your home work. So I will not give you a program that will do it. But if I was doing it I would try using a while loop





something like:





while( printf( (char)65 + (char)66 ) { }





this is just a starting point you will have to work on it from here





UPDATE:


Ok people are still saying it can't be done so here is the code to do it.





#include %26lt;stdio.h%26gt;


void main( int arg, char *argv[] )


{


while( printf( argv[1] ) %26amp;%26amp; false ) { }


}





No semi colon, no quotes. And if need be I could do it with out a command line parameter. (I just dont feel like looking up the ascii codes)
Reply:first - you do need one semicolon, otherwise there's no way to do it.





second - figure out what each letter in your name is numerically. a quick way to find out - write a different program. a *very* basic version is the following:





---





main()


{


char name[4]="joe";


char i;





for(i=0;i%26lt;3;i++)


printf("%d ",name[i]);


}





---





let's assume you found out "joe" is 12 92 43. (which in reality it's not.) a very basic version of the program you could write is:





---





main()


{


cout %26lt;%26lt; (char)12,(char)92,(char)43;


}
Reply:No way, semi colons to C are like period points to English. Without ever using quotes in C is also impossible.
Reply:Not that I know of. The not using an array is the tricky part...a string (which would be neccisary to hold a name) needs to be an array of chars. I guess you could have a seperate variable for each letter. But then you're faced with actually calling some kind of output function which will need to be terminated with a semicolon. Sorry, I don't think it's possible, even using super god like macro power.
Reply:thier is no way at all, especially the semi colon


Using C++ how can I write a recursive function to sort an array?

Look up "quicksort".





It fits very naturally into a recursive implementation


and is also a very efficient sorting algorithm.





I've included a link to the Solaris source for quicksort.


It is written in C (rather than C++). It is somewhat


complicated because it optimizes the sorting of


short sequences by switching to an insertion sort.


However, you could implement a simpler version which


ran quicksort all the way to completion.

Using C++ how can I write a recursive function to sort an array?
You're a glutton for punishment eh? Heh-heh. Seriously, you can use a recursive binary search to sort your array.





Here is some code I just snagged from the web (source to follow) concerning a recursive binary search:





/* Given: IntArray Array of integers.


Low The low index of the range of integers to search.


High The top index of the range of integers to search.


Target The integer for which to search.


Task: To do a recursive binary search for Target in the specified


range of IntArray.


Return: In the function name, return the index of where Target was


found or -1 if it was not found.


*/


int BinarySearch(IntArrayType IntArray, int Low, int High, int Target)


{


int Mid, Difference;





if (Low %26gt; High)


return -1;


else


{


Mid = (Low + High) / 2;


Difference = IntArray[Mid] - Target;





if (Difference == 0) // IntArray[Mid] == Target


return Mid;


else if (Difference %26lt; 0) // IntArray[Mid] %26lt; Target


return BinarySearch(IntArray, Mid + 1, High, Target);


else


return BinarySearch(IntArray, Low, Mid - 1, Target);


}


}


In C how do you extract the integer component of a char* array?

I am extracting argv from the input: main(int argc, char* argv[])


one of my inputs is an integer that I need to be an integer for a function. How do I use argv[2] as an int instead of a char*. Currently the compiler cannot convert. =(

In C how do you extract the integer component of a char* array?
Argv[] contains the command-line arguments, all as strings. It's your job to convert the appropriate string to an integer, I'd suggest using atoi(). Be sure to handle error conditions, though, as when argv happens to be alphabetic.





Hope that helps.
Reply:My C is a bit rusty here.. but why couldn't you create a pointer for an integer and point it to the address of argv[2]. The compiler shouldn't complain about that.....





hope that helps.


How do I write a C program for 100 doors and 100 students using an array??

There are 100 doors (1-100) and 100 students (1-100). All the doors are closed. As a student numbered x goes to all the doors that are multiples of x and changes the status of the door (opens if closed and closes if opened), After all the students have completed their turns what are the door numbers that will be left open?

How do I write a C program for 100 doors and 100 students using an array??
You can make an array for the doors. Initial values are false.





//for loop that stops at 100 for students





//while (student times x multiple %26lt; 100)


// !element of the array


// x++;





//set x = 1 for the next loop iteration





// exit for loop and output array elements that are true
Reply:Hi there are lots of ways of doing this and Ive chosen an array of characters that is set to C=Closed or O=Open, as each Student tries to open all the doors.





A visual representation of the status of the doors can be printed and the O and C characters can be added up to tally the totals.





Good luck.





#define DOORS 100





// Define a char array of 100 DoorStatus values


// C = Door Closed


// 0 = Door Open


char DoorStatus[DOORS] = {0};





void main()


{


int DoorNum=0;


int StudentNum=0;


int DoorOpen=0;


int DoorClosed=0;





// Initialise the Door to Closed


for (DoorNum=0; DoorNum%26lt;DOORS; DoorNum++)


{


DoorStatus[DoorNum] = 'C';


}





// in the last element add a null char so we may print


// the char array as a string


DoorStatus[DOORS+1] = '\0';





// Outer loop: each student [1-100] gets a go at closing


// the doors they are allowed to


for (StudentNum=1; StudentNum%26lt;=100; StudentNum++)


{


// Inner loop: Each student tries all the doors and


// only the ones that are his multiples get changed


for (DoorNum=1; DoorNum%26lt;=DOORS; DoorNum++)


{


// Use mod to see if the Students number


// is a multiple of the Door number


if ((DoorNum % StudentNum) == 0)


{


// Students number is a multiple of the Door number


// change the Doors status from Closed to Open


// or Open to Closed


if (DoorStatus[DoorNum-1] == 'C')


{


DoorStatus[DoorNum-1] = 'O';


}


else


{


DoorStatus[DoorNum-1] = 'C';


}


}


}


// Compile this in if you want to see the status of the Doors


// after Student get a go on each Door


//printf("%s\n", DoorStatus);


}





// You now have an array that can be printed to see the


// status of all the doors


printf("\nVISUAL DOOR STATUS\n%s\n\n", DoorStatus);





// Loop again on the DoorStaus array and count the C


// and O characters resectively


for (DoorNum=0; DoorNum%26lt;DOORS; DoorNum++)


{


if (DoorStatus[DoorNum] == 'C')


{


DoorClosed++;


}


else if (DoorStatus[DoorNum] == 'O')


{


DoorOpen++;


}


}





printf("Doors: Open=%d, Closed=%d\n\n",


DoorOpen, DoorClosed);


}











Output should be as follows:





VISUAL DOOR STATUS


OCCOCCCCOCCCCCCOCCCCCCCCOCCCCCCCCCCOCC...





Doors: Open=10, Closed=90
Reply:This will print out an array of ones. You tell me why.


#include %26lt;stdio.h%26gt;





void change(int door[100], int place);





int main()


{


int students, i, doors[100];





students =1;


for (i=0;i%26lt;100;i+=1)


doors[i]=0;





for (i=0;i%26lt;100;i+=1)


{


if (students%(i+1)==0)


change(doors, i);


students+=1;


}


for (i=0;i%26lt;100;i+=1) printf("%d ", doors[i]);


return 0;


}





void change(int door[100], int place)


{


if (door[place]==1) door[place]=0;


else door[place]=1;


}

floral

Can i get a C program for finding greatest and smallest numbers among an array of numbers?

If you have an int array called A with a range of 100 (A[100]):





int i;





int Smallest;





int Largest;





Smallest=A[0];


Largest=A[0];











for (i = 0; i %26lt; 100; i++)


{


if A[i]%26gt;Largest


{


Largest=A[i];


}





if A[i]%26lt;Smallest


{


Smallest=A[i];


}





}





You should probably do your own homework, you know...Yahoo Answers won't be available when you're taking a test in the classroom!

Can i get a C program for finding greatest and smallest numbers among an array of numbers?
Yes you can get the C program.


In C (not C++), is it possible to implement a function that takes an array and returns one?

and how would you write the prototype? thanks.

In C (not C++), is it possible to implement a function that takes an array and returns one?
It's not possible in standard C to pass an array to a function by value, or to return an array from a function. When an array is used as an argument to a function, it's automatically converted to a pointer to the first element of the array.


Solving a problem for c++ Arrays?

I try using a value of a string for example string value[] to establish a condition in a loop, only it give me this error :(


"C++ forbids comparison between pointer and integer"


Can you establish a string inside a while loop and what conditions do you need?


string value[]





for ( )


while (value != '$')


{


code


}

Solving a problem for c++ Arrays?
The problem here is that





string value[]





declares an _array_ of strings. The code then tries to compare value (which is a pointer to an array of strings), to '$', which is a character (an 8-bit integer).





If you want to compare a string in the while loop, you need to compare a string to a string. For example:





while ( value[0] != "$" )





This will compare the string at index 0 of the value array, to the string "$". Note that double quotes is used to specify a string, whereas a single quote is used to specify a character.
Reply:No.
Reply:Quit = fasle;


while(true){


if(string =='fsdf')


{


//do this


}else


{


//do this


Quit = true;


}


}


if(Quit = true)


break;


}


In C++ how do you write a program to input an array and output the standard deviation?

Hi!


Find the folowing program:





#include %26lt;iostream%26gt;


#include %26lt;math.h%26gt;


using namespace std;


int main()


{


int number;


double* array;


int i;


double SD;


double PreSD = 0;


double total = 0;


double mean;


double SDbm;


int a;


cout%26lt;%26lt;"***Standard Deviation***";


cout%26lt;%26lt;endl;


cout%26lt;%26lt;"Enter number of values";


cout%26lt;%26lt;endl;


cin%26gt;%26gt;number;


cout%26lt;%26lt;endl;


array = new double[number];


cout%26lt;%26lt;endl;


cout%26lt;%26lt;"Enter values to calculate Standard Deviation";


cout%26lt;%26lt;endl;


for (int i = 0; i%26lt;number; i = i + 1)


{


cout%26lt;%26lt;i + 1 %26lt;%26lt; ". ";


cin%26gt;%26gt;array[i];


}


for (int i = 0; i%26lt;number; i = i + 1)


{


total = array[i]+total;


}


mean = total/number;


for (int i = 0; i%26lt;number; i = i + 1)


{


PreSD = pow ((array[i]-mean) , 2)+PreSD;


}


SDbm = (PreSD/(number-1));


SD = sqrt (SDbm);


cout%26lt;%26lt;endl;


cout%26lt;%26lt;"Standard Deviation = ";


cout%26lt;%26lt;SD;


cout%26lt;%26lt;endl;


cout%26lt;%26lt;"Mean = ";


cout%26lt;%26lt;mean;


cout%26lt;%26lt;endl;


cout%26lt;%26lt;endl;


system("PAUSE");


cout%26lt;%26lt;endl;


cout%26lt;%26lt;endl;


selection:


cout%26lt;%26lt;"Would you like to find another Standard Deviation?";


cout%26lt;%26lt;endl;


cout%26lt;%26lt;"(1) Yes";


cout%26lt;%26lt;endl;


cout%26lt;%26lt;"(2) No";


cout%26lt;%26lt;endl;


cin%26gt;%26gt;a;


switch(a)


{


case 1:


system("cls");


return main();


break;


case 2:


return 0;


break;


default:


system("cls");


goto selection;


break;


}


}

In C++ how do you write a program to input an array and output the standard deviation?
try above program




















http://www.jobsgala.com

daisy

C++ How do I remove the last element of an array?

What do you mean? Arrays are a constant size in C++ the same as C. So you can't really remove elements entirely from them, unless you create a new array that is one shorter and copy the values (skipping the last one) into it.





BTW- You should look at using std:vector if you want something that is more dynamic but acts a lot like an array. There's not many reason to use C style arrays in C++ because vectors are so much nicer.

C++ How do I remove the last element of an array?
Well, you have to consider what an array in c/c++ is.


When you code


int array[20];


What you basicly do is say to the compiler:


'Hey, I want to use 20 integer numbers set up one after another'


What you get is a pointer to the first element. You have to remember that this is static memory consumption thingie, and the memory can't be recovered untill the variable is out of range.





Were you to use this construct


int *array = new int[20];


You'd get 20 integers in a row in dynamic memory.


then you could do


int *array2= new int[19];


for(int i=0;i%26lt;19;i++) array2[i]=array[i];


delete(array);


array=array2;


This way your array's last element is gone, but you kinda have rewritten the array into another place..
Reply:An STL vector is a generic array, and much more powerful than a plain-old-data array. Removing the last element of a vector is easy. Here's an example:





#include %26lt;iostream%26gt;


#include %26lt;vector%26gt;





using namespace std;





const int VEC_LEN = 4;


void printVec(const vector%26lt;int%26gt;%26amp;);





int main(int argc, char *argv[]) {


vector%26lt;int%26gt; intVec;





// fill vector and print it


for (int i = 0; i %26lt; VEC_LEN; i++) {


intVec.push_back(i);


}


printVec(intVec);





// remove last element, and print


intVec.pop_back();


printVec(intVec);





return 0;


}





void printVec(const vector%26lt;int%26gt;%26amp; v) {


for (vector%26lt;int%26gt;::const_iterator iter = v.begin();


iter != v.end(); ++iter) {


cout %26lt;%26lt; *iter %26lt;%26lt; " ";


}


cout %26lt;%26lt; endl;


}





Program output:


0 1 2 3


0 1 2
Reply:U can't remove elements from any array but in linklist


C# question - Does the language provide any sort of expandable array?

I created my own class to do this, and it's working well enough, but I suspect that this is not really the "proper" way to do it.


I've done some Google searches for them, but you know what a pain it can be to wade through the various programming forums and whatnot that it links you to.

C# question - Does the language provide any sort of expandable array?
You should design in the bounds and limits. Otherwise, your program's array could grow to the maximum size and cause unwanted results.





Every program should be designed with limits, bounds and a user identifiable error condition and message. Otherwise, you will have CRAPPY software like that stuff that Microsoft sells.





Good luck and Happy Computing!
Reply:hey man if you found a way to make it work stick with it.if its not broke dont fix it.ok thats kind of cliche but i think that applies to this situation.
Reply:Look at the System.Collections.ArrayList - it is a collection class with a .ToArray() method. You can cast it to an array at the very last minute, after you've filled it with the items you want.





Using this method, you don't even have to think about the array depth or boundaries. The .ToArray() method takes care of all of it.
Reply:I'm not sure what you're asking, but you can always declare a dynamic array and expand it as needed:





int[] myarray = new int[];


Anybody good w/ C++ arrays? I can't a little bit of code to work.?

You are given two int variables j and k , an int array zipcodeList that has been declared and initialized, an int variable nZips that contains the number of elements in zipcodeList , and a bool variable duplicates .








Write some code that assigns true to duplicates if any two elements in the array have the same value, and that assigns false to duplicates otherwise.





Use only j , k , zipcodeList , nZips , and duplicates .


__________________________________


Ok so that is the question and here is the code I typed... It doesn't work














for(j=0;j%26lt;nZips;j++)


{


for(k=1;k%26lt;nZips;k++)


{


if(zipcodeList[j]==zipcodeList[k])


duplicates=true;


}


}


if(duplicates!=true)


duplicates=false;

Anybody good w/ C++ arrays? I can't a little bit of code to work.?
// Assume that there are no duplicates


duplicates=false;





for(j=0;j%26lt;(nZips - 1) %26amp;%26amp; !duplicates;j++)


{


for(k=j + 1;k%26lt;nZips %26amp;%26amp; !duplicates;k++)


{


if(zipcodeList[j]==zipcodeList[k])


{


duplicates=true;


}


}


}





Edited the array initializers
Reply:do we have to do your frigging homework for you?


Questions again on c++ arraying?

question for example,





if a question asked me...do you wish to add a person to your house hold? (the house hold is the array in this case). House hold can hold a total of 10 people. If a question ask me if i want to add a person to my household, how do i write a for loop that will add that person to the first array [0] in the household? But after i added that person and i wanna add another person, how should i write a for loop that will also add the second person and store it in the household array [1] and if i want to add more people, and store them [2], [3], [4], respectively. Can you tell me how for loop works in this situation? and can u give me a example of how it should be like?

Questions again on c++ arraying?
Why dont you ask it in programming, they help a lot there, but im sorry i dont know any C++ or C as wel

gladiolus

C++, Arrays, Max/Min Values?

I've designed a program that asks the user to enter a certain number of temperature between 0 and 100, whatever the user wants. After that, the program finds the average, standard deviation and the maximum and minimum values. All that works. The problem is when I output the max/min values, I also need to output which reading number (box in the array) that the max/min value comes from. I cannot figure out how to tell the program to output that value, whatever it may be. To help you with this, I've included the part of the code that declares max/min values





float minTemp = temp[0];


for (i = 0; i %26lt; numTemps; i++)


{


if (minTemp %26gt; temp[i])


minTemp = temp[i];


}


cout %26lt;%26lt; "The Minimum Temperature is: " %26lt;%26lt; minTemp %26lt;%26lt; " in Reading # " %26lt;%26lt; WHAT DO I PUT HERE? %26lt;%26lt; "\n";





float maxTemp = temp[0];


for (i = 0; i %26lt; numTemps; i++)


{


if (maxTemp %26lt; temp[i])


maxTemp = temp[i];


}


cout %26lt;%26lt; "The Maximum Temperature is: " %26lt;%26lt; maxTemp %26lt;%26lt; " in Reading # " %26lt;%26lt; WHAT DO I PUT HERE? %26lt;%26lt; "\n";








return

C++, Arrays, Max/Min Values?
You just need another variable that saves the index in the array.





float minTemp = temp[0];


int index = 0;


for (i = 0; i %26lt; numTemps; i++)


{


if (minTemp %26gt; temp[i]) {


minTemp = temp[i];


index = i;


}


}


cout %26lt;%26lt; "The Minimum Temperature is: " %26lt;%26lt; minTemp %26lt;%26lt; " in Reading # " %26lt;%26lt; index %26lt;%26lt; "\n";





You would do the same for the other part.
Reply:try using java it works better than C++ and it shows your what is exactly wrong.


C++ Arrays Question?

What would be the most efficient way to take a user-inputted array of type int and figure out all the unique numbers in it and the number of occurences of each unique number?





{2,2,3,4,5,5} would be...





2-2


3-1


4-1


5-2

C++ Arrays Question?
I don't think a set will do it, don't they have to have unique contents?





Go with the hashtable, store the integers as the keys and the values as a count of their key.
Reply:i would suggest you use multiset from stl. suppose the integer array is already stored in "int arr[]", and the number of elements is "n". then, the following program should work:





#include %26lt;multiset%26gt;


using std::set;





...





multiset%26lt;int%26gt; myset;


int i;


for (i = 0; i %26lt; n; i ++)


myset.insert(arr[i]);


multiset%26lt;int%26gt;::iterator it;


for (it = myset.begin(); it != myset.end(); it = myset.upper_bound(*it)) {


printf("%d-%d\n", *it, myset.cound(*it));


}





For efficiency consideration, you can also use hashtable, and each burrow in the hashtable can be a multiset.


Is it possible to start numbering array cells from 1 instead of 0 in C++?

yes but it goes against convention so you need to make a note of it for others that may work on your program

Is it possible to start numbering array cells from 1 instead of 0 in C++?
The compiler will always generate internal represenations of arrays that are numbered from 0.





You can do weird tricks so your code reads as if the arrays were numbered from 1





- Ignore the zero element. In all array calculations/references you must ensure you never reference element 0


- Create an array access routine that decrements the index by 1, always use the array access routine to access arrays


- Get the source code for the Gnu C++ compiler and alter it so that all arrays are numbered by 1, and that any reference to array[0] is a fault. Compile it and post it online for everyone who wants natural numbers only.
Reply:You can use an associative array and start the keys at whatever value you wish. The trouble is you have to manage the incrementing of the keys as you add array elements.





See: http://en.wikipedia.org/wiki/Associative...
Reply:Thats a very intresting question, while I don't belive I can give you a answer that is 100% sure, because of my lack of experence in the real world, I would have to say somewhat. If you use a type of stack data structure where 0 would represent the element you are deleting and 1 as the element in which calculations are done then it would be possible. However I seriously doubt you could just start numbering arrays starting with 1 as the first index instead of 0 in any other case, because while you may not use the data in 0, unless you initaize that index there will always be something there, whatever was stored inside the memory address previously.





In any case, good luck!


Write a complete C++ program that will let a user input 8 integer values into an array.?

After entering the values display the following statistics: the third element in the array and the average of all the numbers.

Write a complete C++ program that will let a user input 8 integer values into an array.?
#include%26lt;iostream.h%26gt;


void main()


{


int a[8],i,sum=0;


float avg;


cout%26lt;%26lt;"Enter The 8 numbers :";


for(i=0;i%26lt;8;i++)


{


cin%26gt;%26gt;a[i];


sum+=a[i];


}


avg=sum/8;


cout%26lt;%26lt;"Third Element in the array"%26lt;%26lt;a[2];


cout%26lt;%26lt;"\nAverage of 8 numbers :"%26lt;%26lt;avg;


}
Reply:#input%26lt;stdio.h%26gt;





void main()


{


int i,a,iArr[10];





a= 0;


for(i=0;i%26lt;8;i++)


{ scanf("%d",%26amp;iArr[i]); a += iArr[i]; }





printf("\n\n\t The third number was %d and the average is ", iArr[2] a/8);


// c arrays are 0 based so third element will be index 2


}
Reply:if a[8] is the array u have defined. then follow the below





cout%26lt;%26lt;a[2]; ---- to display 3rd element





b=0;


for(i=0;i%26lt;8;i++)


b+=a[i]; ----- to find the sum of all the numbers in the array





cout%26lt;%26lt;b/8; ---- displays the average of the array





try this....


Write a C code to traverse a 2-dimensional array in spiral order?

http://www.openasthra.com/c-tidbits/prin...


[Pointers in C] What does this mean to an array of integers?

int a[10]={1,2,3,4,5,6,7,8,9};


int *p=a;


/* what does


p++


*p++


*(p++)


(*p)++


++*p


mean? */

[Pointers in C] What does this mean to an array of integers?
Arrays are the collection of similar Data Types(i.e elements) and pointers are those variables ehich holds the physical address of another variables.


Now you code


int *p=a holds the address of first element(correct would be int *p=%26amp;a)





p++ increments the address with 2 bytes because int type acquire 2 bytes in memory


*p++ means increase value at address P to 1








++*p incremtns (i.e postincrement value at address of a)
Reply:*p=a p will have the address of the variable a


p++ is post increment if we have a address as 1000 then the address will be incremented by 1 by post increment method.


*p++ will increment the value of the data present in the p


*(p++) first the value of p will be increment then address


(*p)++ this will increment the address of p value


++*p this will preincrement the p value


/* */ this is treated as multi line comment

floral deliveries

Program in C++ to create a 3 by 3 array and extract the maximum and the maximum alongwith the original matrix

i've made this prog but it is not printing the correct output. plzzz help


#include%26lt;iostream.h%26gt;


#include%26lt;conio.h%26gt;


void main()


{


clrscr();


int a[3][3],max,min;


cout%26lt;%26lt;"enter the matrix: ";


for(int i=0;i%26lt;3;i++)


{ for(int j=0;j%26lt;3;j++)


{ cin%26gt;%26gt;a[i][i]; }


}


max=a[0][0];


min=a[0][0];


for(i=0;i%26lt;3;i++)


{ for(int j=0;j%26lt;3;j++)


{ if(a[i][j]%26lt;min)


min=a[i][j];


if(a[i][j]%26gt;max)


max=a[i][j];


}


}


cout%26lt;%26lt;"the max character is: "%26lt;%26lt;max%26lt;%26lt;"\m"%26lt;%26lt;"the min character is: "%26lt;%26lt;min;


getch();


}

Program in C++ to create a 3 by 3 array and extract the maximum and the maximum alongwith the original matrix
the line


{cin %26gt;%26gt;a[i][i];}





should read


{cin %26gt;%26gt;a[i][j];}





In the part where you are entering the matrix. Otherwise you are just reading into the diagonals of the matrix and leaving the off-diagonals empty.
Reply:You need to print out the matrix, but I don't see that anywhere.





Within your two nested for loops, you need to add a cout statement (or two.) The first would be immediately after the second for and would be something like:





cout %26lt;%26lt; " " %26lt;%26lt; a[i][j];





the next would be between the two braces after the max= line and it would look like:


cout %26lt;%26lt; endl;





This prints the item in each matrix position while you're searching for the largest number.





Also, initialize max and min to 0, not a[0][0]





It looks like you're reading data into a[i][i]... that should be a[i][j], right?


I want to create a two dimensional array of integers based on the dimesions that the user provides in C++.?

I get an error from the compiler saying that the value (int array[#][#]) in the brackets must be a const. How can make the integer array based on the dimension the user provides? Statically and dynamically (with new int)

I want to create a two dimensional array of integers based on the dimesions that the user provides in C++.?
Dynamically with new int[value]. Statically, you need to know the values at compile time.





First, get your x and y values from the user.


Then:





int ** arr=new int*[y];


for(int i=0; i %26lt; y; i++)


{


arr[i]=new int[x];





}
Reply:When you create an array on the stack (int someArr[DIM_ONE][DIM_TWO]) the size must be known at compile time, which means the integers must be constant. This means that the only way you can create an array of variable size is to do so on the free store.





Hence you’ll have to do something like int *someArr = new int[dimOne][dimTwo]. Be careful with the pointer. Remember to free the memory up.





EDIT: My mistake. Yes, TreyJ is correct. You can't do [][], so you'll have to construct it by multiplying out the dimensions. See the FAQ entry for more details: http://www.parashift.com/c++-faq-lite/fr...
Reply:The compiler I'm using (Visual Studio's C++) doesn't support non-constant arrays, so the example given by the previous person doesn't work. I couldn't find a way to do it using [x][y], but I did find a way using a single-dimention array if you don't mind computing the offset manually. Here's my example for you that creates a 3 x 5 array of integers, fills it, and then displays the values:





#include %26lt;stdio.h%26gt;





void main()


{


int *a = NULL;


int Dim1, Dim2;


int i, j;





Dim1 = 3;


Dim2 = 5;





a = new int[Dim1*Dim2];





for ( i = 0; i %26lt; Dim1; i++ ) {


for ( j = 0; j %26lt; Dim2; j++ ) {


a[i*Dim2 + j] = (i+1) * (j+1);


}


}





for ( i = 0; i %26lt; Dim1; i++ ) {


for ( j = 0; j %26lt; Dim2; j++ ) {


printf( "Value at (%d,%d) which is %d*%d: %d\n", i, j, i+1, j+1, a[i*Dim2 + j] );


}


}


delete [] a;


a = NULL;


}





which gives the output:





Value at (0,0) which is 1*1: 1


Value at (0,1) which is 1*2: 2


Value at (0,2) which is 1*3: 3


Value at (0,3) which is 1*4: 4


Value at (0,4) which is 1*5: 5


Value at (1,0) which is 2*1: 2


Value at (1,1) which is 2*2: 4


Value at (1,2) which is 2*3: 6


Value at (1,3) which is 2*4: 8


Value at (1,4) which is 2*5: 10


Value at (2,0) which is 3*1: 3


Value at (2,1) which is 3*2: 6


Value at (2,2) which is 3*3: 9


Value at (2,3) which is 3*4: 12


Value at (2,4) which is 3*5: 15


C++: What's the easiest way to put the filenames of a directory in an array?

I'm using a Microsoft Visual Studio 2005 MFC application.





I would like go through a directory, reading file names. If the file name (not including extension, of course) is three letters long, I would like to put that filename into an array, and then move on to the next file to test whether it belongs in the array, until I've reached the end of the directory. What is the easiest way to do this? Should I use a CFileFind, or is there a more efficient method?





Specific examples would be appreciated. Also, please keep in mind that this is an MFC application: NOT a console application.





Thanks!

C++: What's the easiest way to put the filenames of a directory in an array?
Doesn't matter if console or not, you still can use console techniques, just need to modify to fit your instance.


for the cout, replace that with your array, I would recommend a dynamic array or better yet use a vector class so you don't have to worry about allocation





CFileFind finder;


BOOL bWorking = finder.FindFile("*.*");


while (bWorking)


{


bWorking = finder.FindNextFile();


cout %26lt;%26lt; (LPCTSTR) finder.GetFileName() %26lt;%26lt; endl;


}
Reply:Ugh...Truthfully, I'd recommend that you program Windows with the Windows API instead of using the stupid Microsoft MFC or Borland VCL frameworks because they both produce incredibly bloated, slow code. They also don't teach you how to really program the operating system since they are bloated, slow wrappers which EVENTUALLY calls the Windows API functions. Anyways...





The 1st thing that comes to mind is the size of your array. Normally, you would have to write code so that the allocated memory block or array for the file names is large enough for a good number of file names (this can waste memory), or you have to write code that will dynamically allocate another block of memory when your 1st buffer gets full. Something to keep in mind...





As far as getting the file names, do something like this:


1) Call CFileFind::FindNextFile(). Set a flag if it returns 0 (last file in directory).


http://msdn2.microsoft.com/en-us/library...





2) Call CFileFind::GetFileName().


http://msdn2.microsoft.com/en-us/library...





3) In a loop, read the file name and copy it to array/memory block if necessary.





4) If the flag wasn't set, go back to step 1.


In c#,,how to declare a structure of array,,and how to access them,,tnx?

http://msdn2.microsoft.com/en-us/library...

In c#,,how to declare a structure of array,,and how to access them,,tnx?
The code is something like :





int[ ] myInts = New int[5]





This would decalre and instantiate an array with 6 positions (arrays in C# are 0 based). To access elements, simply do





myInts[2] = 42 // assign value to 3rd pos


result = myInts[3] // assign value in4th position to variable





Here is a link to a great site for C# stuff :





http://www.c-sharpcorner.com/UploadFile/...





Good luck :)

buy flowers

How can I use pointers to transfer the contents of an array to another of the same size and type in C++?

I need to transfer the contents of a 20-item char array of one object to another, and I'd really like to avoid using for loops (I have to do this several thousand times). is there a way to set a pointer to the first array, and transfer its contents to the second?





Thanks!

How can I use pointers to transfer the contents of an array to another of the same size and type in C++?
With a little work you can reduce the number of steps.





You can cast a pointer to long int to point to your array and move 8 bytes at a time, *only if* you assure that each of your arrays is 8-byte aligned.





The best way to do this is something like the following:





long fakeArray[3];


char *charArray = (char *)fakeArray;





then to copy do something like


long *longPtr = fakeArray, *longPtr2 = fakeArray2;


*longPtr++ = *longPtr2++;


*longPtr++ = *longPtr2++;


*longPtr++ = *longPtr2++;





Maybe even make this a macro:





#define COPY(AAA, BBB) {long *longPtr = (long *) %26amp;(AAA), *longPtr2 = (long *) %26amp;(BBB);\


*longPtr++ = *longPtr2++;\


*longPtr++ = *longPtr2++;\


*longPtr++ = *longPtr2++;\


}





Notice if you do this each of your arrays will need 24 bytes instead of 20, so if you really have a lot of them it will make your memory image larger.





It is often said that premature optimization is a real enemy to good code. Computers are really fast, my guess is that copying short arrays is not going to slow you down very much. Why don't you write the program normally first and then run a profiler to see if this is a problem or not?
Reply:I don't know. I know when programming for Palm, there is an api call named MemMove which will do this, but I don't know for windows.





Maybe you should write that segment in assembly, that would make it quick, but not so easy :)





Hope that helps!
Reply:sorry, u must use a loop to increment the pointer's position


but i guess u can use something called memcpy "it's C not C++ , but i guess u will find it in C++"


or u can use any function that maniuplate strings in C++ like strcat or strcpy and this stuff


sorry if i didn't give u a big help but im really not good in C++, u should move to C# coz it's much better


How 2 write a programmetha generate array of 101 random numbers in c++?

I won't do the work for you, since this smells like homework, but I can give you pseudocode:





define int array random_number of 101 integers


define int i // loop counter





seed random number generator





for i = 0 to 100


__ random_number[i] = generated random number


next i





It's up to you to get the C++ syntax and functions to generate the random numbers.

How 2 write a programmetha generate array of 101 random numbers in c++?
You posted in the wrong section, it should be in Computers %26gt; Programming %26amp; Design (anyway, that shouldn't be much a problem since this is simple and some mathematician are programmers too)





Ok, in C++, you can generate random numbers by calling rand(), but first you've got to #include %26lt;cstdlib%26gt;. Since computers can only generate pseudorandom numbers, most of the time it's good to seed the random number by calling srand(); generally feeding it the current time as current time is always unique.





You can read around here for a bit more about random numbers:


http://www.daniweb.com/forums/thread1769...





You can declare array by using the square bracket:





int anarray[101];





this will create an int array that have 101 members and is named anarray.





Now, one bit you should know, C++'s array is zero-based so the lowest indices start with 0 (anarray[0]) and the highest indices is length of array - 1, that means anarray[100]





Next, you'll need a loop. In C++, there are several kinds of loop, for this one, for-loop is the best choice, I won't talk about the rest for now. The syntax for a for-loop is:





for (initialsituation ; conditiontoloop; operation) {


...codes...


}





You'll need something like this:


for (int i = 0; i %26lt;= 100; i++)





This i variable would be used as the index for your random number array, you'll generate the random number one-by-one, and put it in the next array location.





anarray[i] = rand();





That covers the basic building block. You should be able to write your own code with this and llafer's pseudocode. I hope you could appreciate programming, as it's a fun thing to do once you learned the basic.
Reply:In BASIC:





Dim A(101)


For I = 1 to 101


A(I) = RAND


Next I


Write a program to display the array elements in reverse order in c language?

what kind of elements? integer, strings...etc.





Here is a quickie integer reverse. Assume 10 elements.





for(i=9;i%26lt;=0;i--) {


printf("Array[%d]=%d\n",i,myarray[i]);


}


C programme for largest element in an array?

Ok, for C and not C++?


Just loop through an existing unsorted array to pick out the largested number?





#include %26lt;stdio.h%26gt;


#include %26lt;stdlib.h%26gt;


#include %26lt;limits.h%26gt;





int main()


{


int nums[] ={8,3,7,5,1,9,6,2,0,4};


int counter, maxNum=INT_MIN;


for (counter=0; counter%26lt;=sizeof(nums); counter++)


if (maxNum %26lt; nums[counter]) maxNum = nums[counter];


/* -or- maxNum=Max(maxNum, nums[counter]); */





printf("%d is the largest number in the array\n",maxNum);





return 0;


}

C programme for largest element in an array?
#include%26lt;stdio.h%26gt;


#define size 10


int main()


{


int i,a[size],largest;


printf("Enter the elements in the array\n");


for(i=0;i%26lt;size;i++)


{


scanf("%d",%26amp;a[i]);


}


largest=a[0];


for(i=0;i%26lt;size;i++)


{


largest=a[i]%26gt;largest?a[i]:largest;


}


printf("Largest element is %d\n",largest);


return 0;


}

floral

C++ source code on radix sort using array.?

counting the major operation,passes

C++ source code on radix sort using array.?
if you want people to do your undergraduate homework,


at least you should give more information


and show that at least you tried to do it yourself


How to pass two dimension array to function(by reference in c++)?

arrays are always passed by reference in c++ (so just pass the array like you would an int and it is passed by reference)

How to pass two dimension array to function(by reference in c++)?
void func_for_array(type** array, int size, int size2)


{


};





void main()


{


type array[10][10];


func_for_array(array,10,10);


};


What type should I use to store an array of strings in a class in Visual Studio 2005 C++ ?

I have used char name[20]; to store names before but this is an array itself, correct?





name = "myname"; Does this variable still use 20 bytes? Is a NULL inserted after the last letter of the name in this case?





Maybe a two dimensional char would be best here?





Like char name[20][100]; to store 100 different names?





THanks for helping this newb!

What type should I use to store an array of strings in a class in Visual Studio 2005 C++ ?
yes, char name[20][100] will store 100 names





from what I saw in my debug I typed in "mike"





and it gave me





0-3 were for m i k e


4 was '0'


and the rest were "-52" not sure what to make of it though
Reply:First of all, you're using C++ which has a standard string class. Example of using it:





#include %26lt;string%26gt;


using namespace std;


string name = "My name";





Once you're using the std::string class, you will only need a one-dimensional array (or vector or linked list).





It depends on how many strings you want to store and how you want to access them. If you use an array, you will have to resize them manually when you run out of space, or you will end up wasting space.





The standard library for C++ also includes vectors (arrays that automatically resize themselves).





You can also use linked lists to never waste space. But the problem with linked lists is that you have to look through most of them to find the particular string you want.


How to rotate 2d array 90 degree anticlockwise by using c programming?

Hello,


Rotating an image requires math knowledge as well as experience using the graphic libraries. Take a look at the links I provided below, especially that google groups link.





Basically the operations to rotate the image is to recreate the image the examples below clearly indicate the steps.





Good Luck

How to rotate 2d array 90 degree anticlockwise by using c programming?
Sounds a lot like homework to me... figure it out yourself or you won't learn anything.
Reply:you can think of it as matrix


of dimension 2*n


1 2


3 4


4 5





so it should look like


1 3 4


2 4 5

daisy

How do I input a word from a file using fscanf in the C language? Do I declare an array and use %s?

If you can just give me an example using fscanf to read from a file, one word at a time. I guess we will read til end of file. I want to read 3 words in. Does fscanf ignore whitespace? Will I have to type the 3 words with a hard return in my file?

How do I input a word from a file using fscanf in the C language? Do I declare an array and use %s?
Try the following:


char str [255];


char s_wrd1[80];


char s_wrd2[80];


char s_wrd3[80];





fscanf(tFile, "%s", str);


sscanf(str, "%s %s %s", s_wrd1, s_wrd2, s_wrd3);





The first 3 words will be stored in s_wrd1, s_wrd2 and s_wrd3 variables.





About the hard return, it doesn't matter whether you have it or not.
Reply:Check out this page:


http://www.cse.ucsc.edu/classes/cmps101/...





It gives and example program using the fscanf function.





And yes, I it ignores whitespace. Hard returns will not matter, because it will reach the EOF (End Of File) and return EOF.





FILE in_file;


in_file = fopen(filename, "r");


fscanf(in_file, "%s", %26amp;variable)





Good luck!


Saturday, May 22, 2010

How can i get afree examples on written programs in c languages about the calculation of matrix using array?

Try this Link


http://visualcplus.blogspot.com/2006/03/...

How can i get afree examples on written programs in c languages about the calculation of matrix using array?
http://www.google.co.uk/search?hl=en%26amp;q=m...





Why, Google of course?





Whenever the question is "where can I find..." the answer is always Google.





Rawlyn.

narcissus

Write a C program that stores 5 input numbers into an array and sorts these?

What Vera said. :-)

Write a C program that stores 5 input numbers into an array and sorts these?
C++ :P ('cause I'm more comfortable with itas methods of input and output).





I'm assuming that you want the array ordered in ascending order:





.........


void main()


{


double array[5];





for(int i=0; i%26lt;5; i++)


{


cout%26lt;%26lt;"Please provide a number: ";


cin%26gt;%26gt;array[i];


}





for(int i=0; i%26lt;4; i++)


{


for(j=i+1; j%26lt;5; j++)


{


if(array[i]%26gt;array[j])


{


int aux = array[i];


array[i] = array[j];


array[j] = aux;


}


}


}





count%26lt;%26lt;"The ordered array is: "


for(int i=0; i%26lt;5; i++)


{


cout%26lt;%26lt;array[i]%26lt;%26lt;" ";


}





return;


}





The idea is as follows:


In a for loop I read 5 numbers. Then for the first 4 positions, I make sure that every element on the following positions is greater than or equal to them.





eg.


for a given position i, I make sure that array[i+1], array[i+2] .. array[4] are all greater than or equal to array[i]. If I find a value that does not conform to this, I exchange it with the value of array[i].





P.S. you will need to include the appropriate libraries.





PPS. cout and cin are C++ specific functions, you will need need to switch them with printf respectively gets.


How can I make an array named X to hold MAXSIZE strings in C++?

make the int 'const' and it will/should work.


const int MAX_SIZE = 9999;

How can I make an array named X to hold MAXSIZE strings in C++?
Use pointers to create a dynamic array. Use new to dynamically allocate the size equal to MAXSIZE of string

statice

When C.Norris comes back he will come in golden array at the head of his Chuck Wagon. Who can stand in his way

Jackie Chan. The Chanman rules.

When C.Norris comes back he will come in golden array at the head of his Chuck Wagon. Who can stand in his way
Jean Claude VanDamme
Reply:No, that's too cheap and wack for him. Chuck will do it his own way, he will come floating in the air while the Walker Texas Ranger song plays as background. Chuck Norris will be showing all the things he can do and kill us if we don't do what he dang want us to do: recognize his greatness and fear him
Reply:Who knows where he will be but running a Chuck Wagon upon the return of Jesus may be something he gets. With his faith in God and Jesus I can be pretty sure he will be there ... nothing will stand in the way of Jesus's judgment... so no one.





Here why don't you learn something about what Chuck believes.


http://www.newmanmag.com/display.php?id=...


http://www.newmanmag.com/display.php?id=...


http://www.newmanmag.com/display.php?id=...
Reply:Anyone with an AK-47 or an M-16A2