Пример #1
0
TestPVMonitor::TestPVMonitor(const TestPVChannel::shared_pointer& ch,
              const pvd::MonitorRequester::shared_pointer& req,
              size_t bsize)
    :channel(ch)
    ,requester(req)
    ,running(false)
    ,finalize(false)
    ,inoverflow(false)
    ,needWakeup(false)
{
    pvd::PVDataCreatePtr fact(pvd::PVDataCreate::getPVDataCreate());
    for(size_t i=0; i<bsize; i++) {
        pvd::MonitorElementPtr elem(new pvd::MonitorElement(fact->createPVStructure(channel->pv->dtype)));
        free.push_back(elem);
    }
    overflow.reset(new pvd::MonitorElement(fact->createPVStructure(channel->pv->dtype)));
    overflow->changedBitSet->set(0); // initially all changed
    epicsAtomicIncrSizeT(&countTestPVMonitor);
}
Пример #2
0
int main(){
	double number, sum1, sum, term, term1, loop;
	sum=0.0;
	sum1=0.0;
	printf("Enter the number:\n");
	scanf("%lf", &number);
	for(loop= 1.0; loop<=10.0; loop++){
		term= pow(number, loop)/loop;
		sum+=pow(-1.0,(loop+1.0))*term;

	}
	printf("Log %3lf is %.3lf \n", number+1.0, sum);
	for(loop= 0.0; loop<=10.0; loop++){
		term1= pow(number, loop)/fact(loop);
		sum1+=term1;
	}
	printf("e raised to power %3lf= %.3lf\n", number, sum1);
	return 0;
}
int main() {
	
	int n = -1,
		i;
	double sum = 0.00;
	
	while (n<0 || n>20) {
		scanf("%d", &n);
	}
	
	for (i=1; i<=n; i++) {
		sum = sum + (1.00 / fact(i));
	}
	
	printf("%f", sum);

	return 0;

}
Пример #4
0
void foo (int x, int c, char h)
{
    int i = fact(x);
    int a = a+1;
    void foo3 (void);
    int niz1[5] = { 1, 2, 3 };
//    int niz[10] = a;              // ne smije s desne strane biti niz, moze jedino biti konstantni niz
    
    for (i = 0; i < 5; i++)
        break;
    while(1)
    {
        break;
        i = i + 2;
    }
//  return 5;           // vraca int a treba vracati void
    return;
//  break;              // break izvan petlje
}
Пример #5
0
int main() {
    
    // Very basic, NOT comprensive, tests of the recursive methods.
    
    int vals[4];
    printf("7! = %d\n", fact(7));
    printf("31^2 + 32^2 + ... + 200^2 = %d\n", sumsq(31, 200));
    
    vals[0] = 37; vals[1] = 48; vals[2] = 56; vals[3] = 63;
    printf("vals has %d Odd values.\n", ArrayOdd(vals, 4));
    
    print_reverse("writethisbackwards", 18);
    printf("\n");
    printf("3^10 = %d\n", powerA(3,10));
    printf("3^11 = %d\n", powerB(3,11));
     
    if (Rbinary(33, vals, 0, 3) == -1)
        printf("33 was not found in vals.\n");
        
    dectobin(179);
    printf("\n");
    
    if (check("madamimadam", 11))
        printf("madamimadam is a palindrome.\n");
        
    printf("The 27th Fibonacci number is %d\n", fibonacci(27)); 
    
    // Test of fast exponentiation vs. regular version
    
    int start = time(0);
    int ans1 = slowModPow(6874, 1000000000, 13713);
    int end1 = time(0);
    int ans2 = modPow(6874, 1000000000, 13713);
    int end2 = time(0);
    
    printf("ans1 = %d, ans2 = %d.\n", ans1, ans2);
    printf("slowModExp took %d sec.\n", end1-start);
    printf("modPow took %d sec.\n", end2-end1);
    
    system("PAUSE");
    return 0;
}
Пример #6
0
static void test_empty_contours(skiatest::Reporter* reporter) {
    SkPath path;

    path.moveTo(0, 0).lineTo(100, 100).lineTo(200, 100);
    path.moveTo(2, 2).moveTo(3, 3);                 // zero-length(s)
    path.moveTo(4, 4).close().close().close();      // zero-length
    path.moveTo(5, 5).lineTo(5, 5);                 // zero-length
    path.moveTo(5, 5).lineTo(5, 5).close();         // zero-length
    path.moveTo(5, 5).lineTo(5, 5).close().close(); // zero-length
    path.moveTo(6, 6).lineTo(7, 7);
    path.moveTo(10, 10);                            // zero-length

    SkContourMeasureIter fact(path, false);

    // given the above construction, we expect only 2 contours (the rest are "empty")

    REPORTER_ASSERT(reporter, fact.next());
    REPORTER_ASSERT(reporter, fact.next());
    REPORTER_ASSERT(reporter, !fact.next());
}
Пример #7
0
void kperm(int num,int search, int pole[]){
    int i,*options;
    search--;
 	 if(search==1){
       for(i=0 ; i<num ; i++){
       	pole[i] = (i+1);
       }
     }
    options = (int *)malloc(num*sizeof(int));

    for(i=0 ; i<num ; i++){
        options[i] = i+1;
    }

    for(i=0 ; i<num ; i++){
        double help = fact(num-1-i);
        pole[i] = getNthNum(search/help+1,options,num);
        search = search%(int)help;
    }
}
Пример #8
0
int main(void)
{
    unsigned i, sum = 0;
    char buf[16];

    for (i = 3; i < 100000; i++) {
        unsigned j, s = 0;

        snprintf(buf, sizeof buf, "%u", i);
        for (j = 0; buf[j] != 0; j++) {
            s += fact(buf[j]-'0');
        }
        if (i == s) {
            sum += s;
        }
    }
    printf("%u\n", sum);

    return 0;
}
Пример #9
0
 void Chunk::toPrettyString(std::ostream &o, size_t indent) const{
   if (!p){
     o << std::string(indent, ' ') << "INVALID CHUNK" << std::endl;
     return;
   }
   switch (Bit::btohl(p)){
   case 0x52494646lu: // RIFF
   case 0x4C495354lu: // LIST
     return ListChunk(p).toPrettyString(o, indent);
   case 0x666D7420: // "fmt "
     return fmt(p).toPrettyString(o, indent);
   case 0x66616374: // fact
     return fact(p).toPrettyString(o, indent);
   case 0x49534654: // ISFT
     return ISFT(p).toPrettyString(o, indent);
   default:
     o << std::string(indent, ' ') << "[" << getType() << "] UNIMPLEMENTED ("
       << (getPayloadSize() + 8) << "b)" << std::endl;
   }
 }
int findRank (char* str)
{
	int len = strlen(str);
	int mul = fact(len);
	int rank = 1;
	int countRight;

	int i;
	for (i = 0; i < len; ++i)
	{
		mul /= len - i;

	
		countRight = findSmallerInRight(str, i, len-1);

		rank += countRight * mul ;
	}

	return rank;
}
Пример #11
0
static SCM
_wrap_fact (SCM s_0)
{
#define FUNC_NAME "fact"
  int arg1 ;
  SCM gswig_result;
  SWIGUNUSED int gswig_list_p = 0;
  int result;
  
  {
    arg1 = (int) scm_to_int(s_0);
  }
  result = (int)fact(arg1);
  {
    gswig_result = scm_from_signed_integer(result);
  }
  
  return gswig_result;
#undef FUNC_NAME
}
Пример #12
0
int main(){

    const ll MOD = 1e9 + 7;

    ll n; scanf("%lld", &n);
    std::vector<ll> fact(2 * n + 1, 1);
    for(ll p = 2; p <= 2 * n; p++){fact[p] = p * fact[p - 1] % MOD;}

    std::vector<ll> modInv(n + 2, 1);
    for(ll p = 2; p <= n + 1; p++){modInv[p] = (MOD - ((MOD / p) * modInv[MOD % p] % MOD)) % MOD;}

    ll cur(1), ans(0);
    for(ll k = 1; k <= n + 1; k++){
        cur *= ((n + k) * modInv[k] % MOD); cur %= MOD;
        ans += cur; ans %= MOD;
    }

    printf("%lld\n", ans);

    return 0;
}
Пример #13
0
								int main(void)

								{

								    int n;

								    printf("Ó‹Ëã1*2+2*3+3*4+...+(n-1)*n\n");

								    printf("ՈݔÈën£º");

								    scanf("%d",&n);

								     

								    printf("´ð°¸ÊÇ£º%d", fact(n,0));

								     

								    return 0;

								}
Пример #14
0
int *minFinder(int *arr, int p){
	int i, count = 0,product=1,*dup_count;
	dup_count = (int *)malloc(sizeof(int)* 11);
	for (i = 0; i < 11; i++)
		dup_count[i] = 0;
	for (i = p - 1; i >= 0; i--){
		if (arr[i] <= arr[p]){
			if (dup_count[arr[i]] < 1)
				count++;
			dup_count[arr[i]] += 1;
		}
	}
	for (i = 0; i < 10; i++){
		if (dup_count[i] != 0)
			product *= fact(dup_count[i]);
		//dup_count[i] = 0;
	}
	//dup_count[10] = count;
	dup_count[10] = product;
	return dup_count;
}
Пример #15
0
int Solution::uniquePaths(int A, int B) {
    // Do not write main() function.
    // Do not read input, instead use the arguments to the function.
    // Do not print the output, instead return values as specified
    // Still have a doubt. Checkout www.interviewbit.com/pages/sample_codes/ for more details
    
    int x = A-1;
    int y = B-1;
    
    if(x == 0 || y == 0){
        return 1;
    }
    
    int small = x;
    if(y < x){
        small = y;
    }
    int ans = int (permute(x+y, small)/fact(small));
    
    return ans;
}
Пример #16
0
int main()
{
    int num;
    int result;
 
    printf("Enter the number \n ");
    scanf("%d", &num);

    if (num < 0)
    {
        printf("cant calcutate factorial of negative numbers\n");
    }
    else
    {
        result = fact(num);
        
        printf("The Factorial of %d is %d.\n", num, result);
    }
    return 0;

}
Пример #17
0
int main(void){
  unsigned int digit = 10, limit = fact(10);
  unsigned int j,sum=0,hits=0;
   
  while(next_perm()){
    if(unusual()){
      results = realloc(results,(hits+1)*sizeof *results);
      results[hits] = malloc(len*sizeof *results[0]);
      memcpy(results[hits],perm,len*sizeof perm[0]);
      //printf("%d : ",j);
      printResult(results[hits]);
      hits++;
    }
    //next_perm();
  }
  calc_sum(results,hits);
  print_sum();
  //printf("sum is %d\n",sum);
  
  return 0;
}
Пример #18
0
int main(void)
{
	int num;
	printf("This program calculates factorials.\n");
	printf("Enter a value in the range 0-12 (q to quit):\n");
	while (scanf("%d", &num) == 1)
	{
		if (num < 0)
			printf("No negative numbers, please.\n");
		else if (num > 12)
			printf("Keep input under 13.\n");
		else 
		{
			printf("loop: %d factorial = %ld\n", num, fact(num));
			printf("recursion: %d factorial = %ld\n", num, rfact(num));
		}
		printf("Enter a value in the range 0-12 (q to quit):\n");
	}
	printf("Bye.\n");
	return 0;
}
Пример #19
0
void main()
{
    int i=0,j,k,c,y,res,n,l;
    int a[50],b[50];
    scanf("%d",&n);
    while(n!=0)
    {
        a[i]=n%10;
        n=n/10;
        i++;
    }
    k=i;
    l=k;
    for(i=0; i<k; i++)
    {
        b[l]=a[i];
        l--;
    }
    y=0;
    l=k;
    for(i=1; i<l; i++)
    {
        c=0;
        res=0;
        for(j=i+1; j<l+1; j++)
        {
            if(b[i]>b[j])
            {
                c++;
            }
        }
        if(c!=0)
        {
            res=c*fact(k-1);
        }
        y=y+res;
        k--;
    }
    printf("%d",y);
}
Пример #20
0
void test_rec()
{
    printf("\tTesting Recursion Algorithms...\n\n");

    long num = 20;
    printf("factorial of %ld = %ld\n", num, fact(num));

    int len = 10000;
    int i = 0;

    int numbers[len];

    for (i = 0; i < len; ++i)
        numbers[i] = i + 1;

    printf("sum of array = %d\n", sumArray(numbers, len));
    printf("largest in array = %d\n", largest(numbers, len));
    printf("largest in array = %d\n", largest2(numbers, 0, len - 1));

    int big_num = 203041;
    printf("sum of digits of %d = %d\n", big_num, sumOfDigits(big_num));
}
Пример #21
0
int main(int argc, char **argv) {
    int res, n;

    if (argc == 1) {
        printf("usage:  %s n\n\n", argv[0]);
        printf("\tFor nonnegative argument 'n', the program prints n!.\n\n");
        return 1;
    }

    res = sscanf(argv[1], "%d", &n);
    if (res != 1) {
        printf("Unparseable input \"%s\".\n\n", argv[1]);
        return 1;
    }
    if (n < 0) {
        printf("%d is less than 0.\n\n", n);
        return 1;
    }

    printf("%d! = %d\n\n", n, fact(n));

}
Пример #22
0
void main()
{
int t,l;
unsigned long* n = NULL;
unsigned long nn;
unsigned long in=0;
void fact(unsigned long nn);
clrscr();
try
{
cin>>t;
if(t>2000)
	{
		throw 1;
	}
	n = new unsigned long[t];
	for(int l=0;l<t;l++)
	{
		cin>>in;
		if(in>=(10^9))
		{
			n[l]=in;
		}
		else
		{
			throw 2;
		}
	}
	for(l=0;l<t;l++){
	fact(n[l]);
	cout<<endl;
}
}
catch(int)
{
	cout<<"invalid input";
}
getch();
}
Пример #23
0
main()
{
char arr[30];
printf("Enter the word whose permutations is to be found --> ");
scanf("%s",arr);
int len=strlen(arr);
int k=fact(len);
Node* perm[k];
int i,j;
for(i=0;i<k;i++)
{
perm[i]=malloc(sizeof(Node));
perm[i]->next=0;
}


for(j=0;j<len;j++)
{
 int count=1;
 for(i=0;i<k;i++)
 {
 Node* temp=malloc(sizeof(Node));
 temp->a=arr[j];
 temp->next=0;

 insert(perm[i],temp,count);
 count++;
 if(count==j+2)
 count=1;
 }
}

for(i=0;i<k;i++)
{
printf("\n%d\t",i+1);
display(perm[i]->next);
}
getch();
}
Пример #24
0
int main(){
    int n, s;
    int i, max, count;

    while(scanf("%d %d", &n, &s)==2){
        if(DEBUG)
            printf("%d %d\n", n, s);

        count = 0;
        max = fact(n);
        for(i=0;i<max;i++){
            if(hash2sum(n, i) == s){
                if(DEBUG)
                    printf("%d\n", i);
                count++;
            }
        }
        printf("%d\n", count);
    }

    return 0;
}
Пример #25
0
long long count_repeat(char* S,int l,long long* A)
{
            int alpha[27];
            int i,m;
            for(i=0 ; i < 27 ; i++)
            {
                alpha[i] = 0;
            }
            for(i=0;i<l;i++)
            {
                m = ((int)S[i])-65+1;
                alpha[m] += 1;
            }
            long int val = 1;
            for(i=1;i<27;i++)
            {
                if(alpha[i] > 1 )
                {
                    val *= fact(alpha[i],A);
                }
            }
            return val;
}
Пример #26
0
void MenuState::bootstrapMenu() {
	EntityFactory fact(getEngines());
	auto bullet = fact.createFromTemplateName<SingleVisualEntity>("bullet",
			Vector2(0.0f, 0.0f));
	bullet->getActiveVisual().get().setIngame(
			getEngines().renderEngine().getScreenTransform(),
			Vector2(0.0f, 0.0f), false);
	m_currentItemPointer = bullet.get();
	m_currentItem = -1;

	getEngines().entityEngine().addEntity(std::move(bullet),
			&getManagedEntityList());

	auto loadingScreen = fact.createFromTemplateName<SingleVisualEntity>(
			"loading-screen", Vector2(10.5f, 7.0f));
	loadingScreen->getActiveVisual().get().setIngame(
			getEngines().renderEngine().getScreenTransform(),
			Vector2(10.5f, 7.0f), false);
	loadingScreen->getActiveVisual().get().setVisible(false);
	m_loadingPane = loadingScreen.get();
	getEngines().entityEngine().addEntity(std::move(loadingScreen),
			&getManagedEntityList());
}
Пример #27
0
int main() {
	freopen("bynumber.in", "rt", stdin);
	freopen("bynumber.out", "wt", stdout);

	scanf("%d %d", &N, &M);
	for (int i = N - 1; i >=0; i--) {
		int iFact = fact(i);
		int ind = M / iFact;
		M %= iFact;
		int pos = 0;
		for (int j = 0; j < N; j++) {
			if (color[j]) continue;
			if (pos == ind) {
				printf("%d ", j + 1);
				color[j] = 1;
				break;
			}
			pos++;
		}
	}

	return 0;
}
Пример #28
0
int main()
{
    int i,m,n,f,sum=0,fsum=0,j;
    scanf("%d%d",&n,&m);
    int a[n];
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
    for(i=0;i<n;i++)
    {
        fsum=0;
        for(j=1;j<=a[i];j++)
        {
            f=j*(fact(j)+a[i]);
            fsum=fsum+f;

        }

        sum=sum+fsum;

    }
    printf("%d",(sum%m));
    return 0;
}
Пример #29
0
int64_t test(bool fSimple, int64_t cItems, int64_t * aArray)
{
   int64_t minramp = rampValue(cItems,0);
   int64_t maxramp = minramp;
   int64_t last = minramp;


   for (int64_t i = 0; i < cItems; ++i) {
      int64_t initialValue = rampValue(cItems, i);

      if (initialValue < minramp) {
         minramp = initialValue;
      }

      if (initialValue > maxramp) {
         maxramp = initialValue;
      }

      if (initialValue < last) {
         printf("Bad Ramp! index:%d  last:%d cur:%d", i, last, initialValue);
      }

      int64_t expectedValue;
      if (fSimple) {
         expectedValue = -initialValue;
      }
      else {
         expectedValue = fact(initialValue);
      }

      if (aArray[i] != expectedValue) {
         printf("Error! index:%d value:%d expected:%lld\n", i, aArray[i], expectedValue);
      }
   }

   printf("min: %d, max: %d\n", minramp, maxramp);
}
Пример #30
0
int main(int argc, char** argv) {
    const int n = 500;
    //OPTITEST::DejongProblemFactory fact(n, -4, 8);


    //OPTITEST::Ackley1ProblemFactory fact(std::vector<std::pair<double,double>>(n, std::pair<double, double>(-4,8)));
    OPTITEST::RosenbrockProblemFactory fact(n, -2, 5);
    COMPI::MPProblem<double> *mpp = fact.getProblem();

    /*
    auto obj = std::make_shared<COMPI::FuncCnt<double>>(mpp->mObjectives.at(0));
    mpp->mObjectives.pop_back();
    mpp->mObjectives.push_back(obj);
     */

    LOCSEARCH::CTCoordinateDescent<double> desc(*mpp);
    desc.getOptions().mHInit = .1;
    //desc.getOptions().mHLB = 1e-10;
    //desc.getOptions().mParallelMode = false;
    desc.getOptions().mNumThreads = 6;
    desc.getOptions().mGradLB = 0;

    double x[n];
    snowgoose::BoxUtils::getCenter(*(mpp->mBox), x);
    double v;
    auto start = std::chrono::steady_clock::now();
    bool rv = desc.search(x, v);
    auto end = std::chrono::steady_clock::now();
    auto diff = end - start;
    std::cout << desc.about() << "\n";
    std::cout << "Found v = " << mpp->mObjectives.at(0)->func(x) << "\n";
    //std::cout << " at " << snowgoose::VecUtils::vecPrint(n, x) << "\n";
    //std::cout << "Number of objective calls is " << obj->mCounters.mFuncCalls << "\n";
    //SG_ASSERT(v <= 0.01);
    std::cout << "Execution time = " << std::chrono::duration <double, std::milli> (diff).count() << " ms" << std::endl;
    return 0;
}