They are pretty much useless if they do nothing else other than to boost up ones 'hard drive' temporarily.
vijayan121 commented: !! +6
hammerhead 19 Posting Whiz in Training
They are pretty much useless if they do nothing else other than to boost up ones 'hard drive' temporarily.
For two matrices to be equal, the dimensions of both matrices have to be equal and the corresponding values should also be equal. I would follow niek_e's method to compare two matrices.
I dont know if it can be classified as anime or not, but I like Avatar.
Insert line 20 inside the while loop and add the statement prev=prev->link;
at the end of the loop.
Take a good book on computer architecture and start reading, once you have finished a chapter start reading the refrences given at the end of the chapter. Most of them will be papers from IEEE or ACM so you need to find access to them as they are paid (try your college, most colleges suscribe to their services). I begin this way when I have to do a major project.
An alternative could be using link list if you want to do it without STL. That way your first issue would be solved, but still the best way would be using vectors.
Spend the day adventure sporting with my friends.
10 C and I am outside in a t-shirt.
40C here and I am burning :(
You are not using your head and instead simply copy pasting the code. If you had read any of the posts above the mistake in my code would have been clear to you.
number1 = number % 10;
number=number/10;
number2 = number % 10;
number=number/10;
number3 = number % 10;
No you are not. The base of the numbers is 10 not 100 or 1000. And you have used cout the wrong way
cout << endl << number<< number2<<number3;
A hint, divide a number by 10. The quotient would be the number except for the least significant digit and the remainder would be the least significant digit. Use these two in combination to get your answer
I am not sure, it has worked for me and I have never bothered to search. I will leave it for more experienced programmers to answer your question.
There is no need to use floor() as int truncates any decimal place as it is.
for any 4 digit number this should do the trick to extract all 4 digits
i=0;
while(number>0)
{
a[i]=number%10;
number=number/10;
i++;
}
i=0 will correspond to the last digit(4th in this case), i=1 to the 3rd and so on.
so your answer will be
ans=a[3]*3+a[2]*a[1]-a[0];
Its not
cin >> number,first,second,third,fourth;
but
cin >> number>>first>>second>>third>>fourth;
and kindly use code tags in future
I dont mind being called a geek because that is more or less what I am :)
Note that the '==' operator does not apply to float. You would get the output as C++ if you tried
if(f==.7)
How would i then access elements on the second row? and elements in the columns for multiplication. The method to access these is described to me, however i do not know how to implement it in a loop. The method states "multiply the number of rows minus one * the number of columns on each row, then add the column number minus one to this result. So to access the 2nd element on the second row, it would be sumthing like ((2-1)*3) + (2-1) = 4. So if we count 0..4 we get the second element on the second row which is 23
The formula can be generalized as
index= ((row_num-1)*3) + (col_num-1)
where index is the index in the array
row_num is the row number of the element you want to refer and
col_num is the column number of the element you want to refer.
Suppose you want to refer to 34
row_num=2
col_num=3
you get index as 5
Hi James
Right click on My Computer and select Manage. On the left select disk management and select your drive. On the unallocated partition, right click and select format. You will have options of which file system you want to use (NTFS or FAT32) choose anyone (I suggest NTFS) and format.
Be careful, do not format your C: drive. Format only that space that you see as unallocated.
This will not integrate into the primary one, it will only create more drives that you can use. I am not sure as to how you can integrate, I guess softwares like partition magic can do that. I am not sure though.
Also read this link
http://support.microsoft.com/kb/309000
Format the partitions from disk management in either FAT32 or NTFS.
for(int i=countDown;i>=0;i-- )
Number of colums in the first matrix have to be equal to the number of rows in the second one. If you have only a row or a column matrix i.e. two arrays, their lengths have to be equal in order for the multiplication to take place.
Umm, I think I got the hcf part of it (thanks hammerhead), but how to figure out 'lcm of 2 nos' just beats me :-/ ...
Also note how m and n get interchanged if n>m, consider the case of m=6 and n=15
r1=6 MOD 15 = 6
m<-n implies m=15
n<-r implies n=6
the process is repeated to get gcd as 3
LCM is the tricky one. One needs to know that every number greater than 1 can be represented as products of prime numbers. Once factors each number m,n into its corresponding prime factors and then by multiplying the numbers with highest order we get the LCM. I have never implemented it on C++, it would be a good idea to do it now :D
Here are some links on LCM
http://mathworld.wolfram.com/LeastCommonMultiple.html
http://en.wikipedia.org/wiki/Least_common_multiple
Okay here is the pseudo code for hcf, credit to Euclid.
gcd(m,n)
r<-(m MOD n);
if r=0 then
{ return n }
else
{
m<-n
n<-r
gcd(m,n)
}
Sorry if my pseudocode is not as per standard.
All compilers follow certain processes such as lexical analysis, syntax analysis semantic analysis etc in one way or another.
Are you using a dhcp to assign ip's to your ethernet card? What is your isp? Also if you are using pppoe make sure that your username and password are correct :P
Or maybe
arr1 = 3 0 0 5 size=4
arr2= 3 0 5 size=3
// array sol of size 5 here
then we need the array solution as size 4+1. It will still be simulation of decimal addition, but in that case two loops might be required.
One that starts to add from the lowest 5's till the smaller array is exhausted and the other that simply copies the remaining elements of the larger array into the sol array.
Again the two loops may not be nested.
and must be able to handle unusual situations (e.g.,
what if two days have the same number of cars?)
For this you can do what Ancient Dragon said and find out the maximum/minimum value and then traverse the array once again and compare each element with the maximim/minimum value, if it is equal then simply print that day also.
Another alternative would be sorting the array in ascending order and then printing values from the beginning/end while two consecutive values are equal.
^ Umm I think that 2038. And another one in 10000.
In the above loop you would have to check for every i if it is odd or not using
if(i%2!=0)
alternatively you could use i=i-2 instead of i-- and simply display the numbers.
I dont know how I missed this thread, but here is an interesting article I came across some days back
http://www.nytimes.com/2008/03/29/science/29collider.html?pagewanted=1
There is a strrev() function in string.h for char array. I dont know enough to help you with your code but I suggest you to follow a different method for checking palindrome in a string.
Instead of checking a string with a reverse string, make two pointers one at the starting of the string and other at the end. For a string to be a palindrome the starting should match the end, if so then increment the starting pointer and decrease the end pointer. Again both should be equal for the string to be a palindrome. Keep doing so until start equals end.
I dont know what you are trying to do but in line 12 during the last iteration of the loop i=4, i+1 will be 5 that will go out of bounds for the array pass. Run the loop till i<4 because there will be no i+1 for the last element.
At line 7 when the loop ends, f will be 10. You are simply multiplying 1*10 and storing it in result. You can make result an array of size 10 then use
result[f-1]=k*f;
If you want to do it by using regular expressions you would need a lexical analyzer. For C/C++ lex is usually used. Here is a tutorial page
http://dinosaur.compilertools.net/lex/index.html
as for the code
int i,
char x;
for(i = 0; i <= test_string.length; i++) //checks the entire length of the string
{
if('0' <= test_string[i] && test_string[i] <= '9') //checks for ints between 0 to 9
{
// character is a digit
}
else if(test_string[i]=='.')
{
// string is a floating point
}
cout<<" test string is full of digits"<<endl;
}
Tennis, sleeping and movies.
Factorial of any number greater than 5 ends with a zero. For a larger number, the number of zeroes at the end constitute a large part of the number. If you can eliminate those zeroes it will help.
If you can simple check at the end of the factorial that if it ends with 0 then you can reduce that number by dividing it by 10. In this case
For example
6!= 720
7!=5040
7!=7*6!
now 6! is reduced to 72
7!=7*72=504
append a 0 at the end and we get 5040
you will have to maintain a counter for the number of zeroes you will be required to add at the end.
Oops correction
f(209)=f(f(20)+9)=f(f(f(2)+0)+9))=f(f(2)+9)=f(11)=f(1)+1=2
So many f's . But again I might be wrong again :) . I havnt tested it for values where sum of the digits is a number of three digits or more.
Use else if statement. According to your code, if a=0 and b=0 then both the first and the second if statements will be executed. And the output will be
"There are no solutions"
"There is one solution x"
use this
if (a == 0 && b ==0)
{
printf("There are no solutions.");
}
else if (a == 0)
{
one root = -c / b;
printf("There is one root of %f.);
}
else if (sqrt(pow (b ,2)) - (4 * a * c)) < 0)
{
printf("There are no real roots.");
}
else if (a < 0 && a > 0 && b < 0 && b > 0)
{
x1 = (-b + sqrt ((pow (b, 2)) - (4 * a * c))) / (2 * a);
x2 = (-b + sqrt ((pow (b, 2)) - (4 * a * c))) / (2 * a);
printf("The two real roots are %f and %f.", x1, x2);
}
From the test cases I used, the code was working fine (till the max value of int) . I usually write down a mathematical expression before coding it. The function for sum of the digits of a whole number would be
f(x) = { x if x is single digit i.e x<10
f(x/10)+(f%10) otherwise
}
if the sum returned by this function is more than a single digit number, we can use the same function again to find the eigen number. That is what I have done in the first code by using a while loop.
If we use
f(f(x/10)+(x%10))
it will calculate the sum of sum of the digits unless the number or its sum comes out to be a single digit number. A few examples
f(1)= 1 as x <10
f(10)= f(f(1)+0)=f(1)=1
f(209)=f(f(20)+9)=f(f(2)+0+9)=f(2+9)=f(11)=f(1)+1=1+1=2
I think the function is correct but if there is some problem kindly inform me. It will be highly appreciated.
Okay here is another shorter alternative.
#include<iostream.h>
int eig(int num)
{
if(num<10)
{
return num;
}
else
{
return eig(eig(num/10)+(num%10));
}
}
void main()
{
int n,ans=0;
cin>>n;
ans=eig(n);
cout<<"Eigen number is "<<ans<<endl;
}
Okay I made this code on Turbo C
#include<iostream.h>
int eig(int num)
{
if(num<10)
{
return num;
}
else
{
return eig(num/10)+(num%10);
}
}
void main()
{
int n,ans=0;
cin>>n;
ans=eig(n);
while(1)
{
if(ans<10)
{
break;
}
else
{
ans=eig(ans);
}
}
cout<<"Eigen number is "<<ans<<endl;
}
Its not totally recursive though. I will post if can make a totally recursive one.
From what I remember of my coordinate geometry, testing for a point inside a triangle wasnt easy. Try this
http://mathworld.wolfram.com/TrianglePointPicking.html
you might have to translate one point to match that of origion.
I am presently working on emulation of human movements through robotics as my college project.
You can clear the entire screen using the cleardevice() function and redraw the square in a loop with the new positions.
Live life as if you are going to die tommorrow and learn as if you are going to live forever.
It is better to burn out than to fade away- Kurt Cobain