Shankye 36 Junior Poster

Oopss no idea

may be consider one poly use two loops Check term by term with all remaining poly

considering p4 (in program p[0])

for(i=0; i<MAX_EXP; i++)
{
 for(j=0; j<k; j++)
 {
   for(int m=0; m<k; k++)
    {
     if(p[0].term[j].expo = p[i].term[m].expo)
        p[0].term[j].coeff += p[i].term[m].coeff;
    }
  }
}

But if exponent are in decreasing order and dont think this type of comparisn may be needed ..

Hope it helped

Shankye 36 Junior Poster

I agree with Ckoy ..
If want new updated things switch to power langs ;)

Shankye 36 Junior Poster

ok thanks

How about going 4 5 years back in schooling time and doing how we used to do in school

p1 = 3x^2 + 2x^1 + x^0
p2 = 1x^2 + 1x^1 + 2x^0
----------------
multiplying term by term

p4 = 0x^4 + 0x^3 + 6x^2 + 4x^1 + 2x^0
p5 = 0x^4 + 3x^3 + 2x^2 + 1x^1 + 0x^0
p6 = 3x^4 + 2x^3 + 1x^2 + 0x^1 + 0x^0
-------------------------------------

Adding above will give our answer ..


I think this approach will be easier ..

mul(poly p1, poly p2, poly *p3)
{
poly p[p1.noOfterms];

	for(int i=0; i<p1.noOfTerms; i++)
	{
	   for(int j=0,int k=0; j<p2.noOfTerms; j++,k++)
            {
		p[i].terms[k].coeff = p1.terms[i].coeff * p2.terms[j].coeff;
	        p[i].terms[k].expo  = p1.terms[i].expo  + p2.terms[j].expo;
	    }
	}

   // Comapare exponent and if equal add their coeff
}
Shankye 36 Junior Poster

ok thanks :)

How about going 4 5 years back in schooling time and doing how we used to do in school

p1 = 3x^2 + 2x^1 + x^0
p2 = 1x^2 + 1x^1 + 2x^0
----------------
multiplying term by term

p4 = 6x^2 + 4x^1 + 2x^0
p5 = 3x^3 + 2x^2 + 1x^1
p6 = 3x^4 + 2x^3 + 1x^2
-------------------------------------

Adding above will give our answer ..


I think this approach will be easier ..

mul(poly p1, poly p2, poly *p3)
{
poly p[p1.noOfterms];

	for(int i=0; i<p1.noOfTerms; i++)
	{
	   for(int j=0,int k=0; j<p2.noOfTerms; j++,k++)
            {
		p[i].terms[k].coeff = p1.terms[i].coeff * p2.terms[j].coeff;
	        p[i].terms[k].expo  = p1.terms[i].expo  + p2.terms[j].expo;
	    }
	}

   // Using a loop Comapare exponent and if equal add their coeff

}
vinitmittal2008 commented: Like ur suggestion :) +1
Shankye 36 Junior Poster

B4 posting it want to say im student and if any mistake im sorry

May be like manually how we do ...
Assign first term of p4 to p5 and then go on checking if same exponent term exists,
If exists add thr coefficinents
and if not than add that term to p5, it will be p5.term[1]
and again go on checking again if same exponent in p4 exists if not add next term and so on ..

May be like

poly p5;

p5.term[0] = p4->term[0];
p5.noOfTerms = 1;

while( i <= k)
{
    for(i=0; i <= p5.noOfTerms; i++)
     {
        if(p5.term[i].expo == p4->term[i]->expo)
            p5.term[i].coeff += p4->term[i]->coeff ;
     }
   /* If same exponent term in p5 and p4 not found
      add that term to p5 
      and p5.noOfTerms++ */
}
Shankye 36 Junior Poster

No idea about new books

But search for

Committee Draft — Septermber 7, 2007 ISO/IEC 9899:TC3

Shankye 36 Junior Poster
Shankye 36 Junior Poster

I think K&R is best book to read after learning basics of C,
I read BalaguruSwamy .. An indian author ..

Heard about this book but not read ..
C Programming: A Modern Approach by K. N. King

Shankye 36 Junior Poster

@Colin mac .
They are different functions used to get user inputs similar to scanf and getche() which your sir suggested..

U can google to know more about functions like getchar() getch() fgets() ..

Shankye 36 Junior Poster

And if problem solved close this thread ..

Shankye 36 Junior Poster

oh thts nice..
strcmp is better way stick with this but i think u need correcting on 4th line..
U scannig string so use %s and dont use address operator(&

If its working its fine :)

Shankye 36 Junior Poster

I not getting what help you expecting from all??????

see your code

while(1)
		{
		printf("\ntype 'ls' to see your whats in your current directory or press x to continue ");
		scanf("%c", &input);
		if(input[0] == "ls")
		{
		system(input);
		continue;
		}
		else
		{
		if (input[0] != "ls")
		break;
		
		
	}

You scanning single char with %c and thn taking suggestion to use strcmp??

Dude first tell what is input???????
<b>char???
Array of char???
pointer????</b>

what is tht??

Shankye 36 Junior Poster

And i think i and j must be assigned before loop ..

Try using this code ..

i=0;
      j=n-1;   // You may be going wrong here 

      while(i<j)
      { 
         if(a[i]==a[j])
         {
           i++;
           j--;
         }
         else
           break; 
       }
 // Remaining code as it is ..
Shankye 36 Junior Poster

I think you checking even new line char '\n'..

Try to trim newline char and than check for palidrome ..

Shankye 36 Junior Poster

Write to fflush all the buffers and make stdin and stdout clean..

IF possible post full code, will try to compile and check whether it works here

Shankye 36 Junior Poster

getch() completely worked fine for me ..

Here is code which compiled and worked for me ..

#include <stdio.h>

int main (void)
{

  char temp;
  while(1)
  {
     if( (temp=getch()) == 'x')
     {
        printf("Bye");
        exit(0);
     }
     printf("Looping");
   }
 return(0);
}
Shankye 36 Junior Poster

May be getc() wont return unless enter hit so use getch() which returns key pressed and neither echo it to the screen..

if   ((answer = getch()) == 'x')
Shankye 36 Junior Poster

First of all, when you scanning float u should use %f

scanf("%f", &num);

I think u need an int operand to to use with %..
so cast the float to int with (int)

rightdigit = (int)num % 10;
Shankye 36 Junior Poster

Ya but he want a recursion and iteration based program ..

Mark it solved if problem solved ..

Shankye 36 Junior Poster

I dont think following lines are required in your your program

*nextRow = &row;

   *nextColumn = &column;

When you call function with appropriate parameters, nextRow and nextColumn will be initialized .
I am not getting why u changing there values again and making them point to other.


may be this code will help you.

int guess;
      for(int i=0; i<10; i++)
      {
        for(j=0; j<10; j++)
        {
           printf("Enter your guess");
           scanf("%d",&guess);

           // Check whether write ship guessed 
           // and make suitable flow on gamer guess
         }
      }
Shankye 36 Junior Poster

Problem solved may be ..
Mark it solved

Shankye 36 Junior Poster

818

Shankye 36 Junior Poster

Learn OpenGL dude ..

Check this out

http://www.cs.uccs.edu/~semwal/indexGLTutorial.html

Shankye 36 Junior Poster

You may be interested in this page ..

File handling

Shankye 36 Junior Poster

796

Shankye 36 Junior Poster

Welcome ..
Mark it solved ..

Shankye 36 Junior Poster

798

Shankye 36 Junior Poster

806

Shankye 36 Junior Poster
Shankye 36 Junior Poster

:-)

Shankye 36 Junior Poster

Thr are some so called Good programming practices in C, Try to follow them to avoid frustration ..

While opening file, use something like this..

if( (file = fopen("FileName.txt",r)) == NULL )
   {
         printf("Error opening file \n Program exiting\n");
         system("pause");
         exit(0);
   }

If file couldnt be opened in that case NULL is returned by fopen() function,
so by checking whether its NULL or not we will be sure about file operation ..

Happy programming ..

Shankye 36 Junior Poster

Oops sorry for the mistake..
Correct code may be like this

while(i != 0)
{
      sum += i;
      i--;
}

Hope code is correct now ..

Shankye 36 Junior Poster

I run your program, didnt got any error ..

On 16th line while opening file you gave extra space between C: and \\

c: \\familyin.txt"

i just removed that space and program worked fine..

Shankye 36 Junior Poster

@Dragon I think he is opening two different files ..

One is familyin.txt and familyout.txt..
Whr you talking about those two???

Ancient Dragon commented: Yes, you are right :) +34
Shankye 36 Junior Poster

696

Shankye 36 Junior Poster

Ya ..
But as you need longest word dont forget to go on storing longest word along with the length ...

Shankye 36 Junior Poster

Check this
precedence of all operators ..

http://www.difranco.net/cop2220/op-prec.htm

Shankye 36 Junior Poster

@kimprosthom Create a new thread and post your doubts ..

Shankye 36 Junior Poster

Its possible may be..

I dont know in C but i saw a similar program in C++ .. though didnt understood ;-)

Shankye 36 Junior Poster

Its C forum ..

Shankye 36 Junior Poster

It simple dude

Lvalue on left and Rvalue on right ;-)

Shankye 36 Junior Poster

U are on the way but need more efforts ..

Check this may help

As you know fib series is obtained by adding previous numbers, You want recursion so function must call itself repeated to get serious
Here is function which does that

fib (int x, int y, int z)
{
        if(z==0)
        { 
                return ;
        }

        printf("%d\n",x);
        z--;
 // For next number in serious add current number (x+y) and exact previous
        fib(y,(x+y),z);
}

Just call the function once from main()

int main (void)
{
        int x, y, z;
        x=0; y=1;
        printf("Enter a number: ");
        scanf("%d", &z);
        fib(x, y, z);
        return(0);
}

You try for iteration method ..

Shankye 36 Junior Poster

Recursion may be like this

sum(int n)
{
          if(n==0)
             return 0;
          else
             return n+sum(n-1);
}

iteration may be like this

while(i != 0)
{
      sum += i;
}
Shankye 36 Junior Poster
Shankye 36 Junior Poster

Yup ..
Go on checking step by step how the program flows..

See your values are
x=2 and y=5

When main calls sumS
n=2 and m=5
which are not equal
so else block executed
which returns n*n + again call to sumS with 3 and 5
3 and 5 are not equal so (n+1)*(n+1) + again call to sumS with 4 and 5 and so on
Which ends when 5=5 with returning only 5*5

so finally your result will contain

n*n + (n+1)*(n+1) + (n+2)*(n+2) and so on till n=m ...

2*2 + 3*3 + 4*4 + 5*5 = 54 ...

Hope its clear

Shankye 36 Junior Poster

Yup ..
Go on checking step by step how the program flows..

See your values are
x=2 and y=5

When main calls sumS
n=2 and m=5
which are not equal
so else block executed
which returns n*n + again call to sumS with 3 and 5
3 and 5 are not equal so (n+1)*(n+1) + again call to sumS with 4 and 5 and so on
Which ends when 5=5 with returning only 5*5

so finally your result will contain

n*n + (n+1)*(n+1) + (n+2)*(n+2) and so on till n=m ...

2*2 + 3*3 + 4*4 + 5*5 = 54 ...

Hope its clear

Shankye 36 Junior Poster

Answer is 3 ..

First 3*3*3 gives 27
thn modulus operator gives remainder of 27%4
Hence ans is 3..

I got your doubt

U thinking

3*3*3%4
= 3*3*(3%4)
= 3*3*3
= 27

but its wrong ..

U need to refer operator precedence in C

* / % Multiplication/division/modulus left-to-right
so first multiplication is done and thn division if any and thn modulus operator comes..
Hence the result 3..

Shankye 36 Junior Poster

Multiples of 3 gives 27

the remainder of the operation is given by modulus operator(%)

so
.
27%4 = 3 which is remainder obtained by division ..

Shankye 36 Junior Poster

Those are not formula ..
U need to understand program flow, how actually program runs and how decisions are made in its way ..
Hope Vinit 'll agree with me ...

Shankye 36 Junior Poster

Embedded your code in code tag..
U did nothing to solve your problem dude..
Try something if got problem in implementing your code we will help you