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;
}


}

Thursday, March 13, 2014

Mathematical operators

Mathematical expressionsExpressed in the CProcess
. X or nothing*multiplication
Mode%Modular quotient
//Quotient
+1++Unary increment
-1--Unary decrement
++Sum
--Difference

The expression of meaning may change for operator location. The right or left is important.
headerheader
A++ (postincrement)Firstly use A, than add 1 to the number.
++A ( preincrement )Firstly add 1 to the A, after use number.
A -- ( postdecrement )Firstly use A, than subtract 1 to the number.
-- A ( predecrement )Firstly subtract 1 to the A, after use number.


An example of a difference in meaning of change unory operator location; For example, should it be : a=4, b=5

headerheaderheaderheaderheaderheader
c=a++ *bc=a*b
a=a+1
c=4*5=20
a=4+1=5
a=5b=5c=20
c=++a–ba=a+1
c=a - b
a=4+1=5
c=5 - 5=0
a=5b=5c=0
c= -- a + b --a=a+1
c=a+b
b=b - 1
a=4 - 1=3
c=3+5=8
b=5 - 1=4
a=3b=4c=8
+/- Click and see the code that is about the article.
/* source : freelearncprogramming.blogspot.com */
#include <stdio.h>
main ()
{
int a,b,c;
float c1;
a=4;
b=5;
c=a++*b ;
c1=++a-b ;
printf ("c = %d \n",c);
printf ("c1 = %d \n",c1);
return 0;
}

Operators

Operators are symbols that used to perform mathematical, logical and assignment operations. These operators and the values ​​into the process is called operand. Operators can receive more than one operand. Operator that has one operand is called unary operators. The operators used in C language is analyzed in three groups.
  1. Mathematical,
  2. Logical,
  3. Assignment operators.

Main function

Almost all C programs consist of multiple functions. main () that should be found in all C programs is the program's main function. The function will be executed firstly is main (). The statements (lines of code) will be executed in the program {-} are written in curly brackets. The structure of each of the statements of brackets is called code blocks. A block of code has variables that is used in the program and commands to perform operations to be performed.

An example
 

+/- Click and see the code that is about the article.
/* The first C program */
/* We will see "Hello World !" on the screen. */
/* source : freelearncprogramming.blogspot.com */

#include <stdio.h>

main ()

{
printf("Hello World !");

return 0;

}

Preprocessor directives

Preprocessor directives starts with '#' and operate by the preprocessor before the program is compiled. Each preprocessor directives has a different function. #include and #define directives are most commonly used. #include directive is used in the program to include required code for the codes used for functions. For example, we have designed a program and we want to print the output to the screen. For this, we have to use printf function that is a standard function of the C language.
Printf ("Sample Output");
However, in order to run the printf function, we need to have files. To include this file to the program, #include <stdio.h> command line is written to the top of the program. Files with .h extension is called Header File in the C programming language. <stdio.h> header file contains the necessary codes for standard input-output operations.