Forum: C++ May 15th, 2008 |
| Replies: 10 Views: 780 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. |
Forum: C++ May 13th, 2008 |
| Replies: 4 Views: 569 Insert line 20 inside the while loop and add the statement prev=prev->link; at the end of the loop. |
Forum: C++ May 11th, 2008 |
| Replies: 7 Views: 950 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. |
Forum: C++ May 1st, 2008 |
| Replies: 15 Views: 1,318 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. |
Forum: C++ May 1st, 2008 |
| Replies: 15 Views: 1,318 number1 = number % 10;
number=number/10;
number2 = number % 10;
number=number/10;
number3 = number % 10; |
Forum: C++ May 1st, 2008 |
| Replies: 15 Views: 1,318 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; |
Forum: C++ May 1st, 2008 |
| Replies: 15 Views: 1,318 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... |
Forum: C++ Apr 27th, 2008 |
| Replies: 26 Views: 2,104 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. |
Forum: C++ Apr 27th, 2008 |
| Replies: 26 Views: 2,104 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;... |
Forum: C++ Apr 27th, 2008 |
| Replies: 26 Views: 2,104 Its not
cin >> number,first,second,third,fourth;
but
cin >> number>>first>>second>>third>>fourth; |
Forum: C++ Apr 26th, 2008 |
| Replies: 8 Views: 695 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) |
Forum: C++ Apr 26th, 2008 |
| Replies: 27 Views: 3,923 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... |
Forum: C++ Apr 25th, 2008 |
| Replies: 1 Views: 459 for(int i=countDown;i>=0;i-- ) |
Forum: C++ Apr 25th, 2008 |
| Replies: 27 Views: 3,923 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... |
Forum: C++ Apr 24th, 2008 |
| Replies: 14 Views: 4,339 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 |
Forum: C++ Apr 24th, 2008 |
| Replies: 14 Views: 4,339 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... |
Forum: C++ Apr 24th, 2008 |
| Replies: 14 Views: 4,339 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 |
Forum: C++ Apr 17th, 2008 |
| Replies: 9 Views: 1,265 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... |
Forum: C++ Apr 16th, 2008 |
| Replies: 8 Views: 532 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... |
Forum: C++ Apr 14th, 2008 |
| Replies: 7 Views: 529 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. |
Forum: C++ Apr 11th, 2008 |
| Replies: 6 Views: 2,697 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... |
Forum: C++ Apr 10th, 2008 |
| Replies: 4 Views: 400 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... |
Forum: C++ Apr 9th, 2008 |
| Replies: 3 Views: 508 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; |
Forum: C++ Mar 23rd, 2008 |
| Replies: 8 Views: 984 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... |
Forum: C++ Feb 28th, 2008 |
| Replies: 16 Views: 1,247 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... |
Forum: C++ Feb 28th, 2008 |
| Replies: 16 Views: 1,247 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... |
Forum: C++ Feb 28th, 2008 |
| Replies: 16 Views: 1,247 Okay here is another shorter alternative.
#include<iostream.h>
int eig(int num)
{
if(num<10)
{
return num; |
Forum: C++ Feb 28th, 2008 |
| Replies: 16 Views: 1,247 Okay I made this code on Turbo C
#include<iostream.h>
int eig(int num)
{
if(num<10)
{
return num; |
Forum: C++ Feb 27th, 2008 |
| Replies: 4 Views: 9,124 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... |