Search results

  1. A

    Comp Sci Huffman Tree Coding

    First, I get the string and I find the frequency of the every character. My struct is: typedef struct huffman_tree{ char c; int freq; //unsigned? struct huffman_tree *left; // 0 (left) struct huffman_tree *right; // 1 (right) }huffman_tree; I write this to create Huffman tree...
  2. A

    Comp Sci Using Malloc to Read a File Dynamically

    #include<stdio.h> #include<stdlib.h> #include<math.h> #include<string.h> #include<time.h> int main(){ int index=1; int *arr; int data; char *c; FILE *fp; int input,inp; arr=(int*)malloc(sizeof(int)); fp=fopen("list2.txt","r")...
  3. A

    Comp Sci String and sscanf

    #include<stdio.h> int main(){ char str[]="My first book"; char *a,*b,*c; sscanf(str,"%s %s %s",a,b,c); printf("a=%s b=%s c=%s",a,b,c); } If I write like this, I am getting seg fault
  4. A

    Comp Sci String and sscanf

    #include<stdio.h> int main(){ char str[]="My first book"; char *a,*b,*c; sscanf("%s %s %s",a,b,c); printf("a=%s b=%s c=%s",a,b,c); } I want the output: a= My b=first and c=book. But it does not work, why?
  5. A

    C/++/# Recursive-Array

    I want to write code walk around the array recursively. For some reason I cannot share my code. Let's say I have a array like this: arr[4], I want to look 012 123 013 or 01 12 23 02 03 13. In code I write I can look 012 123 or 01 12 23 but I cannot look 013 or 02 03 13. What algorithm should I...
  6. A

    Comp Sci Using Recursion to Calculate (n + r)!/(n! * r!)

    Yes, right. But it doesn't work if I entered 5 and 2 , output-2. But if n-5 and r-5 ->output-21
  7. A

    Comp Sci Using Recursion to Calculate (n + r)!/(n! * r!)

    Shouldn't function constantly call itself? Is this still recursion?
  8. A

    Comp Sci Using Recursion to Calculate (n + r)!/(n! * r!)

    Okay if n=5 and r=5--> 10!/5!*5! is not equal 5!/0!*5!
  9. A

    Comp Sci Using Recursion to Calculate (n + r)!/(n! * r!)

    Yes, you are right. It also doesn't return the true result of the division. For example if 5/6 it returns 0. But I have to write int function.
  10. A

    Comp Sci Using Recursion to Calculate (n + r)!/(n! * r!)

    I wirte code but it does not work. I entered n=5 and r=2, result is 0. And I want to calculate this recursively. #include<stdio.h> int func(int n, int r); int main(){ int n,r; int result=0; printf("Enter the number:\n"); scanf("%d",&n); printf("Enter the 2.number:\n")...
  11. A

    Comp Sci Recursive Double code to Calculate the sum of the square roots <= a number

    Yes I can use loop but my teacher does not allow loop in this homework
  12. A

    Comp Sci Recursive Double code to Calculate the sum of the square roots <= a number

    at first I added another value that holds the number in the function like this; #include<stdio.h> #include<math.h> double foo(int n, double mean, int n2){ if(n==1){ return(1); } if(n!=0){ return( (sqrt((n-mean)*(n-mean))+foo(n-1,mean,n2))/(sqrt(n2-1)) ); }...
  13. A

    Comp Sci Recursive Double code to Calculate the sum of the square roots <= a number

    #include<stdio.h> #include<math.h> double foo(int n, double mean){ double square; if(n==1){ return(1); } if(n!=0){ return( (sqrt((n-mean)*(n-mean))+foo(n-1,mean))/(sqrt(n-1)) ); } } int main(){ int num; double mean; int i; int sum=0...
  14. A

    Recursively calculate the standard deviation

    #include<stdio.h> #include<math.h> double foo(int n, int mean){ double square; if(n==1){ return(1); } if(n!=0){ square=pow(n-mean,2); return( (sqrt(square)+foo(n-1,mean))/(sqrt(n-1)) ); } } int main(){ int num; double mean; int i...
  15. A

    Comp Sci Recursive Double code to Calculate the sum of the square roots <= a number

    not n, n-1. I typed wrong. Forget it and let's say I want to calculate standard deviation recursively.
  16. A

    Comp Sci Recursive Double code to Calculate the sum of the square roots <= a number

    return( sqrt((n))+foo(n-1) ); I write like this and it works. Now I'm wondering where I would write the (n) if I wanted to calculate it sqrt((5+4+3+2+1)/n) recursively.
  17. A

    Comp Sci Recursive Double code to Calculate the sum of the square roots <= a number

    I tried a lot but it does not happen.. :( Anyway thank you for help.
  18. A

    Comp Sci Recursive Double code to Calculate the sum of the square roots <= a number

    #include<stdio.h> #include<math.h> double foo(int n){ if(n==1){ return(1); } if(n!=0){ return( sqrt((n)+foo(n-1) ) ); } } int main(){ int num; printf("Enter the number: "); scanf("%d",&num); foo(num); printf(" %lf ",foo(num)); return(0)...
  19. A

    Comp Sci Recursion double function

    I did not understand what you say. the function will call itself about 560 times
  20. A

    Comp Sci Recursion double function

    double foo(int arr[], double *ave, int index){ double *s; *s=*ave; // calculation// return(foo (arr,ave,index)); // other calculation// } I want to keep the ave value during the recursion, because after ave is calculated, I will do another calculation is recursively in this...
  21. A

    Comp Sci Do-while loop-> exit not working (making a crossword puzzle)

    Yes, string.h is written my code. I tried to use strcmp. When I used this, I get a segmentation fault.
  22. A

    Comp Sci Do-while loop-> exit not working (making a crossword puzzle)

    I tried to use strcmp. When I used this, I get a segmentation fault.
  23. A

    Comp Sci Do-while loop-> exit not working (making a crossword puzzle)

    You are right. I don't use this place too much. Please forgive me for my inexperience. :)
  24. A

    Comp Sci Do-while loop-> exit not working (making a crossword puzzle)

    Thanks for your answer. I tried, but still it does not work.
  25. A

    Comp Sci Do-while loop-> exit not working (making a crossword puzzle)

    Hello! My homework is making a crossword. I write a code like this: do{ //code printf("Please enter the coordinate and the word: \n"); scanf(" %c%d %s",&row2,&column2,word2); if(row2=='E' && word2=="xit") exit(0); //code }while(count2!=10); But this is...
Top