コード例 #1
0
int lucky(char *argn){
	int i,j;
	long int input = atol(argn);
	int length = find_length(input);
	float *number = (float *)malloc(length*sizeof(float));
	init(number,length,input);
	float *number1 = (float *)malloc(length*sizeof(float));
	int **oper2;
	oper2 = (int **)malloc(Pow(4,(length-1))*sizeof(int *));	
	for (i=0; i<Pow(4,(length-1)); i++){
		oper2[i] = (int *)malloc(length*sizeof(int));
	}
	int *oper3 = (int *)malloc(length*sizeof(int));
	float *number3 = (float *)malloc(length*sizeof(float));
	create_opers(oper2,length);
	int length1;
	for (i=0; i<Pow(2,(length-1)); i++){
		length1 = create_group(i,number,length,number1);
		for (j=0; j<Pow(4,(length1-1)); j++){
			copy_arrays(number1,number3,oper2[j],oper3,length1);
			if (check(length1,number3,oper3)){
				return 0;
			}
		}
	}
	return 1;
}
int find_length(char *s, int i) {
  if (s[i] == '\0') {
    return 0;
  }
  /* else */
  return 1 + find_length(s, i + 1);
}
コード例 #3
0
ファイル: Cluster.cpp プロジェクト: rmdcarney/testBeamAna
unsigned Cluster::get_length(){
	if(length == 0){
		if(DEBUG)
			std::cout<<"I am starting to caluclate the length"
				<<std::endl;
		find_length();
}
	return length;
}
コード例 #4
0
void str_words_in_rev(char *input, int len) {

    int length;
    length = find_length(input);
    reverse(input, 0, length - 1);
    reverse_words(input, length);


}
int is_palindrome(char *s) {
  int n;
  int m;
  
  n = find_length(s, 0) - 1;
  if (n % 2 == 0) { /*if length is odd */
    m = n/2;
  } else { /* length is even */
    m = n/2 + 1;
  }
  return check_chars(s, 0, n, m);
}
コード例 #6
0
/* copy_string finds the length of a given string,
   allocates space for a copy of the string,
   loops through the string to copy its char values into the allocated space,
   and returns the string.
*/
char *copy_string(char *s) {
  int i;
  int length;
  char *copy;

  length = find_length(s);
  copy = malloc(sizeof(char)*length);
  
  for (i = 0; i < length; i++) {
    copy[i] = s[i];
  }
  return copy;
}
コード例 #7
0
char KthIndexFromEnd(char *str, int k) {
	int i=0;
		int len = find_length(str);
		if ((k<len) && (k>=0)&&len>0){
			for (i = 0; i < len; i++){
				if (i == (len - 1 - k)){
					return str[i];
					break;
				}
			}
		}
	else
	return '\0';
}
コード例 #8
0
ファイル: digits.c プロジェクト: tdurieux/IntroClass
int main() {
	int n, length, digits;
	printf("\nEnter an integer > ");
	scanf("%d", &n);
	length = find_length(n);
	while (length != 0) {
		if (n<0 && length != 1)
			digits = abs(n) % 10;
		else
			digits = n % 10;
		n = n / 10;
		length = length - 1;
		printf("%d\n", digits);
		}
	printf("That's all, have a nice day!\n");

	return 0;
}
コード例 #9
0
ファイル: hilenv.c プロジェクト: amaggi/legacy-code
int hilbert(int numsamp,const double *f,double *fhilb)

{

  void cfft();
  int find_length();
  void detrend();
  int i, j,npts_max;
  double bpfilt;
  dcomplex imag;
  dcomplex *x;

  if(numsamp<=0) { 
    fprintf(stderr,"%s\n","No data points read ....");
    return (1);
  }

  npts_max = find_length(numsamp);
  if (npts_max == 0) {
    fprintf(stderr,"Too long input time series \n");
    return (2);
  }
  x = (dcomplex *) malloc(npts_max * sizeof(dcomplex));

  if ( x == NULL ) {
    fprintf(stderr,"Incorrect allocation\n");
    return (3);
  }

  imag.re = 0.;  imag.im = 1.0;

  for( i=0; i<numsamp; i++)   
    {
      x[i].re = f[i]; 
      x[i].im = 0.;
    }
  for(i=numsamp; i<npts_max; i++) 
    x[i].re = x[i].im = 0.;

  cfft( x,npts_max,-1 );

  for (i=1; i<=npts_max/2; ++i)
    { 
      x[i] = dcmult(x[i],imag);
    }

  x[0].re = 0.;
  x[0].im = 0.;

  for( i=(npts_max/2)+1; i<npts_max; i++ ) 
    x[i] = dconj(x[npts_max-i]);

  cfft( x,npts_max,1 );

  for( i=0; i<numsamp; i++)       
    fhilb[i] = x[i].re/npts_max;

  detrend(fhilb, numsamp);
  free(x);
  return (0);
}