Friday, April 4, 2014

Write a program that repeatedly collects positive integers(only)


Write a program that repeatedly collects positive integers from the user, stopping when the user enters a negative number or zero.
+/- Click and see the code that is about the article.
#include 
int main() {

int number,product=1,counter=0; 
for (counter=0;counter<=10;counter++) 
{
 counter=1;
 printf("Enter a number : ");
 scanf("%d",&number);
 if (number>0)
 {
  product=number*product;
  continue;
  
 }
 else break;
 
}
 printf("%d",product);
}

Thursday, April 3, 2014

Sum square difference

The sum of the squares of the first ten natural numbers is,
12 + 22 + ... + 102 = 385

The square of the sum of the first ten natural numbers is,
(1 + 2 + ... + 10)2 = 552 = 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.
+/- Click and see the code that is about the article.
#include 

int main ()

{
 int counter,first,second=0,third=0,last,finally;
 
 for (counter=1;counter<=100;counter++)
 
 {
  first=counter*counter;
  second +=first;
 }
  printf("First : %d\n",second);

 for (counter=1;counter<=100;counter++)
 
 {
  third+=counter;
  last=third*third;
 }
  printf("Second : %d\n",last);
        finally=last-second;
  printf("Diffirence : %d\n",finally);

}

What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?



2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.

What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?

+/- Click and see the code that is about the article.
/* source : freelearncprogramming.blogspot.com */


#include <stdio.h>

int main ()

{
int counter;

for (counter=1;counter<=400000000000;counter++)

{
if (counter%1) {
continue;
}
else if (counter%2)
{
continue;

}
else if (counter%3)
{
continue;

}
else if (counter%4)
{
continue;

}
else if (counter%5)
{
continue;

}
else if (counter%6)
{
continue;

}
else if (counter%7)
{
continue;

}
else if (counter%8)
{
continue;

}
else if (counter%9)
{
continue;

}
else if (counter%10)
{
continue;

}
else if (counter%11)
{
continue;

}
else if (counter%12)
{
continue;

}
else if (counter%13)
{
continue;

}
else if (counter%14)
{
continue;

}
else if (counter%15)
{
continue;

}
else if (counter%16)
{
continue;

}
else if (counter%17)
{
continue;

}
else if (counter%18)
{
continue;

}
else if (counter%19)
{
continue;

}
else if (counter%20)
{
continue;

}

printf("%d\n",counter);
break;
}


}