prime number

question:

By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6^(th) prime is 13.
What is the 1001^(st) prime number?
answer:
  #include
#include
void main()
{
 long int i,j,prime,count=0;
 clrscr();
 for(i=2;i<10000;i++)
 {
  prime=1;
  for(j=2;j<=i/2;j++)
   {
    if(i%j==0)
     {
      prime=0;
     }
   }
   if(prime==1)
   {
    count=count+1;
    if(count==1001)
    {
    printf("%ld is prime\n",i);
    break;
    }
   }
  }
  printf("count is %ld",count);
  getch();
}
answer:7927

posted under , | 0 Comments

Differance between sum square and square sum

question:

The sum of the squares of the first ten natural numbers is,
1^(2) + 2^(2) + ... + 10^(2) = 385
The square of the sum of the first ten natural numbers is,
(1 + 2 + ... + 10)^(2) = 55^(2) = 3025
Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 − 385 = 2640.
Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
answer:
#include
#include
void main()
{
 long int i,sum=0,sq=0;
 clrscr();
 for(i=0;i<=100;i++)
 {
  sum=sum+i;
  sq=sq+(i*i);
 }
 printf("sum sq=%ld,sq=%ld,diff=%ld",sum*sum,sq,(sum*sum)-sq);
 printf("over");
 getch();
}

output:25164150

posted under , | 0 Comments

palindromic number

hello friends,
recently i have started working on projecteular.net which tests our programming skill... so i have created few programs... those codes are here..one after other
question:
A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.
Find the largest palindrome made from the product of two 3-digit numbers.

answer:
#include
#include
void main()
{
 long int d0,d3,d2,d1,d5,d4,i,j,l,max=0;;
 clrscr();
 for(l=999;l>100;l--)
 for(i=999;i>100;i--)
  {
   j=l*i;
// j=986689;
   d5=(j%10);
   d4=((j-d5)%100)/10;
   d3=((j-d5-d4)%1000)/100;
   d2=((j-d5-d4-d3)%10000)/1000;
   d1=((j-d5-d4-d3-d2)%100000)/10000;
   d0=((j-d5-d4-d3-d2-d1)%1000000)/100000;
   if(d0==d5)
    if(d1==d4)
     if(d2==d3)
      {
       printf("l=%ld,i=%ld,j=%ld\n",l,i,j);
       if(max
       max=j;
      }
  }
 printf("max is %ld",max);
 getch();
}

Answer:906609

posted under , | 0 Comments
Newer Posts Older Posts Home

About Me

My photo
Hi everyone,myself Alagappan...electronic and communication engg. student... living in madurai... interested in everything... want to achieve something great in my lifetime...

Followers


Recent Comments