Sponsored Content
Top Forums Programming Programming Challenges - A List Post 302120584 by matrixmadhan on Thursday 7th of June 2007 06:59:49 AM
Old 06-07-2007
Quote:
Originally Posted by blowtorch
Challenge: DRAM

Difficulty: Easy to Medium in C, Easy in perl/python

As the problem says, the value of the palindrome may exceed your system's defined integer size in C/C++.
Here is my shot! Smilie

Code:
#include <stdio.h>

int reverseCheck(unsigned long);

int main()
{
  unsigned long number = 2468;
  unsigned long tmp = 0;

  while ( tmp != number ) {
    tmp = reverseCheck(number);
    if( tmp == number ) {
      tmp = number;
    }
    else {
      number += tmp;
    }
  }

  printf("Number:%d\n", number);

  return 0;
}

int reverseCheck(unsigned long number) {
  unsigned int i;
  unsigned long num;
  unsigned long sum;

  for( num = number, i=1; num / 10; i *= 10, num /= 10 );
  for( sum = 0; number > 0; sum += (number % 10) * i, number /= 10, i /= 10);

  return sum;
}

 

3 More Discussions You Might Find Interesting

1. AIX

AIX 6.1 IDSLDAP Installation Challenges

Please bare with me, since I am new to AIX and LDAP. I am attempting to install idsldap server on our AIX 6.1 NIM server. I installed the following packages: root@nim(/)# lslpp -l|grep ldap db2_08_01.ldap 8.1.1.80 COMMITTED DB2 LDAP Support idsldap.clt64bit61.rte 6.1.0.17 COMMITTED... (6 Replies)
Discussion started by: ecollins
6 Replies

2. UNIX for Advanced & Expert Users

Challenges in finding and copying the block

Hi, I have a below challenging task where iam unable to find the block and copy the same into a file. I tried my luck,howver iam unable to reach the first and second step..Can anyone help me with a clue or with the commands so that i can give a try. 1. search the <number>9966993366</number>... (2 Replies)
Discussion started by: cskumar
2 Replies

3. Shell Programming and Scripting

Korn shell script - SQL statement challenges

Hi scripting experts. I have some coding challenges that I'm hoping you can help me out. I have one file#1 that contains the following sql statement that spans over multiple lines: sql Select /*+ use_has(a,b) */ * from customer a, customer_address b where a.id = b.id... (1 Reply)
Discussion started by: pchang
1 Replies
SYSINFO(2)						     Linux Programmer's Manual							SYSINFO(2)

NAME
sysinfo - returns information on overall system statistics SYNOPSIS
#include <sys/sysinfo.h> int sysinfo(struct sysinfo *info); DESCRIPTION
Until Linux 2.3.16, sysinfo used to return information in the following structure: struct sysinfo { long uptime; /* Seconds since boot */ unsigned long loads[3]; /* 1, 5, and 15 minute load averages */ unsigned long totalram; /* Total usable main memory size */ unsigned long freeram; /* Available memory size */ unsigned long sharedram; /* Amount of shared memory */ unsigned long bufferram; /* Memory used by buffers */ unsigned long totalswap; /* Total swap space size */ unsigned long freeswap; /* swap space still available */ unsigned short procs; /* Number of current processes */ char _f[22]; /* Pads structure to 64 bytes */ }; and the sizes were given in bytes. Since Linux 2.3.23 (i386), 2.3.48 (all architectures) the structure is struct sysinfo { long uptime; /* Seconds since boot */ unsigned long loads[3]; /* 1, 5, and 15 minute load averages */ unsigned long totalram; /* Total usable main memory size */ unsigned long freeram; /* Available memory size */ unsigned long sharedram; /* Amount of shared memory */ unsigned long bufferram; /* Memory used by buffers */ unsigned long totalswap; /* Total swap space size */ unsigned long freeswap; /* swap space still available */ unsigned short procs; /* Number of current processes */ unsigned long totalhigh; /* Total high memory size */ unsigned long freehigh; /* Available high memory size */ unsigned int mem_unit; /* Memory unit size in bytes */ char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding for libc5 */ }; and the sizes are given as multiples of mem_unit bytes. sysinfo provides a simple way of getting overall system statistics. This is more portable than reading /dev/kmem. For an example of its use, see intro(2). RETURN VALUE
On success, zero is returned. On error, -1 is returned, and errno is set appropriately. ERRORS
EFAULT pointer to struct sysinfo is invalid CONFORMING TO
This function is Linux-specific, and should not be used in programs intended to be portable. The Linux kernel has a sysinfo system call since 0.98.pl6. Linux libc contains a sysinfo() routine since 5.3.5, and glibc has one since 1.90. SEE ALSO
proc(5) Linux 2.0 1997-08-25 SYSINFO(2)
All times are GMT -4. The time now is 01:24 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy