Write a program that reads ten numbers (in an array), and counts the number of elements in the array that are divisible by 3.
What would this look like in C++ code?
#include %26lt;iostream%26gt;
using namespace std;
int main( int, char **)
{
int i, ary[10];
for (i = 0; i %26lt; 10; ++i)
cin %26gt;%26gt; ary[0];
int cnt = 0;
for (i = 0; i %26lt; 10; ++i)
{
if (ary[i] % 3 == 0)
++cnt;
}
cout %26lt;%26lt; cnt %26lt;%26lt; endl;
return 0;
}
Reply:all numbers are divisible by 3. No need to load them into an array.
Reply:It could look very similar to a program written in C to do the samething. Shouldn't you do your own homework? At lease give it a try and ask for help.
Actually - I've seen someone earlier posting a nearly complete program to do the same thing but having problems withit.
chrysanthemum
Monday, May 24, 2010
Explain line by line the following C++ code?
#include %26lt;iostream.h%26gt;
#include %26lt;conio.h%26gt; //for getch()
#include %26lt;ctype.h%26gt; //for isdigit
#include %26lt;stdlib.h%26gt; //for atoi
main()
{
char ch;
char entier[6];
int compteur=0;
cout %26lt;%26lt; "Enter a whole number : ";
cout.flush ();
do
{
ch = getch();
if ( ch=='\b' %26amp;%26amp; compteur%26gt;0)
{
compteur--;
cout %26lt;%26lt;'\b';
cout %26lt;%26lt; ' ';
cout %26lt;%26lt;'\b';
cout.flush ();
}
else
if (compteur%26lt;6 %26amp;%26amp; isdigit(ch))
{
entier[compteur++]=ch;
cout%26lt;%26lt;ch;
cout.flush();
}
}
while(ch!='\r');
entier [compteur]='\0';
int valeur=atoi(entier);
cout %26lt;%26lt; "\nThe whole number is " %26lt;%26lt; valeur %26lt;%26lt; endl;
system("pause");
}
Explain line by line the following C++ code?
Hey that's not a very good question to ask here. We are here to help you, not serve you.
So instead of giving a junk code and ordering others to explain the damn code, point to the specific line and ask to explain that line. Hope you got my point.
Reply:Damn, that code is just hard enough to read that I couldn't be bothered trying to comprehend it. Damn Yahoo! answers for not keeping indentation.
Reply:hey are you reading Programming for Dummies? Because I'm reading it too
#include %26lt;conio.h%26gt; //for getch()
#include %26lt;ctype.h%26gt; //for isdigit
#include %26lt;stdlib.h%26gt; //for atoi
main()
{
char ch;
char entier[6];
int compteur=0;
cout %26lt;%26lt; "Enter a whole number : ";
cout.flush ();
do
{
ch = getch();
if ( ch=='\b' %26amp;%26amp; compteur%26gt;0)
{
compteur--;
cout %26lt;%26lt;'\b';
cout %26lt;%26lt; ' ';
cout %26lt;%26lt;'\b';
cout.flush ();
}
else
if (compteur%26lt;6 %26amp;%26amp; isdigit(ch))
{
entier[compteur++]=ch;
cout%26lt;%26lt;ch;
cout.flush();
}
}
while(ch!='\r');
entier [compteur]='\0';
int valeur=atoi(entier);
cout %26lt;%26lt; "\nThe whole number is " %26lt;%26lt; valeur %26lt;%26lt; endl;
system("pause");
}
Explain line by line the following C++ code?
Hey that's not a very good question to ask here. We are here to help you, not serve you.
So instead of giving a junk code and ordering others to explain the damn code, point to the specific line and ask to explain that line. Hope you got my point.
Reply:Damn, that code is just hard enough to read that I couldn't be bothered trying to comprehend it. Damn Yahoo! answers for not keeping indentation.
Reply:hey are you reading Programming for Dummies? Because I'm reading it too
What owuld this lookd like in C++ code?
A program that reads ten numbers (in an array) and displays them in reverse order in which they are read.
What owuld this lookd like in C++ code?
#include %26lt;iostream%26gt;
using namespace std;
int main( int, char **)
{
int i, ary[10];
for (i = 0; i %26lt; 10; ++i)
cin %26gt;%26gt; ary[i];
for (i = 0; i %26lt; 10; ++i)
cout %26lt;%26lt; ary[ 9 - i ];
cout %26lt;%26lt; endl;
return 0;
}
Reply:It could look very similar to a program written in C to do the samething. Shouldn't you do your own homework? At lease give it a try and ask for help.
What owuld this lookd like in C++ code?
#include %26lt;iostream%26gt;
using namespace std;
int main( int, char **)
{
int i, ary[10];
for (i = 0; i %26lt; 10; ++i)
cin %26gt;%26gt; ary[i];
for (i = 0; i %26lt; 10; ++i)
cout %26lt;%26lt; ary[ 9 - i ];
cout %26lt;%26lt; endl;
return 0;
}
Reply:It could look very similar to a program written in C to do the samething. Shouldn't you do your own homework? At lease give it a try and ask for help.
How can you write and run C code on mac?
You get yourself a compiler that runs on a mac.
I am told you can get this to run on a mac:
http://www.leonardo-vm.org/
Apple itself distributes Xcode:
http://developer.apple.com/tools/downloa...
I checked out this Mac forum:
http://forums.macrumors.com/showthread.p...
Their response in the end is the Gnu GCC compiler which is so familiar to those of us who work on Linux.
http://gcc.gnu.org/
How can you write and run C code on mac?
you cant... its a mac.
Reply:C is portable and will run where it was compiled so long as you are not counting on OS specific API's
You can can GCC for this.
Reply:Find a compiler that works on the mac and get it.
Reply:Just get a compiler.
Reply:Get XCode:
http://developer.apple.com/tools/downloa...
Or just get GCC for Mac.
In order to download XCode, you'll have to create developer's account with Apple, which is free. XCode includes GCC.
I am told you can get this to run on a mac:
http://www.leonardo-vm.org/
Apple itself distributes Xcode:
http://developer.apple.com/tools/downloa...
I checked out this Mac forum:
http://forums.macrumors.com/showthread.p...
Their response in the end is the Gnu GCC compiler which is so familiar to those of us who work on Linux.
http://gcc.gnu.org/
How can you write and run C code on mac?
you cant... its a mac.
Reply:C is portable and will run where it was compiled so long as you are not counting on OS specific API's
You can can GCC for this.
Reply:Find a compiler that works on the mac and get it.
Reply:Just get a compiler.
Reply:Get XCode:
http://developer.apple.com/tools/downloa...
Or just get GCC for Mac.
In order to download XCode, you'll have to create developer's account with Apple, which is free. XCode includes GCC.
Is there software that will write C++ code automatically?
It depends. There are packages out there that will convert UML to C++ code or many other types of code such as Java or SQL that you then run through a compiler or interpreter. Can it do that for a PC application? Probably no. Can it do that for general applications? Probably yes. Is it a good idea? That is a loaded question. It is definitely a programming paradigm shift, modifications and maintenance may be more difficult but on the other hand good requirements analysis and documentation are required since they "are" the code. Google "code generation" or "rose realtime" as a start.
Is there software that will write C++ code automatically?
Depends what you mean. If you mean, you don't have to touch any code, period, the short answer is no.
There are a number of IDEs (integrated development environments) that allow you to visually drag and drop elements into a project, and then specify certain parameters via a form; that minimizes your coding.
Borland's C++ Developer does this:
http://www.borland.com/us/products/cbuil...
So does Microsoft's Visual C++ Express:
http://msdn.microsoft.com/vstudio/expres...
And that tool is free to download / use.
There are also several programs that will convert one programming language to another; for example, a Visual Basic program to C++.
daffodil
Is there software that will write C++ code automatically?
Depends what you mean. If you mean, you don't have to touch any code, period, the short answer is no.
There are a number of IDEs (integrated development environments) that allow you to visually drag and drop elements into a project, and then specify certain parameters via a form; that minimizes your coding.
Borland's C++ Developer does this:
http://www.borland.com/us/products/cbuil...
So does Microsoft's Visual C++ Express:
http://msdn.microsoft.com/vstudio/expres...
And that tool is free to download / use.
There are also several programs that will convert one programming language to another; for example, a Visual Basic program to C++.
daffodil
I need help to write this C++ code urgently. I don't know where to start??
A.) Write a function named powfun () that raises an integer number passed to it to a positive integer power and displays the result. The positive integer should be the second value passed th the function. Declare the variable used to store the result as a long-integer data type to ensure sufficient storage for the result.
B.) Include the function written in (A.) in a working program. Make sure your function is called from main ().
Test the function by passing various data to it.
I need help to write this C++ code urgently. I don't know where to start??
just first try to learn c++ then code otherwise u will start hating it.
Reply:unsigned long powfun(int base, int power)
{
unsigned long res = 1;
for (int i=power; i%26gt;=1; --i)
res = res * base;
return res;
}
Now, do the main() function yourself.
Reply:A) create a function that returns long-integer
make sure the function has 2 parameters one for the base and one for the power.. example call power_func(base, power); once u have the skeleton done, write a loop the decreases Power until it is one, every time it decreases the power it should multiply the base time its self and store that into a temp. variable, then return That temp variable outside ur loop, after it
also u have to account for the 0th power which is always 1, u might want to block ur while with an if statement
Thats a normal way for doing powering , there are way faster algorithms out there for fast powering, like interval halving
Reply:#include %26lt;stdio.h%26gt;
#include %26lt;stdlib.h%26gt;
#include %26lt;math.h%26gt;
int main()
{
int integer,
power,
result;
printf("Please input the integer\n");
scanf("%d",%26amp;integer);
printf("Please input the power\n");
scanf("%d",%26amp;power);
{
result=pow(integer,power);
}
printf("%d raised to the %d power is %d",integer,power,result);
system("PAUSE");
return 0;
}
B.) Include the function written in (A.) in a working program. Make sure your function is called from main ().
Test the function by passing various data to it.
I need help to write this C++ code urgently. I don't know where to start??
just first try to learn c++ then code otherwise u will start hating it.
Reply:unsigned long powfun(int base, int power)
{
unsigned long res = 1;
for (int i=power; i%26gt;=1; --i)
res = res * base;
return res;
}
Now, do the main() function yourself.
Reply:A) create a function that returns long-integer
make sure the function has 2 parameters one for the base and one for the power.. example call power_func(base, power); once u have the skeleton done, write a loop the decreases Power until it is one, every time it decreases the power it should multiply the base time its self and store that into a temp. variable, then return That temp variable outside ur loop, after it
also u have to account for the 0th power which is always 1, u might want to block ur while with an if statement
Thats a normal way for doing powering , there are way faster algorithms out there for fast powering, like interval halving
Reply:#include %26lt;stdio.h%26gt;
#include %26lt;stdlib.h%26gt;
#include %26lt;math.h%26gt;
int main()
{
int integer,
power,
result;
printf("Please input the integer\n");
scanf("%d",%26amp;integer);
printf("Please input the power\n");
scanf("%d",%26amp;power);
{
result=pow(integer,power);
}
printf("%d raised to the %d power is %d",integer,power,result);
system("PAUSE");
return 0;
}
Is it possible to copy your c++ code and put into a word file? If so, how is it done?
C++ or any code prior to compilation or interpretation is a text file fun through a parser, etc. All you need to do is either cut-n-paste, as above, or open the file in Word, or whatever editor.
Is it possible to copy your c++ code and put into a word file? If so, how is it done?
Yea, you copy the code from your compilers editor and then paste it into word or elsewhere.
Is it possible to copy your c++ code and put into a word file? If so, how is it done?
Yea, you copy the code from your compilers editor and then paste it into word or elsewhere.
I need to have the the c++ code for this one..i really need it...help me pls!!!!?
The first output is:
Group Project in
IT221-Data Structures
Submitted by:
Juna Char
Mai Char
submitted to:
Emo
please press enter to continue....
The second output is:
Select the following choices:
1. STACKS
2. QUEUES
3. TREE
4. SORTING
*Under the Stacks you can have 1 sample program
like testing contiguous implementation.
*Under the Queues you can have 1 sample program
like Using queues of strings.
*Under the Tree you can have traversal or binary tree.
*and under the Sorting you can have the 3 simple sorting:
bubble sorting, selection sorting and insertion.
2 days ago - 1 day left to answer
I need to have the the c++ code for this one..i really need it...help me pls!!!!?
Just a thought, but by looking at this problem you are in about a freshman/sophomore college level class, most likely going into Computer Science or Management Information Systems... Since you chose this degree, I suppose you have many more courses to take, such as OS, Architecture, Automata, SE, etc, you might want to learn about basic programming and data structures... Try learning it on your own... It might help for future courses.
Reply:Look, the display is pretty straightforwarward. And it looks like the required actions are display.
My teacher in college told us that C (and C++) is a language that in and of itself doesn't DO much, until you add libraries.
for the display screens on a windows system the libraries you need are iostream and cstdlib which you begin the program by telling the compiler you need thus:
#include %26lt;iostream%26gt;
#include %26lt;cstdlib%26gt;
Because of a change in the language a few years back, the next line is required to keep the syntax from being impossibly convoluted. I won't explain it because it wouldn't help.
using namespace std;
Notice the semicolon at the end. Most but not all of the statements which follow should end with a semicolon. If they don't then the program won't compile.
This next line is the first exception:
void main(){
After this you need to know a few commands/operators:
cout is the standard output. In other words the screen.
%26lt;%26lt; sends something somewhere, usually to cout.
endl. is the end of the line. When you send it to cout it moves to the next line of output.
system() from cstlib is a function which calls another program which is why this can only work with Windows. You;ll be calling a program which doesn't work in Linux or MacOS.
Now for the code:
cout %26lt;%26lt; "Group Project in" %26lt;%26lt; endl;
cout %26lt;%26lt; "IT221-Data Structures" %26lt;%26lt; endl;
cout %26lt;%26lt; endl;
cout %26lt;%26lt; "Submitted by:" %26lt;%26lt; endl;
cout %26lt;%26lt; "Juna Char" %26lt;%26lt; endl;
cout %26lt;%26lt; "Mai Char" %26lt;%26lt; endl;
cout %26lt;%26lt; endl;
cout %26lt;%26lt; "submitted to:" %26lt;%26lt; endl;
cout %26lt;%26lt; "Emo"; %26lt;%26lt; endl;
cout %26lt;%26lt; endl;
cout %26lt;%26lt; endl;
cout %26lt;%26lt; "please ";
system("pause");
That is your first screen and that's all I think you need. Close off the program with a '}' and an enter.
}
Pause stops the program prints out "press any key to continue" and waits for you to press a key before continuing. Therefore all the elements you want are there on the screen.
You probably can do the second screen yourself. If this is for college you should. If you want to know how to implement the menu choices you should tell us how the stacks, queues and trees are implemented. There are two ways of doing each -- with arrays and with pointers -- and we don't have enough information to try any of them.
Group Project in
IT221-Data Structures
Submitted by:
Juna Char
Mai Char
submitted to:
Emo
please press enter to continue....
The second output is:
Select the following choices:
1. STACKS
2. QUEUES
3. TREE
4. SORTING
*Under the Stacks you can have 1 sample program
like testing contiguous implementation.
*Under the Queues you can have 1 sample program
like Using queues of strings.
*Under the Tree you can have traversal or binary tree.
*and under the Sorting you can have the 3 simple sorting:
bubble sorting, selection sorting and insertion.
2 days ago - 1 day left to answer
I need to have the the c++ code for this one..i really need it...help me pls!!!!?
Just a thought, but by looking at this problem you are in about a freshman/sophomore college level class, most likely going into Computer Science or Management Information Systems... Since you chose this degree, I suppose you have many more courses to take, such as OS, Architecture, Automata, SE, etc, you might want to learn about basic programming and data structures... Try learning it on your own... It might help for future courses.
Reply:Look, the display is pretty straightforwarward. And it looks like the required actions are display.
My teacher in college told us that C (and C++) is a language that in and of itself doesn't DO much, until you add libraries.
for the display screens on a windows system the libraries you need are iostream and cstdlib which you begin the program by telling the compiler you need thus:
#include %26lt;iostream%26gt;
#include %26lt;cstdlib%26gt;
Because of a change in the language a few years back, the next line is required to keep the syntax from being impossibly convoluted. I won't explain it because it wouldn't help.
using namespace std;
Notice the semicolon at the end. Most but not all of the statements which follow should end with a semicolon. If they don't then the program won't compile.
This next line is the first exception:
void main(){
After this you need to know a few commands/operators:
cout is the standard output. In other words the screen.
%26lt;%26lt; sends something somewhere, usually to cout.
endl. is the end of the line. When you send it to cout it moves to the next line of output.
system() from cstlib is a function which calls another program which is why this can only work with Windows. You;ll be calling a program which doesn't work in Linux or MacOS.
Now for the code:
cout %26lt;%26lt; "Group Project in" %26lt;%26lt; endl;
cout %26lt;%26lt; "IT221-Data Structures" %26lt;%26lt; endl;
cout %26lt;%26lt; endl;
cout %26lt;%26lt; "Submitted by:" %26lt;%26lt; endl;
cout %26lt;%26lt; "Juna Char" %26lt;%26lt; endl;
cout %26lt;%26lt; "Mai Char" %26lt;%26lt; endl;
cout %26lt;%26lt; endl;
cout %26lt;%26lt; "submitted to:" %26lt;%26lt; endl;
cout %26lt;%26lt; "Emo"; %26lt;%26lt; endl;
cout %26lt;%26lt; endl;
cout %26lt;%26lt; endl;
cout %26lt;%26lt; "please ";
system("pause");
That is your first screen and that's all I think you need. Close off the program with a '}' and an enter.
}
Pause stops the program prints out "press any key to continue" and waits for you to press a key before continuing. Therefore all the elements you want are there on the screen.
You probably can do the second screen yourself. If this is for college you should. If you want to know how to implement the menu choices you should tell us how the stacks, queues and trees are implemented. There are two ways of doing each -- with arrays and with pointers -- and we don't have enough information to try any of them.
Guys.. can u translate it into C++ code?? please....?
Sub SingleSorter( byRef arrArray)
Dim row, j
Dim StartingKeyValue, NewKeyValue, swap_pos
For row = 0 To UBound( arrArray ) - 1
'Take a snapshot of the first element
'in the array because if there is a
'smaller value elsewhere in the array
'we'll need to do a swap.
StartingKeyValue = arrArray ( row )
NewKeyValue = arrArray ( row )
swap_pos = row
For j = row + 1 to UBound( arrArray )
'Start inner loop.
If arrArray ( j ) %26lt; NewKeyValue Then
'This is now the lowest number -
'remember it's position.
swap_pos = j
NewKeyValue = arrArray ( j )
End If
Next
If swap_pos %26lt;%26gt; row Then
'If we get here then we are about to do a swap
'within the array.
arrArray ( swap_pos ) = StartingKeyValue
arrArray ( row ) = NewKeyValue
End If
Next
End Sub
Guys.. can u translate it into C++ code?? please....?
Let me guess, you needed Bubble sort in c++, couldn't figure it out on your own. You googled, but got the code in VB instead. Pathetic.
You would get better help if you wanted to seriously learn the algorithms at hand.
Reply:ya that first guy was right on
this is for asking questions, not getting people just to do work for u
hyacinth
Dim row, j
Dim StartingKeyValue, NewKeyValue, swap_pos
For row = 0 To UBound( arrArray ) - 1
'Take a snapshot of the first element
'in the array because if there is a
'smaller value elsewhere in the array
'we'll need to do a swap.
StartingKeyValue = arrArray ( row )
NewKeyValue = arrArray ( row )
swap_pos = row
For j = row + 1 to UBound( arrArray )
'Start inner loop.
If arrArray ( j ) %26lt; NewKeyValue Then
'This is now the lowest number -
'remember it's position.
swap_pos = j
NewKeyValue = arrArray ( j )
End If
Next
If swap_pos %26lt;%26gt; row Then
'If we get here then we are about to do a swap
'within the array.
arrArray ( swap_pos ) = StartingKeyValue
arrArray ( row ) = NewKeyValue
End If
Next
End Sub
Guys.. can u translate it into C++ code?? please....?
Let me guess, you needed Bubble sort in c++, couldn't figure it out on your own. You googled, but got the code in VB instead. Pathetic.
You would get better help if you wanted to seriously learn the algorithms at hand.
Reply:ya that first guy was right on
this is for asking questions, not getting people just to do work for u
hyacinth
Please people help me with a c code which compresses files by conversion bmp to jpg?or where should i search?
its urgent!
Please people help me with a c code which compresses files by conversion bmp to jpg?or where should i search?
.bmp is a more of a microsoft paint extension, that and most websites will not be able to upload a picture with that extension anyway.
Go with jpg or jpeg, this is a universal format.. any website host can upload them and they are much smaller in size than .bmp's are
Reply:u just need to open ur pic using mspaint(in run command u type mspaint and open ur file) and then save as ur file whatever u extension u want it always be in compressed form ....have a fun!
Reply:http://www.wikipedia.org
Please people help me with a c code which compresses files by conversion bmp to jpg?or where should i search?
.bmp is a more of a microsoft paint extension, that and most websites will not be able to upload a picture with that extension anyway.
Go with jpg or jpeg, this is a universal format.. any website host can upload them and they are much smaller in size than .bmp's are
Reply:u just need to open ur pic using mspaint(in run command u type mspaint and open ur file) and then save as ur file whatever u extension u want it always be in compressed form ....have a fun!
Reply:http://www.wikipedia.org
Can u provide me with a c code for logic given below.......?
$GPRMC,040302.663,A,3939.7,N,10506.6,W,0...
$GPRMC,
040302.663, //time (current IST=Time+5.30)
A, //Validate (OK)
3939.7675,N, //Latitude ddmm.mmmm
10506.64565,W, //Longitude dddmm.mmmm
0.27,
358.86,
200804, //Date
,*1A
/**********Latitude Calculation**************/
ddmm.mmmm = 3939.7675
dd=39
mm.mmmm= 39.7675
minutes= mm.mmmm/60 =0.66279
decimal format = dd + minutes
= 39.66279
/************longitude calculation***********/
dddmm.mmmm= 10506.6456
ddd= 105
mm.mmmm= 06.64565
minutes= mm.mmmm/60 = 0.11076
decimal format = dd + minutes
= 105.11076
/*******Coordiantes to enter in Google Earth************/
Latitude, longitude
39.66279,105.11076
39.66279N,105.11076E
+39.66279,+105.11076
Can u provide me with a c code for logic given below.......?
try c compiler ,or just printf them all
Reply:I can surely but not getting what have you writte mail me regarding this if you want the source code and your question.
$GPRMC,
040302.663, //time (current IST=Time+5.30)
A, //Validate (OK)
3939.7675,N, //Latitude ddmm.mmmm
10506.64565,W, //Longitude dddmm.mmmm
0.27,
358.86,
200804, //Date
,*1A
/**********Latitude Calculation**************/
ddmm.mmmm = 3939.7675
dd=39
mm.mmmm= 39.7675
minutes= mm.mmmm/60 =0.66279
decimal format = dd + minutes
= 39.66279
/************longitude calculation***********/
dddmm.mmmm= 10506.6456
ddd= 105
mm.mmmm= 06.64565
minutes= mm.mmmm/60 = 0.11076
decimal format = dd + minutes
= 105.11076
/*******Coordiantes to enter in Google Earth************/
Latitude, longitude
39.66279,105.11076
39.66279N,105.11076E
+39.66279,+105.11076
Can u provide me with a c code for logic given below.......?
try c compiler ,or just printf them all
Reply:I can surely but not getting what have you writte mail me regarding this if you want the source code and your question.
What would this look like in C++ code?
A program that finds the smallest element in the array of integers.
What would this look like in C++ code?
Amanda's answer is good, but it may be slow when your array is very large. Since most data sets are usually larger than N%26gt;=20 the algorithm I am giving is going to be more useful when dealing with an unsorted array. It may seem long but it is a very powerful algorithm. I apologize for the lack of formatting because it won't accept my spaces.
int quicksort(vector %26amp; A, int left, int right)
{
if(left + 10 %26lt;= right){
int pivot = median(A, left, right);
int i = left, j = right-1;
for( , , ){
while(A[++i] %26lt; pivot) {}
while(pivot %26lt; A[--j]) {}
if(i %26lt; j)
swap(A[i], A[j]);
else
break;
}
swap(A[i], A[right - 1]);
quicksort(A, left, i -1); // sort small elements
quicksort(A, i+1, right); // sort large elements
}
else
insertionSort(A, left, right);
/* array is now sorted so you can select any element you want be it the smallest or the largest because the array is sorted */
return A[0];
}
const int median(vector %26amp; A, int left, int right)
{
int center = (left+right)/2;
if(A[center] %26lt; A[left])
swap(A[left], A[center]);
if(A[right] %26lt; A[left])
swap(A[left], A[right]);
if(A[right] %26lt; A[center])
swap(A[center], A[right]);
swap(A[center], A[right-1]);
return A[right-1];
}
void insertionSort(vector %26amp; A)
{
int j;
for(int p=1; p%26lt;A.size(); p++){
int tmp = A[p];
for(j = p; j %26gt; 0 %26amp;%26amp; tmp %26lt; A[j-1]; j--)
A[j] = A[j-1];
A[j] = tmp;
}
}
Now you can easily find minimum numbers in very large arrays with no problem.
I forgot to mention you need to include %26lt;algorithm%26gt; to use the swap function.
PS - All the other solutions posted so far are really stupid because finding the minimum in say 100 million integers is going to take forever. Also one of them is incorrect.
Reply:#include %26lt;algorithm%26gt;
return *std::min_element(array, array + size);
The std library has many useful routines for doing things like searching, sorting and whatnot.
The previous posters gave good information if you need to write it yourself.
Reply:the easiest way is a for loop:
int smallest=array[0];
for(int i=0; i%26lt;array.length; i++){
__if(array[i]%26lt;smallest)
_____smallest=array[i];
}
that will compare every element in the array.
the underscores are cause its easier to read w/ formatting, but yahoo isn't letting me do that right now. :)
Reply:#include %26lt;iostream%26gt;
using namespace std;
int main(){
//This is an int because I like to return 0.
int alphabet[]={12, 2, 7, 6,39}; //hey, I wanted an array.
int SizeOf=5; //It's always better to assign size of array to a variable
// or macro
int Least; // to hold the smallest number.
Least=alphabet[0];
//No braces because I'm only repeating one
//test/action.
for (int i=1;i%26lt;=SizeOf;i++) if (alphabet[i]%26lt;Least) Least=alphabet[i];
// print out the smallest value.
cout %26lt;%26lt; Least %26lt;%26lt; endl;
// tell the OS all is well and bail.
return 0;
}
Reply:int findSmallest(int *arr, int max) {
int smallest = arr[0];
for (int i=1; i%26lt;max; i++)
if (arr[i] %26lt; smallest)
smallest = arr[i];
return smallest;
}
Reply:const int ARRAY_SIZE = 35;
int array[ARRAY_SIZE] = {4,6,2,9,7,0,1,5,7,4,3,7,9,0,1,3,45,6,7,...
int SmallestElementIndex = 0;
int SmallestElement = array[SmallestElementIndex];
for (int i = 0; i %26lt; ARRAY_SIZE; i++)
{
if(array[i] %26lt; SmallestElement)
{
SmallestElement = array[i];
SmallestElementIndex = i;
}
}
This code finds the smallest integer in the array, and also stores the index of that item. If there are multiple elements that have the same value as the smallest integer then the index will be the lowest index (first occurring smallest integer).
What would this look like in C++ code?
Amanda's answer is good, but it may be slow when your array is very large. Since most data sets are usually larger than N%26gt;=20 the algorithm I am giving is going to be more useful when dealing with an unsorted array. It may seem long but it is a very powerful algorithm. I apologize for the lack of formatting because it won't accept my spaces.
int quicksort(vector %26amp; A, int left, int right)
{
if(left + 10 %26lt;= right){
int pivot = median(A, left, right);
int i = left, j = right-1;
for( , , ){
while(A[++i] %26lt; pivot) {}
while(pivot %26lt; A[--j]) {}
if(i %26lt; j)
swap(A[i], A[j]);
else
break;
}
swap(A[i], A[right - 1]);
quicksort(A, left, i -1); // sort small elements
quicksort(A, i+1, right); // sort large elements
}
else
insertionSort(A, left, right);
/* array is now sorted so you can select any element you want be it the smallest or the largest because the array is sorted */
return A[0];
}
const int median(vector %26amp; A, int left, int right)
{
int center = (left+right)/2;
if(A[center] %26lt; A[left])
swap(A[left], A[center]);
if(A[right] %26lt; A[left])
swap(A[left], A[right]);
if(A[right] %26lt; A[center])
swap(A[center], A[right]);
swap(A[center], A[right-1]);
return A[right-1];
}
void insertionSort(vector %26amp; A)
{
int j;
for(int p=1; p%26lt;A.size(); p++){
int tmp = A[p];
for(j = p; j %26gt; 0 %26amp;%26amp; tmp %26lt; A[j-1]; j--)
A[j] = A[j-1];
A[j] = tmp;
}
}
Now you can easily find minimum numbers in very large arrays with no problem.
I forgot to mention you need to include %26lt;algorithm%26gt; to use the swap function.
PS - All the other solutions posted so far are really stupid because finding the minimum in say 100 million integers is going to take forever. Also one of them is incorrect.
Reply:#include %26lt;algorithm%26gt;
return *std::min_element(array, array + size);
The std library has many useful routines for doing things like searching, sorting and whatnot.
The previous posters gave good information if you need to write it yourself.
Reply:the easiest way is a for loop:
int smallest=array[0];
for(int i=0; i%26lt;array.length; i++){
__if(array[i]%26lt;smallest)
_____smallest=array[i];
}
that will compare every element in the array.
the underscores are cause its easier to read w/ formatting, but yahoo isn't letting me do that right now. :)
Reply:#include %26lt;iostream%26gt;
using namespace std;
int main(){
//This is an int because I like to return 0.
int alphabet[]={12, 2, 7, 6,39}; //hey, I wanted an array.
int SizeOf=5; //It's always better to assign size of array to a variable
// or macro
int Least; // to hold the smallest number.
Least=alphabet[0];
//No braces because I'm only repeating one
//test/action.
for (int i=1;i%26lt;=SizeOf;i++) if (alphabet[i]%26lt;Least) Least=alphabet[i];
// print out the smallest value.
cout %26lt;%26lt; Least %26lt;%26lt; endl;
// tell the OS all is well and bail.
return 0;
}
Reply:int findSmallest(int *arr, int max) {
int smallest = arr[0];
for (int i=1; i%26lt;max; i++)
if (arr[i] %26lt; smallest)
smallest = arr[i];
return smallest;
}
Reply:const int ARRAY_SIZE = 35;
int array[ARRAY_SIZE] = {4,6,2,9,7,0,1,5,7,4,3,7,9,0,1,3,45,6,7,...
int SmallestElementIndex = 0;
int SmallestElement = array[SmallestElementIndex];
for (int i = 0; i %26lt; ARRAY_SIZE; i++)
{
if(array[i] %26lt; SmallestElement)
{
SmallestElement = array[i];
SmallestElementIndex = i;
}
}
This code finds the smallest integer in the array, and also stores the index of that item. If there are multiple elements that have the same value as the smallest integer then the index will be the lowest index (first occurring smallest integer).
I have to input integer for c++ code how can i check whether the user input integer or a string character?
then if he input a charecter how to promt him to enter integer again
I have to input integer for c++ code how can i check whether the user input integer or a string character?
there are functions available in ctype.h header
isalph()
isalnum()
isdigit()
use them
Reply:all input is char values, they must be converted to int values, I believe 0 the character 0 is equal to 32, but you can say
if(x%26gt;='0' || x%26lt;'9') then
{
cout%26lt;%26lt;"This character is a number"
}
if you then wanted to convert it to a real number just subtract the character 0 from it IE '9' - '0' = 9
I have to input integer for c++ code how can i check whether the user input integer or a string character?
there are functions available in ctype.h header
isalph()
isalnum()
isdigit()
use them
Reply:all input is char values, they must be converted to int values, I believe 0 the character 0 is equal to 32, but you can say
if(x%26gt;='0' || x%26lt;'9') then
{
cout%26lt;%26lt;"This character is a number"
}
if you then wanted to convert it to a real number just subtract the character 0 from it IE '9' - '0' = 9
How to unlock SAMSONITE luggage b/c code is lost? Is it possible?
See websites below. Hope you can do it ok.
How to unlock SAMSONITE luggage b/c code is lost? Is it possible?
The plastic method works like a charm. thanks!! Report It
Reply:I had to bust mine open with a screwdriver
Reply:metacafe.com has a video on one way to do it.
There is another way. You can use a small piece of plastic like they use on bread wrappers. Cut a "V" shaped point into it. Slip the pointed in adjacent to the wheels. Turn the wheels until you feel the plastic fall into the notch.
Then go to the next wheel and do the same. Then to the last one.
If you get in touch with samsonite they will send you the instructions and a piece of plastic to do it with.
You might find instructions on their web site. Good luck.
How to unlock SAMSONITE luggage b/c code is lost? Is it possible?
The plastic method works like a charm. thanks!! Report It
Reply:I had to bust mine open with a screwdriver
Reply:metacafe.com has a video on one way to do it.
There is another way. You can use a small piece of plastic like they use on bread wrappers. Cut a "V" shaped point into it. Slip the pointed in adjacent to the wheels. Turn the wheels until you feel the plastic fall into the notch.
Then go to the next wheel and do the same. Then to the last one.
If you get in touch with samsonite they will send you the instructions and a piece of plastic to do it with.
You might find instructions on their web site. Good luck.
What would this look like in C++ code?
a program that reads ten numbers (in an array), and counts the number of elements in the array that are divisible by 3.
What would this look like in C++ code?
#include%26lt;iostream.h%26gt;
#include%26lt;conio.h%26gt;
void main()
{
clrscr();
int arr[10];int ctr=0;
cout%26lt;%26lt;"Enter 10 numbers";
for(int i=0,i%26lt;10,i++)
{
cin%26gt;%26gt;arr[i];
if((arr[i]%3)==0)
ctr++;
}
cout%26lt;%26lt;"The no of elements divisible by 3 are"%26lt;%26lt;ctr;
}
Reply:Assuming you already have the numbers in an array called "numbers":
int count = 0;
for(int i = 0 ; i%26lt;10 ; i++){
if(numbers[i] % 3 ==0){
count++;
}
}
The variable "count" will have what you need. Just stick that into a function.
What would this look like in C++ code?
#include%26lt;iostream.h%26gt;
#include%26lt;conio.h%26gt;
void main()
{
clrscr();
int arr[10];int ctr=0;
cout%26lt;%26lt;"Enter 10 numbers";
for(int i=0,i%26lt;10,i++)
{
cin%26gt;%26gt;arr[i];
if((arr[i]%3)==0)
ctr++;
}
cout%26lt;%26lt;"The no of elements divisible by 3 are"%26lt;%26lt;ctr;
}
Reply:Assuming you already have the numbers in an array called "numbers":
int count = 0;
for(int i = 0 ; i%26lt;10 ; i++){
if(numbers[i] % 3 ==0){
count++;
}
}
The variable "count" will have what you need. Just stick that into a function.
Can I use winvi to save C code and open it using a Unix shell already running on a windows os ?
I'm familiar with Windows and UNIX, but have no experience with Winvi. I'm taking a wild shot and saying that it will either be compatible in a UNIX shell, or not. If it does the wierd line marker syndrome, then you can rectify that with a free utility available from the URL below, called ToFroDOS. This should make life bearable with little bells or whistles.
cosmos
cosmos
I am searching for Java or C code that does Euclidean alignment of two 3D point sets. Anyone know of any?
The algorithm needs to handle 2 point sets that do not necessarily have the same cardinality. If you know of a MATLAB toolkit or library that does that, that'd work as well. Thanks a lot to anyone who responds.
I am searching for Java or C code that does Euclidean alignment of two 3D point sets. Anyone know of any?
I'm not familiar with any code, or those mathematical concepts for that matter, but you could try entering different things into Google Code Search:
google [DOT] com [SLASH] codesearch
(Yahoo kept giving me errors trying to submit with the actual URL...)
You can include in your search:
lang:c
or:
lang:java
to specify you only want results in one particular programing language.
I am searching for Java or C code that does Euclidean alignment of two 3D point sets. Anyone know of any?
I'm not familiar with any code, or those mathematical concepts for that matter, but you could try entering different things into Google Code Search:
google [DOT] com [SLASH] codesearch
(Yahoo kept giving me errors trying to submit with the actual URL...)
You can include in your search:
lang:c
or:
lang:java
to specify you only want results in one particular programing language.
How to do the Histogram equalization + C code using opencv in linux?
My task is to write a program to perform histogram
equalisation on a image.
My program should take 6 parameters as follows:
equalise input.bmp output.bmp 100 200 300 400
This should load the input.bmp image and produce the output.bmp file.
The equalisation should be based on a histogram from the rectangular area in the image defined by the points (x,y) and (x',y').
any help welcom
cheers
How to do the Histogram equalization + C code using opencv in linux?
Browse some of these links for ideas, algorithm descriptions, etc., in the comments.
http://www.google.com/search?q=%22histog...
equalisation on a image.
My program should take 6 parameters as follows:
equalise input.bmp output.bmp 100 200 300 400
This should load the input.bmp image and produce the output.bmp file.
The equalisation should be based on a histogram from the rectangular area in the image defined by the points (x,y) and (x',y').
any help welcom
cheers
How to do the Histogram equalization + C code using opencv in linux?
Browse some of these links for ideas, algorithm descriptions, etc., in the comments.
http://www.google.com/search?q=%22histog...
How to identify the cis-elements in genomic DNA? also how to script a simple code in C/perl to do the same.?
to identify, one should look for physical or chemical traits of cis-elements in genomic DNA.
please do mention how the cis-elements can be identified in a strand of genomic DNA.
the code should take in a sample DNA strand as the input and identify and give the cis-element in that as the output. the code can be in either C or perl or any programing language.
How to identify the cis-elements in genomic DNA? also how to script a simple code in C/perl to do the same.?
Your description of the methodology sounds correct, but I do not have any code that would search for only cis-elements.
please do mention how the cis-elements can be identified in a strand of genomic DNA.
the code should take in a sample DNA strand as the input and identify and give the cis-element in that as the output. the code can be in either C or perl or any programing language.
How to identify the cis-elements in genomic DNA? also how to script a simple code in C/perl to do the same.?
Your description of the methodology sounds correct, but I do not have any code that would search for only cis-elements.
Subscribe to:
Posts (Atom)