<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0"><id>tag:blogger.com,1999:blog-22017830</id><updated>2012-04-30T01:32:41.856+02:00</updated><title type="text">C Lessons Project</title><subtitle type="html">Learn C programming from these daily lessons. They're twelve days ahead of you already so get busy...</subtitle><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://visualcplus.blogspot.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://visualcplus.blogspot.com/" /><link rel="next" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default?start-index=26&amp;max-results=25" /><author><name>Vurdlak</name><uri>http://www.blogger.com/profile/08849999795183163370</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="20" height="32" src="http://img3.imageshack.us/img3/5296/saxophone35qd.jpg" /></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>36</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/CTutorial" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="ctutorial" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry><id>tag:blogger.com,1999:blog-22017830.post-114308487978795118</id><published>2006-03-23T04:33:00.000+01:00</published><updated>2007-01-12T12:37:07.150+01:00</updated><title type="text">Lesson 19: C Programming Examples</title><content type="html">I’ve based this lesson on a single program example. This part of C programming tutorial has dual purpose: firstly to teach you how to apply previously learned C/C++ knowledge, second: to show you how pointers, arrays, functions and matrixes can be combined together in one single program.


Example:

Maximal number of rows and columns matrix can have is predefined. Write your own main program which reads given number of matrix’s rows and columns, and additionally reads matrix’s given elements. Main program prints:


Matrix’s elements sum (calls upon a function that calculates elements sum)
Maximal value in every row of a matrix (calls upon a function that finds the biggest element in a flow)


Matrix mat is declared in a way of two dimensional array (2D array):


float mat[MAXROW][MAXCOL];
Variables nrRow and nrCol store matrix’s dimensions provided by user. The image below shows you this in a visual way. Click on the image to enlarge it.





Memory of a computer allocates MAXROW * MAXCOL * sizeof(float) byte. Matrix’s rows follow one after another, in a way where every next row is placed right after the previous one; and so on. Picture below describes this perfectly. Click on the image to enlarge it.





Generally speaking, for mat[i][j] – number of elements from the beginning of an array is: i * MAXCOL + j


#include &amp;lt;stdio.h&amp;gt;
#define MAXROW     100
#define MAXCOL     100


float max( int len, float *p ) {
// OR: float max( int len, float p[] )

   float res;
   int i;

printf("\nIn function max :");
   printf("\nRow’s beginning address
         in memory : %ld", p);
   res = p[0];
   for( i=1; i&amp;lt;len; i++ )
      if( p[i] &amp;gt; res )
         res = p[i];
   return res;
}


float sumEl(int nrRow,int nrCol,
        int maxCol,float *mat) {

int i, j;
   float sum;

   printf("\nIn function sumEl:");
   printf("\nMatrix’s beginning address
         in memory: %ld", mat);
printf("\nBegin. of 2nd row’s addr.
         in mem.: %ld", &amp;mat[maxCol]); 
  ...&lt;br/&gt;
&lt;br/&gt;
Visit the link for full lesson</content><link rel="replies" type="application/atom+xml" href="http://visualcplus.blogspot.com/feeds/114308487978795118/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=22017830&amp;postID=114308487978795118" title="11 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114308487978795118" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114308487978795118" /><link rel="alternate" type="text/html" href="http://visualcplus.blogspot.com/2006/03/lesson-19-c-programming-examples.html" title="Lesson 19: C Programming Examples" /><author><name>Vurdlak</name><uri>http://www.blogger.com/profile/08849999795183163370</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="20" height="32" src="http://img3.imageshack.us/img3/5296/saxophone35qd.jpg" /></author><thr:total>11</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22017830.post-114279985252045694</id><published>2006-03-19T21:23:00.000+01:00</published><updated>2006-10-03T07:48:05.996+02:00</updated><title type="text">Lesson 18: Pointers and Stacks in C</title><content type="html">Today's lesson goes more into details about pointers and their usage as function's arguments. Additional tutorial about stacks in C and C++ is provided. Be sure to read this lesson carefully in order to understand it, since pointers are most important part of C programming language. 



Transferring Argument’s Address into a Function (call by reference)

Write your own function that changes polar coordinates into Cartesian coordinates, and show how this function is called upon from main program.


#include &amp;lt;math.h&amp;gt;

void cart(float r, float fi, float *x, float *y) {

  *x = r*cos(fi); // x address:1244956,value:1245052
                  //*x address:1245052,value:1.755165

  *y = r*sin(fi); // y address:1244960,value:1245048
                  //*y address:1245048,value:0.958851

}

Main program slice:

float x, y;            // x address:1245052,value:?
                       // y address:1245048,value:?

float fi = 0.5, r = 2; //fi address:1245044,value:0.5
                       // r address:1245040,value:2

cart(r, fi, &amp;x, &amp;amp;y);

printf("x=%f y=%f",x,y);

               // x address:1245052, value:1.755165
               // y address:1245048, value:0.958851




Question: 

What would happen if the function looked like this?


void cart(float r, float fi, float *x, float *y) {

   x = 10000;
  *x = r * sin(fi);
  *y = r * cos(fi);

}


Important: 

Function is able to return single value through its “return” order. In order to return more values (in this case x &amp; y), we can return them through arguments (Call by Reference).




Example:

Write your own function that returns numerator and denominator of a fraction. This fraction is a sum of two fractions, whose two numerators and two denominators are given by user. Function also shortens the fraction if possible, before returning values. Augends numerators and denominators are integers.

(Fraction example: 5/9, Numerator: 5, Denominator: 9)


void addFractions(int nrator1,int denom1,
                int...&lt;br/&gt;
&lt;br/&gt;
Visit the link for full lesson</content><link rel="replies" type="application/atom+xml" href="http://visualcplus.blogspot.com/feeds/114279985252045694/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=22017830&amp;postID=114279985252045694" title="3 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114279985252045694" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114279985252045694" /><link rel="alternate" type="text/html" href="http://visualcplus.blogspot.com/2006/03/lesson-18-pointers-and-stacks-in-c.html" title="Lesson 18: Pointers and Stacks in C" /><author><name>Vurdlak</name><uri>http://www.blogger.com/profile/08849999795183163370</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="20" height="32" src="http://img3.imageshack.us/img3/5296/saxophone35qd.jpg" /></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22017830.post-114244909874600582</id><published>2006-03-15T19:58:00.000+01:00</published><updated>2006-12-20T08:18:04.836+01:00</updated><title type="text">Lesson 17: Pointers in C</title><content type="html">After three days of waiting, C++ Maniac brings you another interesting lesson. This one is labeled no. 17, and I think moment has come when I can proudly say we have crossed a half-way of my complete C Tutorial; at least first part of it, “C Programming In General”. This Lesson is about Pointers and their useful implementation in Your future C programs. Let’s start…



Important:

Examples are translated using Microsoft Visual C++ compiler.



Example:

What will be printed after execution of a following program block?

int a = 5;  //a address:1245052, value:5


int *b;     //a address:1245052, value:5
            //b address:1245048, value:?


 b = &amp;a;    //a address:1245052, value:5
            //b address:1245048, value:1245052

*b = 6;     //a address:1245052, value:6
            //b address:1245048, value:1245052


printf("a = %d *b = %d\n", a, *b);
printf("a = %d b = %ld\n", a, b);
printf("&amp;a = %ld &amp;amp;b = %ld\n", &amp;a, &amp;amp;b);


Result:

a = 6 *b = 6
a = 6  b = 1245052
&amp;a = 1245052 &amp;amp;b = 1245048


Important:

Value that is pointed by variable b is on the same address (b = &amp;a) as the value assigned to variable a.

What would happen if we left out this line: b = &amp;amp;a; ?



Result:

Before assigning value to it, pointer b points to undefined address. This makes it possible for program to store value 6 to an address previously reserved for some other variable or code. This would result in an unexpected behavior or cause an error in program’s execution (because of unauthorized access to memory’s section). 



Typical Mistakes:

scanf(“%d", n);
printf(“%d", &amp;n);


Connection between Pointers and Arrays:


Any declared array’s name can also be used as a pointer. Any pointer can also be used as an array.


What will be printed as a result of following program block?

int x[] = {0, 1, 2};   //x[0] address:1245044, value:0
                       //x[1] address:1245048, value:1
                       //x[2] address:1245052, value:2


printf("&amp;x[0] = %ld x[0] =...&lt;br/&gt;
&lt;br/&gt;
Visit the link for full lesson</content><link rel="replies" type="application/atom+xml" href="http://visualcplus.blogspot.com/feeds/114244909874600582/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=22017830&amp;postID=114244909874600582" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114244909874600582" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114244909874600582" /><link rel="alternate" type="text/html" href="http://visualcplus.blogspot.com/2006/03/lesson-17-pointers-in-c.html" title="Lesson 17: Pointers in C" /><author><name>Vurdlak</name><uri>http://www.blogger.com/profile/08849999795183163370</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="20" height="32" src="http://img3.imageshack.us/img3/5296/saxophone35qd.jpg" /></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22017830.post-114212495410706810</id><published>2006-03-12T01:54:00.000+01:00</published><updated>2006-11-30T03:13:57.176+01:00</updated><title type="text">Lesson 16: Functions in C</title><content type="html">Functions are essential part of code in C and C++ language, so be sure to carefully read this lesson. You’ll notice there’s nothing to be afraid of – they are really easy to understand, and sometimes, can lighten up our program code significantly. In a way, they remind us of our main program. Functions usually return value that we use in our main block, but sometimes they return nothing. Either way, they do their task: like printing on screen or calculating equations. C++ Maniac presents you another interesting tutorial!


Example:

Write your own function that calculates arithmetic middle of three real numbers. Write additional main program that stores given three numbers and calls on your previous function, and then prints calculated arithmetic middle.


#include &amp;lt;stdio.h&amp;gt;

float arit_midd( float a, float b, float c ){

  float ar;
  ar = (a + b + c) / 3;
  return ar; // How many values “return” may return?

}


int main(void) {

   float x, y, z, midd;
   printf("\nInput three real numbers : ");
   scanf("%f %f %f", &amp;x, &amp;amp;y, &amp;z );
   midd = arit_midd(x,y,z);
   printf("\nArithmetic middle : %f", midd);

}



Example:

What will be printed after execution of a program that calls on a function?


void twotimes(int x) {

  printf ("\nF:Argument before change took place %d",x);
  x *= 2;
  printf ("\nF:Argument after tempering with it %d",x);

}


int main(void) {

  int number=10;
  printf ("\nM:Number before function-call %d",number);
  twotimes(number);
  printf("\nM:Number after function-call is %d",number);

}

Result on-screen:

M:Number before function-call 10
F:Argument before change took place 10
F:Argument after tempering with it 20
M:Number after function-call 10



Change inside a function wasn’t saved after execution and return to main program! Why?

int twotimes(int x){

   printf ("\nF:Argument before change took place %d",x);
   x *= 2;
   printf ("\nF:Argument after tempering with it %d",x);
   return x;

}


int main(void) {

   int...&lt;br/&gt;
&lt;br/&gt;
Visit the link for full lesson</content><link rel="replies" type="application/atom+xml" href="http://visualcplus.blogspot.com/feeds/114212495410706810/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=22017830&amp;postID=114212495410706810" title="6 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114212495410706810" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114212495410706810" /><link rel="alternate" type="text/html" href="http://visualcplus.blogspot.com/2006/03/lesson-16-functions-in-c.html" title="Lesson 16: Functions in C" /><author><name>Vurdlak</name><uri>http://www.blogger.com/profile/08849999795183163370</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="20" height="32" src="http://img3.imageshack.us/img3/5296/saxophone35qd.jpg" /></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22017830.post-114202013505934927</id><published>2006-03-10T20:48:00.000+01:00</published><updated>2006-11-01T04:50:15.976+01:00</updated><title type="text">Lesson 15: Matrixes and 2D Arrays</title><content type="html">There was a slight pause in my C++ Maniac programming tutorial, due to me answering some of your C &amp; C++ lesson-related questions. You can find some explanations on previous programming materials in my sidebar now, along with other new C &amp; C++ stuff. It seems to me finally, after all troubleshoots are answered (or are they?!), we can bravely continue. This 15th lesson is about matrixes and two-dimensional C++ arrays. Although this one may look significantly more complicated, if you read through it carefully, you will conquer programming matrixes with no problem – I promise you that. 




Declaration of a 2D array in C language:

int x[3][2] - matrix 3X2 (3 rows, 2 columns), elements: integers
 char myascii[2][4] - array of characters (2 rows &amp; 4 columns)
 float sequence[MAXROW][MAXCOL] - MAXROW X MAXCOL matrix



Example of declaration with initialization:

int array[3][3] = {1, 2, 3, 4, 5};
array[0][0] = 1
array[0][1] = 2 
array[0][2] = 3 
array[1][0] = 4 
array[1][1] = 5
array[1][2] = 0 // even though nowhere stated
array[2][0] = 0
array[2][1] = 0
array[2][2] = 0





char cmaniac[7] = {'C', 'M', 'A', 'N', 'I', 'A', 'C'} 

/* array of characters */





int y[3][4] = {   {1, 2, 3},
                  {4, 5, 6},
                  {7, 8, 9}   };






y[0][0]= 1    y[0][1]= 2    y[0][2]= 3    y[0][3]= 0
y[1][0]= 4    y[1][1]= 5    y[1][2]= 6    y[1][3]= 0
y[2][0]= 7    y[2][1]= 8    y[2][2]= 9    y[2][3]= 0




Declaration of multidimensional array:

int x[3][2][4]          3D array of integer numbers
float x[3][2][4][1]     4D array of real numbers




Example:

Write your own C program that reads through real matrix, 10x10 dimensioned and finds the smallest element in main diagonal and smallest element in secondary diagonal. 



#include &amp;lt;stdio.h&amp;gt;

#define NR_ROW      10
#define NR_COL      10


int main(void) {

int     i, j;
float mat[NR_ROW][NR_COL], min_maindg, min_secdg;


printf("Input matrix elements :");
for (i = 0; i &amp;lt; NR_ROW; i++) {
  for (j =...&lt;br/&gt;
&lt;br/&gt;
Visit the link for full lesson</content><link rel="replies" type="application/atom+xml" href="http://visualcplus.blogspot.com/feeds/114202013505934927/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=22017830&amp;postID=114202013505934927" title="5 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114202013505934927" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114202013505934927" /><link rel="alternate" type="text/html" href="http://visualcplus.blogspot.com/2006/03/lesson-15-matrixes-and-2d-arrays.html" title="Lesson 15: Matrixes and 2D Arrays" /><author><name>Vurdlak</name><uri>http://www.blogger.com/profile/08849999795183163370</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="20" height="32" src="http://img3.imageshack.us/img3/5296/saxophone35qd.jpg" /></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22017830.post-114178370496724858</id><published>2006-03-08T03:05:00.000+01:00</published><updated>2006-03-11T14:10:40.500+01:00</updated><title type="text">C++ Intermezzo</title><content type="html">Before I continue lecturing and post my 15th Lesson, I’ll give you a slight C++ break. This will be in order to provide you with some additional explanations to previous chapters. This decision is based on comments and questions you've submitted to some of my C and C++ topics (yes I read your posts :) You can see there are some fresh lectures regarding C Numerical Systems and Numeric System Conversions, while further explanations and examples regarding Numeric Data Storage and #include library references will also be provided soon. Remember, some of these chapters aren't necessary for you to obtain C &amp; C++ knowledge, but are great material to understand computer’s logic and “behind curtains” view, of how things work inside the machine. This topic is also a great chance for you to post more questions and proposals for my future in-depth C++ articles. Sorry if the site is gonna look a little messy these days… It’s because I’m adding tons of new C++ stuff ;)

Comments section is temporarly moderated, but feel free to post your questions, It just takes some time for them to show up (after I approve them by hand).


Technorati Tags: Numeric, Numerical, Redesign, Transformation, Feedback, Questions, Intermezzo, Conversion, Numbers, News, Convert, Method
&lt;br/&gt;
&lt;br/&gt;
Visit the link for full lesson</content><link rel="replies" type="application/atom+xml" href="http://visualcplus.blogspot.com/feeds/114178370496724858/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=22017830&amp;postID=114178370496724858" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114178370496724858" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114178370496724858" /><link rel="alternate" type="text/html" href="http://visualcplus.blogspot.com/2006/03/c-intermezzo.html" title="C++ Intermezzo" /><author><name>Vurdlak</name><uri>http://www.blogger.com/profile/08849999795183163370</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="20" height="32" src="http://img3.imageshack.us/img3/5296/saxophone35qd.jpg" /></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22017830.post-114178276644087540</id><published>2006-03-08T02:48:00.000+01:00</published><updated>2007-01-15T14:17:20.666+01:00</updated><title type="text">Hex 2 Binary 2 Octal</title><content type="html">General Method for Transforming Numbers - Number we want to transform uses base X: we would like to transform this number into new one, that uses Y base. In this case we will use method of continuous dividing and multiplying (dividing numbers left of comma (,) with Y and multiplying numbers on the right side of comma, by Y - rational numbers). This method is best understood looking at these examples:


Octal System:

Base: 8
Digits: 0, 1, 2, 3, 4, 5, 6, 7
Example: 27 (decimal) = 33 8 (octal)



Hexadecimal (hex) System:

Base: 16
Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
Example: 27 (decimal) = 1B 16 (hex)



Binary System:

Base: 2
Digits: 0, 1
Example: 27 (decimal) = 11011 2 (binary)




Transforming Binary, Hex and Octal - Quickly


Binary     Hex              Binary       Octal

0000                     0                                  000                       0
0001                     1                                  001                       1
0010                     2                                  010                       2
0011                     3                                  011                       3
0100                     4                                  100                       4
0101                     5                                  101                       5
0110                     6                                  110                       6
0111                     7                                  111                       7
1000                     8
1001                     9
1010                     A
1011                     B
1100                     C
1101                     D
1110                     E
1111                     F




Example

Transform -6F,A 16  into binary number 


-6F,A 16  =  -  0110  1111  ,  1010  2  =  - 1101111 , 101 2  



Example

Transform 11,000011001 2 into hex number 

11,000011001 2   =      11  ,  0000  1100  1  2
                    =  0011  ,  0000  1100  1000 2
...&lt;br/&gt;
&lt;br/&gt;
Visit the link for full lesson</content><link rel="replies" type="application/atom+xml" href="http://visualcplus.blogspot.com/feeds/114178276644087540/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=22017830&amp;postID=114178276644087540" title="6 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114178276644087540" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114178276644087540" /><link rel="alternate" type="text/html" href="http://visualcplus.blogspot.com/2006/03/hex-2-binary-2-octal.html" title="Hex 2 Binary 2 Octal" /><author><name>Vurdlak</name><uri>http://www.blogger.com/profile/08849999795183163370</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="20" height="32" src="http://img3.imageshack.us/img3/5296/saxophone35qd.jpg" /></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22017830.post-114178249217866651</id><published>2006-03-08T02:44:00.000+01:00</published><updated>2006-03-08T02:56:33.206+01:00</updated><title type="text">Hexadecimal 2 Decimal</title><content type="html">Number we want to transform uses base X: we would like to transform this number into new one, that uses Y base. In this case we will use method of continuous dividing and multiplying (dividing numbers left of comma (,) with Y and multiplying numbers on the right side of comma, by Y - rational numbers). This method is best understood looking at these examples, where X = 16 (source is hex base, B1=16) and Y = 10 (destination is decimal base, B2=10).



Hexadecimal (hex) System:

Base: 16
Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
Example: 27 (decimal) = 1B 16 (hex)


Decimal System:

Base: 10
Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9



Hex 2 Decimal


     
                 Example

Transform 9EC,570A3 (hex) into decimal number 

9EC, 570A3 16 = 9*162 + 14*161 + 12*160 + 5*16-1 + 7*16-2 + 0*16-3 + 10*16-4 + 3*16-5

                           = 2304 + 224 +12 + 0,3125 + 0,02734375 + 0,0001525878... + 0,00000286102...

                           = 2540 , 33999919891357421875





Technorati Tags: Numeric, Numerical, Transform, Transformation, Binary, Decimal, Octal, Hexadecimal, Hex, Base, Complement, Method

&lt;br/&gt;
&lt;br/&gt;
Visit the link for full lesson</content><link rel="replies" type="application/atom+xml" href="http://visualcplus.blogspot.com/feeds/114178249217866651/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=22017830&amp;postID=114178249217866651" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114178249217866651" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114178249217866651" /><link rel="alternate" type="text/html" href="http://visualcplus.blogspot.com/2006/03/hexadecimal-2-decimal.html" title="Hexadecimal 2 Decimal" /><author><name>Vurdlak</name><uri>http://www.blogger.com/profile/08849999795183163370</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="20" height="32" src="http://img3.imageshack.us/img3/5296/saxophone35qd.jpg" /></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22017830.post-114178222832352109</id><published>2006-03-08T02:39:00.000+01:00</published><updated>2006-11-04T14:19:15.773+01:00</updated><title type="text">Binary 2 Decimal</title><content type="html">Number we want to transform uses base X: we would like to transform this number into new one, that uses Y base. In this case we will use method of continuous dividing and multiplying (dividing numbers left of comma (,) with Y and multiplying numbers on the right side of comma, by Y - rational numbers). This method is best understood looking at these examples, where X = 2, and Y = 10 (binary and decimal base, B1=2, B2=10):


Binary System:

Base: 2
Digits: 0, 1
Example: 27 (decimal) = 11011 2 (binary)


Decimal System:

Base: 10
Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9



Binary 2 Decimal



Example

Transform 110101 (binary) into decimal number


110101 2 = 1*25 + 1*24 + 0*23 + 1*22 + 0*21 + 1*20
          = 1*25 + 1*24 + 1*22 + 1*20
          = 1*32 + 1*16 + 1*4 + 1*1
          = 53 10



Example

Transform -11,101 (binary) into decimal number


-11,101 2 = - (1*21 + 1*20 + 1*2-1 + 0*2-2 + 1*2-3)
         = - (1*21 + 1*20 + 1*2-1 + 1*2-3)
         = - (1*2 + 1*1 + 1*0,5 + 1*0,125)
         = - 3 , 625




Technorati Tags: Numeric, Numerical, Transform, Transformation, Binary, Decimal, Octal, Hexadecimal, Hex, Base, Complement, Method

&lt;br/&gt;
&lt;br/&gt;
Visit the link for full lesson</content><link rel="replies" type="application/atom+xml" href="http://visualcplus.blogspot.com/feeds/114178222832352109/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=22017830&amp;postID=114178222832352109" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114178222832352109" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114178222832352109" /><link rel="alternate" type="text/html" href="http://visualcplus.blogspot.com/2006/03/binary-2-decimal.html" title="Binary 2 Decimal" /><author><name>Vurdlak</name><uri>http://www.blogger.com/profile/08849999795183163370</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="20" height="32" src="http://img3.imageshack.us/img3/5296/saxophone35qd.jpg" /></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22017830.post-114178188121833695</id><published>2006-03-08T02:33:00.000+01:00</published><updated>2006-07-26T11:06:55.586+02:00</updated><title type="text">Decimal 2 Hexadecimal</title><content type="html">Number we want to transform uses base X: we would like to transform this number into new one, that uses Y base. In this case we will use method of continuous dividing and multiplying (dividing numbers left of comma (,) with Y and multiplying numbers on the right side of comma, by Y - rational numbers). This method is best understood looking at these examples, where X equals 10 and Y equals 16 (hex base, B=16)


Decimal System:

Base: 10
Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9


Hexadecimal (hex) System:

Base: 16
Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
Example: 27 (decimal) = 1B 16 (hex)




Decimal 2 Hex



Example

Transform 2540,34 (decimal) into hex number-result ~  9EC, 570A316


a) left from”,”

2540 : 16 = 158 , remaining 12 =&gt; C        160        last digit
158 : 16 =      9 , remaining 14 =&gt; E        161
 9 : 16 =       0 , remaining   9 =&gt; 9        162        first digit

end of procedure  =&gt; 9EC 16

b) right from “,”  

0,34  * 16 =      5,44       5 =&gt;     5     16-1       first digit after zero
0,44  * 16 =      7,04       7 =&gt;     7     16-2
0,04  * 16 =      0,64       0 =&gt;     0     16-3
0,64  * 16 =    10,24     10 =&gt;     A     16-4
0,24  * 16 =      3,84       3 =&gt;     3     16-5                                    
…
…
procedure could be continued  =&gt; 0, 570A3… 16


Final result ~  9EC , 570A316




Technorati Tags: Numeric, Numerical, Transform, Transformation, Binary, Decimal, Octal, Hexadecimal, Hex, Base, Complement, Method




&lt;br/&gt;
&lt;br/&gt;
Visit the link for full lesson</content><link rel="replies" type="application/atom+xml" href="http://visualcplus.blogspot.com/feeds/114178188121833695/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=22017830&amp;postID=114178188121833695" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114178188121833695" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114178188121833695" /><link rel="alternate" type="text/html" href="http://visualcplus.blogspot.com/2006/03/decimal-2-hexadecimal.html" title="Decimal 2 Hexadecimal" /><author><name>Vurdlak</name><uri>http://www.blogger.com/profile/08849999795183163370</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="20" height="32" src="http://img3.imageshack.us/img3/5296/saxophone35qd.jpg" /></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22017830.post-114178093106411591</id><published>2006-03-08T02:21:00.000+01:00</published><updated>2006-10-07T11:33:05.483+02:00</updated><title type="text">Decimal 2 Binary</title><content type="html">Number we want to transform uses base X: we would like to transform this number into new one, that uses Y base. In this case we will use method of continuous dividing and multiplying (dividing numbers left of comma (,) with Y and multiplying numbers on the right side of comma, by Y - rational numbers). This method is best understood looking at these examples where X equals 10 (decimal base, B=10), and Y eqauls 2 (binary base, B=2)


Decimal System:

Base: 10
Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9


Binary System:

Base: 2
Digits: 0, 1
Example: 27 (decimal) = 11011 2 (binary)




Decimal 2 Binary



Example

Transform 29 (decimal) into binary number - reading upwards, result is 111012


29 : 2 =  14 , remaining 1   20            last (smallest) digit
14 : 2 =    7 , remaining 0   21
  7 : 2 =    3 , remaining 1   22
  3 : 2 =    1 , remaining 1   23    
  1 : 2 =    0 , remaining 1   24            first digit
- end of procedure





Example

Transform 0,8125 (decimal) into binary number – reading downwards, result is 0,11012


0,8125  * 2 =      1, 625    2-1            first digit after zero
0,625    * 2 =      1, 25      2-2
0,25      * 2 =      0, 5        2-3
0,5        * 2 =      1, 0        2-4           last digit

0,0                               end of procedure




Example

Transform 0,3 (decimal) into binary number – result is 0,01001 1001 1001… 2   shortly rounded = 0,010012


0,3  * 2 =      0, 6         2-1       first digit after zero
0,6  * 2 =      1, 2         2-2
--------
0,2  * 2 =      0, 4         2-3
0,4  * 2 =      0, 8         2-4
0,8  * 2 =      1, 6         2-5
0,6  * 2 =      1, 2         2-6
--------
…
…

procedure never ends




Example – Quick Method

Transform 53(decimal) into binary number using quick method


  53                                                                          25 + 24 + 22 + 20 =
- 32     -&amp;gt;     25            1*25 + 1*24 + 0*23 + 1*22 + 0*21 + 1*20 =       
--------                                        ...&lt;br/&gt;
&lt;br/&gt;
Visit the link for full lesson</content><link rel="replies" type="application/atom+xml" href="http://visualcplus.blogspot.com/feeds/114178093106411591/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=22017830&amp;postID=114178093106411591" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114178093106411591" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114178093106411591" /><link rel="alternate" type="text/html" href="http://visualcplus.blogspot.com/2006/03/decimal-2-binary.html" title="Decimal 2 Binary" /><author><name>Vurdlak</name><uri>http://www.blogger.com/profile/08849999795183163370</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="20" height="32" src="http://img3.imageshack.us/img3/5296/saxophone35qd.jpg" /></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22017830.post-114178062588009944</id><published>2006-03-08T02:16:00.000+01:00</published><updated>2006-03-08T05:16:31.813+01:00</updated><title type="text">Decimal 2 Decimal</title><content type="html">Number we want to transform uses base X: we would like to transform this number into new one, that uses Y base. In this case we will use method of continuous dividing and multiplying (dividing numbers left of comma (,) with Y and multiplying numbers on the right side of comma, by Y - rational numbers). This method is best understood looking at these exampleswhere both X &amp; Y equal to 10 (decimal base, B=10)



Decimal System:

Base: 10
Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9




Example

Transform 5324 (decimal) into decimal number (?!) using method of continuous dividing – result 5324


5324 : 10 = 532 , remaining 4   100         last digit
532 : 10 =    53 , remaining 2   101
53 : 10 =       5 , remaining 3   102
5 : 10 =       0 , remaining 5   103         first digit


- end of procedure





Example

Transform 0,8125 (decimal) into decimal number (?!) using method of continuous multiplying – result 0,8125


0,8125  * 10 =   8, 125    10-1           first digit after zero
0,125    * 10 =   1, 25      10-2
0,25      * 10 =   2, 5        10-3
0,5        * 10 =   5, 0        10-4            last digit

0,0                                   end of procedure






Technorati Tags: Numeric, Numerical, Transform, Transformation, Binary, Decimal, Octal, Hexadecimal, Hex, Base, Complement, Method

&lt;br/&gt;
&lt;br/&gt;
Visit the link for full lesson</content><link rel="replies" type="application/atom+xml" href="http://visualcplus.blogspot.com/feeds/114178062588009944/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=22017830&amp;postID=114178062588009944" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114178062588009944" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114178062588009944" /><link rel="alternate" type="text/html" href="http://visualcplus.blogspot.com/2006/03/decimal-2-decimal.html" title="Decimal 2 Decimal" /><author><name>Vurdlak</name><uri>http://www.blogger.com/profile/08849999795183163370</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="20" height="32" src="http://img3.imageshack.us/img3/5296/saxophone35qd.jpg" /></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22017830.post-114178012387919647</id><published>2006-03-08T02:08:00.000+01:00</published><updated>2006-03-08T02:08:43.983+01:00</updated><title type="text">Numerical Systems</title><content type="html">Our society uses numerical system with base 10. Simple explanation why this system is used - simply because people have ten fingers, thus this is the easiest way for us to calculate numbers. If things were gone different, and something had messed up primordial soup -&amp;gt; developing Homo sapiens with eight fingers, it would be more likely we would use octal numeric system in present time. Infinite number of numerical systems exist, but following are most commonly used...




Decimal System:

Base: 10
Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9




Octal System:

Base: 8
Digits: 0, 1, 2, 3, 4, 5, 6, 7
Example: 27 (decimal) = 33 8 (octal)




Hexadecimal (hex) System:

Base: 16
Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
Example: 27 (decimal) = 1B 16 (hex)




Binary System:

Base: 2
Digits: 0, 1
Example: 27 (decimal) = 11011 2 (binary)


To learn more about numerical systems and their transformation (decimal2binary, dec2hex, dec2octal, hex2octal,...) continue to next lecture.





Technorati Tags: Numeric, Numerical, Transform, Transformation, Binary, Decimal, Octal, Hexadecimal, Hex, Base, Complement, Method

&lt;br/&gt;
&lt;br/&gt;
Visit the link for full lesson</content><link rel="replies" type="application/atom+xml" href="http://visualcplus.blogspot.com/feeds/114178012387919647/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=22017830&amp;postID=114178012387919647" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114178012387919647" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114178012387919647" /><link rel="alternate" type="text/html" href="http://visualcplus.blogspot.com/2006/03/numerical-systems.html" title="Numerical Systems" /><author><name>Vurdlak</name><uri>http://www.blogger.com/profile/08849999795183163370</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="20" height="32" src="http://img3.imageshack.us/img3/5296/saxophone35qd.jpg" /></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22017830.post-114177966634946437</id><published>2006-03-08T01:59:00.000+01:00</published><updated>2006-12-28T22:54:04.873+01:00</updated><title type="text">Numeric Transformations</title><content type="html">General Method of Transforming Numbers


Number we want to transform uses base X: we would like to transform this number into new one, that uses Y base. In this case we will use method of continuous dividing and multiplying (dividing numbers left of comma (,) with Y and multiplying numbers on the right side of comma, by Y - rational numbers). This method is best understood looking at these examples:




Example

Transform 5324 (decimal) into decimal number (?!) using method of continuous dividing – result 5324


5324 : 10 = 532 , remaining 4   100        last digit
532 : 10 =    53 , remaining 2   101
53 : 10 =       5 , remaining 3   102
5 : 10 =       0 , remaining 5   103         first digit
- end of procedure





Example

Transform 0,8125 (decimal) into decimal number (?!) using method of continuous multiplying – result 0,8125


0,8125  * 10 =   8, 125    10-1           first digit after zero
0,125    * 10 =   1, 25      10-2
0,25      * 10 =   2, 5        10-3
0,5        * 10 =   5, 0        10-4            last digit

0,0                                   end of procedure





Decimal 2 Binary




Example

Transform 29 (decimal) into binary number - reading upwards, result is 111012


29 : 2 =  14 , remaining 1   20            last (smallest) digit
14 : 2 =    7 , remaining 0   21
  7 : 2 =    3 , remaining 1   22
  3 : 2 =    1 , remaining 1   23    
  1 : 2 =    0 , remaining 1   24            first digit
- end of procedure





Example

Transform 0,8125 (decimal) into binary number – reading downwards, result is 0,11012


0,8125  * 2 =      1, 625    2-1            first digit after zero
0,625    * 2 =      1, 25      2-2
0,25      * 2 =      0, 5        2-3
0,5        * 2 =      1, 0        2-4           last digit

0,0                               end of procedure




Example

Transform 0,3 (decimal) into binary number – result is 0,01001 1001 1001… 2   shortly rounded = 0,010012


0,3  * 2 =      0, 6         2-1       first digit after zero
0,6  * 2...&lt;br/&gt;
&lt;br/&gt;
Visit the link for full lesson</content><link rel="replies" type="application/atom+xml" href="http://visualcplus.blogspot.com/feeds/114177966634946437/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=22017830&amp;postID=114177966634946437" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114177966634946437" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114177966634946437" /><link rel="alternate" type="text/html" href="http://visualcplus.blogspot.com/2006/03/numeric-transformations.html" title="Numeric Transformations" /><author><name>Vurdlak</name><uri>http://www.blogger.com/profile/08849999795183163370</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="20" height="32" src="http://img3.imageshack.us/img3/5296/saxophone35qd.jpg" /></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22017830.post-114177445166348304</id><published>2006-03-08T00:33:00.000+01:00</published><updated>2006-12-28T22:58:33.050+01:00</updated><title type="text">Numerical Systems and Transformations</title><content type="html">Our society uses numerical system based on number 10. There is a nutorious explanation why this system is used - it's simple, people have ten fingers, thus makes them easier to calculate numbers. If things were gone different, and something had messed up primordial soup -&gt; developing Homo sapiens with eight fingers, it would be more likely we would use octal numeric system at present time. Infinite number of numerical systems exist, but following are most commonly used, and their conversion from one to another, is simple.




Decimal System:

Base: 10
Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9



Octal System:

Base: 8
Digits: 0, 1, 2, 3, 4, 5, 6, 7
Example: 27 (decimal) = 33 8 (octal)



Hexadecimal (hex) System:

Base: 16
Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
Example: 27 (decimal) = 1B 16 (hex)



Binary System:

Base: 2
Digits: 0, 1
Example: 27 (decimal) = 11011 2 (binary)




General Method of Transforming Numbers


Number we want to transform uses base X: we would like to transform this number into new one, that uses Y base. In this case we will use method of continuous dividing and multiplying (dividing numbers left of comma (,) with Y and multiplying numbers on the right side of comma, by Y - rational numbers). This method is best understood looking at these examples:




Example

Transform 5324 (decimal) into decimal number (?!) using method of continuous dividing – result 5324


5324 : 10 = 532 , remaining 4   100        last digit
532 : 10 =    53 , remaining 2   101
  53 : 10 =       5 , remaining 3   102
     5 : 10 =       0 , remaining 5   103         first digit
- end of procedure





Example

Transform 0,8125 (decimal) into decimal number (?!) using method of continuous multiplying – result 0,8125


0,8125  * 10 =   8, 125    10-1           first digit after zero
0,125    * 10 =   1, 25      10-2
0,25      * 10 =   2, 5        10-3
0,5        * 10 =   5, 0        10-4            last digit

0,0                                   end of...&lt;br/&gt;
&lt;br/&gt;
Visit the link for full lesson</content><link rel="replies" type="application/atom+xml" href="http://visualcplus.blogspot.com/feeds/114177445166348304/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=22017830&amp;postID=114177445166348304" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114177445166348304" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114177445166348304" /><link rel="alternate" type="text/html" href="http://visualcplus.blogspot.com/2006/03/numerical-systems-and-transformations_08.html" title="Numerical Systems and Transformations" /><author><name>Vurdlak</name><uri>http://www.blogger.com/profile/08849999795183163370</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="20" height="32" src="http://img3.imageshack.us/img3/5296/saxophone35qd.jpg" /></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22017830.post-114153609703727444</id><published>2006-03-05T06:20:00.000+01:00</published><updated>2006-11-01T05:05:33.993+01:00</updated><title type="text">Lesson 14: Arrays</title><content type="html">In C language arrays are very popular. They can be found in almost any program code and are pretty helpful and easy to understand. To understand them, just visualize a sequence of numbers and try assigning them to only one declaration. It can be done if the declaration is properly stated as an array including index brackets (example int MySequence[20]).



Arrays

Array is data structure used to share multiple data elements under a single name declaration. It’s important that every single element of data, we wish to assign to array, belongs to the same data type. Array’s elements are easily accessed – we use index; a number that must be nonnegative integer (constant, variable, integer expression). Element’s index is a number between 0 and the number of elements minus one, including. In short: Index ( [0, NrOfElements – 1].



Declaration of an array:

data_type array[index];



Array’s definition in C:

int x[20]  – array consisted of 20 integer numbers
char symbols[2] – array consisted of 2 characters
float sequence[MAX]  – MAX is constant



Assigning element’s values definition:

int array[ ] = {1, 2, 3};
array[0] = 1
array[1] = 2
array[2] = 3

int array [4] = {1, 2};
array[0] = 1
array[1] = 2
array[2] = 0
array[3] = 0



Accessing array’s elements:

x[0]  – first element of an array
sequence[i]  – i. element of an array, 0 &amp;lt;= i &amp;lt;= NrOfElements – 1
sequence[MAX – 1]  – last element of an array



Common Wrong access to array’s elements:

int array[10] = {0};
int x = sequence[10];

float a = 1.;
int x = array[a];
int a = 1, b = 0, c = 1;
int x = array[(a &amp;&amp;amp; b) - c];




Example:

Write your own program that asks user to input sequence of numbers, afterwards it calculates arithmetic middle of the given sequence. Program also prints numbers smaller than arithmetic middle, and afterwards prints numbers bigger than arithmetic middle. 



#include &amp;lt;stdio.h&amp;gt;
#define DIMENSION 10

int main(void) {

int i;
  float sum = 0., arit_midd = 0.,...&lt;br/&gt;
&lt;br/&gt;
Visit the link for full lesson</content><link rel="replies" type="application/atom+xml" href="http://visualcplus.blogspot.com/feeds/114153609703727444/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=22017830&amp;postID=114153609703727444" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114153609703727444" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114153609703727444" /><link rel="alternate" type="text/html" href="http://visualcplus.blogspot.com/2006/03/lesson-14-arrays.html" title="Lesson 14: Arrays" /><author><name>Vurdlak</name><uri>http://www.blogger.com/profile/08849999795183163370</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="20" height="32" src="http://img3.imageshack.us/img3/5296/saxophone35qd.jpg" /></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22017830.post-114153491968092983</id><published>2006-03-05T06:01:00.000+01:00</published><updated>2007-01-18T00:10:39.393+01:00</updated><title type="text">About</title><content type="html">Purpose: "This website will provide you with lessons and quality material to learn basics of C language programming in just a few days. All you have to do is visit it here and then and read trough my lessons. You will notice I'm putting new lessons every day or two. It would be practical if you had Visual Studio installed on your computer and used it parallel to this lessons, but again it isn't neccessary... just follow and read theese C/C++ programming lessons and examples, and you'll be on your way! Let's not waste time, here we go..."&lt;br/&gt;
&lt;br/&gt;
Visit the link for full lesson</content><link rel="replies" type="application/atom+xml" href="http://visualcplus.blogspot.com/feeds/114153491968092983/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=22017830&amp;postID=114153491968092983" title="3 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114153491968092983" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114153491968092983" /><link rel="alternate" type="text/html" href="http://visualcplus.blogspot.com/2006/03/about.html" title="About" /><author><name>Vurdlak</name><uri>http://www.blogger.com/profile/08849999795183163370</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="20" height="32" src="http://img3.imageshack.us/img3/5296/saxophone35qd.jpg" /></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22017830.post-114153093513503482</id><published>2006-03-05T04:55:00.000+01:00</published><updated>2006-10-27T19:50:23.946+02:00</updated><title type="text">alloc.h</title><content type="html">#include &amp;lt;alloc.h&amp;gt;, syntax at the beginning of our code, means we automatically included these (pre-defined) functions in our program:




void *malloc (size_t size);                  NULL error
void free (void *block);
void *realloc(void *block, size_t size);     NULL error









Technorati Tags: alloc.h, Void, Malloc, Realloc, Memory, Cache, RAM
&lt;br/&gt;
&lt;br/&gt;
Visit the link for full lesson</content><link rel="replies" type="application/atom+xml" href="http://visualcplus.blogspot.com/feeds/114153093513503482/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=22017830&amp;postID=114153093513503482" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114153093513503482" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114153093513503482" /><link rel="alternate" type="text/html" href="http://visualcplus.blogspot.com/2006/03/alloch.html" title="alloc.h" /><author><name>Vurdlak</name><uri>http://www.blogger.com/profile/08849999795183163370</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="20" height="32" src="http://img3.imageshack.us/img3/5296/saxophone35qd.jpg" /></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22017830.post-114153086085059227</id><published>2006-03-05T04:54:00.000+01:00</published><updated>2006-08-13T20:40:00.546+02:00</updated><title type="text">ctype.h</title><content type="html">#include &amp;lt;ctype.h&amp;gt;, syntax at the beginning of our code, means we automatically included these (pre-defined) functions in our program:



int toupper(int ch);
int tolower(int ch);
int isdigit(int c);           figure (0-9)
int isalpha(int c);           letter (A-Z or a-z)
int isalnum(int c);           letter (A-Z or a-z) or figure (0-9)
int isprint(int c);           character which can be printed  (0x20-0x7E)
int iscntrl(int c);           control char (0x7F or 0x00-0x1F)
int isspace(int c);           empty space
int islower(int c);           letter (a-z)
int isupper(int c);           letter (A-Z) 








Technorati Tags: ctype.h, Figure, #include, toupper, tolower, isalpha, iscntrl
&lt;br/&gt;
&lt;br/&gt;
Visit the link for full lesson</content><link rel="replies" type="application/atom+xml" href="http://visualcplus.blogspot.com/feeds/114153086085059227/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=22017830&amp;postID=114153086085059227" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114153086085059227" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114153086085059227" /><link rel="alternate" type="text/html" href="http://visualcplus.blogspot.com/2006/03/ctypeh.html" title="ctype.h" /><author><name>Vurdlak</name><uri>http://www.blogger.com/profile/08849999795183163370</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="20" height="32" src="http://img3.imageshack.us/img3/5296/saxophone35qd.jpg" /></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22017830.post-114153083007220312</id><published>2006-03-05T04:53:00.001+01:00</published><updated>2006-12-03T22:40:22.346+01:00</updated><title type="text">string.h</title><content type="html">#include &amp;lt;string.h&amp;gt;, syntax at the beginning of our code, means we automatically included these (pre-defined) functions in our program:


char *strcpy(char *dest, const char *src);
char *strncpy(char *dest, const char *src, size_t maxlen);
char *strcat(char *dest, const char *src);

size_t strlen(const char *s);

char *strlwr(char *s); 
char *strupr(char *s);

int strcmp(const char *s1, const char *s2);
int strcmpi(const char *s1, const char *s2);
int stricmp(const char *s1, const char *s2);
int strncmp(const char *s1, const char *s2, size_t maxlen);
int strncmpi(const char *s1, const char *s2, size_t maxlen);
int strnicmp(const char *s1, const char *s2, size_t maxlen);

char *strchr(const char *s, int c);
char *strstr(const char *string, const char *substring);







Technorati Tags: math.h, Library, #include, strlen, strcmp, strcat, strchr
&lt;br/&gt;
&lt;br/&gt;
Visit the link for full lesson</content><link rel="replies" type="application/atom+xml" href="http://visualcplus.blogspot.com/feeds/114153083007220312/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=22017830&amp;postID=114153083007220312" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114153083007220312" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114153083007220312" /><link rel="alternate" type="text/html" href="http://visualcplus.blogspot.com/2006/03/stringh.html" title="string.h" /><author><name>Vurdlak</name><uri>http://www.blogger.com/profile/08849999795183163370</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="20" height="32" src="http://img3.imageshack.us/img3/5296/saxophone35qd.jpg" /></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22017830.post-114153079915077224</id><published>2006-03-05T04:53:00.000+01:00</published><updated>2006-03-09T20:38:48.100+01:00</updated><title type="text">stdlib.h</title><content type="html">#include &amp;lt;stdlib.h&amp;gt;, syntax at the beginning of our code, means we automatically included these (pre-defined) functions in our program:




void exit (int status);
void randomize (void); or void srand (unsigned int seed);
int rand (void);







Technorati Tags: stdlib.h, Rand, Randomise, Exit, Number, Function, C
&lt;br/&gt;
&lt;br/&gt;
Visit the link for full lesson</content><link rel="replies" type="application/atom+xml" href="http://visualcplus.blogspot.com/feeds/114153079915077224/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=22017830&amp;postID=114153079915077224" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114153079915077224" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114153079915077224" /><link rel="alternate" type="text/html" href="http://visualcplus.blogspot.com/2006/03/stdlibh.html" title="stdlib.h" /><author><name>Vurdlak</name><uri>http://www.blogger.com/profile/08849999795183163370</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="20" height="32" src="http://img3.imageshack.us/img3/5296/saxophone35qd.jpg" /></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22017830.post-114153075530451117</id><published>2006-03-05T04:52:00.000+01:00</published><updated>2006-03-09T23:44:07.516+01:00</updated><title type="text">math.h</title><content type="html">#include &amp;lt;math.h&amp;gt;, syntax at the beginning of our code, means we automatically included these (pre-defined) functions in our program:


int abs (int x);                    IxI
long labs (long x);

double fabs (double x);
double sin (double x);
double cos (double x);
double tan (double x);
double asin (double x);
double acos (double x);
double atan (double x);
double sinh (double x);
double cosh (double x);
double tanh (double x);

double exp (double x);              ex
double log (double x);              ln x
double log10 (double x);            log x

double pow (double x,double y);     xy
double sqrt(double x);              sqare root of x
double fmod(double x, double y);    x mod y

double ceil (double x);
double floor(double x);






Technorati Tags: math.h, Library, #include, abs, long, double, mod
&lt;br/&gt;
&lt;br/&gt;
Visit the link for full lesson</content><link rel="replies" type="application/atom+xml" href="http://visualcplus.blogspot.com/feeds/114153075530451117/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=22017830&amp;postID=114153075530451117" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114153075530451117" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114153075530451117" /><link rel="alternate" type="text/html" href="http://visualcplus.blogspot.com/2006/03/mathh.html" title="math.h" /><author><name>Vurdlak</name><uri>http://www.blogger.com/profile/08849999795183163370</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="20" height="32" src="http://img3.imageshack.us/img3/5296/saxophone35qd.jpg" /></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22017830.post-114145001816735815</id><published>2006-03-04T06:26:00.000+01:00</published><updated>2006-10-14T21:48:39.690+02:00</updated><title type="text">Lesson 13: Hello World! - A Classic -</title><content type="html">This is a true classic. I covered "Hello World!" example in this lesson, which is the one everybody encounters when learning to program – It's just sooner or later. Well, in my lessons –later-. Most of other tutorials start with this example, but I think I'm on the right path of introducing you to it only now. Not much of a new stuff covered here. More like repeating and affirmation.



Loops


Example:

What is the printed result of following program block?


i = 1;
while (i &amp;lt; 5) {

  if (i==3) {

    printf (“\n Hello world %d.x!”, i);
    continue;

  } else if (i==4) {

    printf (“\n Goodbye %d.x!”, i);
    continue;

  }
  i++;
}


Result:

Hello world 3.x!
Hello world 3.x!
...
... 
… and so on for infinite number of times. Even after value 3 is reached, orders under i==3 are executed. Because of “continue” command, i doesn’t increase, but the program branches on conditional phrase (i &amp;lt; 5). 





Example:

Write your own program block that prints multiplying table of numbers up to 100.


/*1*/ int main(void) {
/*2*/   int i,j;
/*3*/
/*4*/   for (i = 1; i &amp;lt;= 10; ++i) {
/*5*/       for (j = 1; j &amp;lt;= 10; ++j) 
/*6*/          printf("%3d",i*j);
/*7*/          printf("\n");
/*8*/    }
/*9*/}


By adding single line of code, we accomplish that new table is made from even numbers only:


/*6*/ if ( (i%2!=0) &amp;&amp;amp;amp; (j%2!=0) ) continue;     // both odd numbers

Same thing: 

/*6*/ if ( (i%2==0) || (j%2==0) )     // at least one number is even





Example:

Write your own program block that prints first N Fibonacci numbers. N is given by keyboard. Algorithm to calculate Fibonacci Numbers: 


     Fibonacci(n) = Fibonacci(n-1) + Fibonacci(n-2)
     Fibonacci(0) = Fibonacci(1) = 1

1, 1, 2, 3, 5, 8, 13, 21,...



#include &amp;lt;stdio.h&amp;gt;

int main () {

  int N, i, f0 = 1, f1 = 1,f = 1;
  printf ("\n Input amount of Fibonacci Numbers (N) : \n");
  scanf ("%d",&amp;N);
  for (i = 0; i &amp;lt;= N; i++) {

      if (i &amp;gt; 1) {  

         f = f1 + f0;
         f0...&lt;br/&gt;
&lt;br/&gt;
Visit the link for full lesson</content><link rel="replies" type="application/atom+xml" href="http://visualcplus.blogspot.com/feeds/114145001816735815/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=22017830&amp;postID=114145001816735815" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114145001816735815" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114145001816735815" /><link rel="alternate" type="text/html" href="http://visualcplus.blogspot.com/2006/03/lesson-13-hello-world-classic.html" title="Lesson 13: Hello World! - A Classic -" /><author><name>Vurdlak</name><uri>http://www.blogger.com/profile/08849999795183163370</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="20" height="32" src="http://img3.imageshack.us/img3/5296/saxophone35qd.jpg" /></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22017830.post-114126608477087351</id><published>2006-03-02T03:21:00.000+01:00</published><updated>2006-11-05T00:44:30.910+01:00</updated><title type="text">Lesson 12: Switch-Case, Break; and Continue;</title><content type="html">New lesson is up. I’ve composed this one, based on common examples where controls: break; and continue; are used. Another explanation on branching - using “switch – case” order is provided. Enjoy it! Hope you’ve noticed by now I also added some appendixes (more to be added soon); and for some time now, I post regular News regarding C++ Maniac homepage development. You can find these links in my sidebar.



Loop flow controls: break; and continue;


C uses two different orders to control loop’s flow
break – escapes from the nearest outer loop
continue – inside “while” and “do” loop: switches program execution to test condition, inside “for” loop: switches program execution to “for” loop step and then to condition test (also applies for nearest outer loop) - this can sound little messy, so better check the examples



Example:

Write your own program that tests if the given number is prime number.

 
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;math.h&amp;gt;

  void main() {

     int     i, n, prime=1;               // prime is true
     
     printf("Input natural number :");
     scanf("%d", &amp;n);
     
     for( i=2; i&amp;lt;= n-1; i++) {     
       
           if( n % i == 0 ) {              // also possible to state if(!(n % i)) 

           prime =0;                      // prime is now false
            break;

        }
     }
     
     if( prime )

           printf("%d is prime number !\n", n);
     
     else

           printf("%d isn’t prime number!\n", n);

  }
 


Possible algorithm enhancements (decreasing number of loop’s iterations/repeats):

It is enough to loop n/2 times, better, only till square root(n) (C function sqrt(n)) 
Test if the number is dividable with 2, and if it isn’t, test inside loop if the number is dividable with odd numbers bigger than 2



Example: 

Write your own program that reads integers given by keyboard and applies following rule above them: if the given number is smaller than zero, program should print error message and stop...&lt;br/&gt;
&lt;br/&gt;
Visit the link for full lesson</content><link rel="replies" type="application/atom+xml" href="http://visualcplus.blogspot.com/feeds/114126608477087351/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=22017830&amp;postID=114126608477087351" title="8 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114126608477087351" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114126608477087351" /><link rel="alternate" type="text/html" href="http://visualcplus.blogspot.com/2006/03/lesson-12-switch-case-break-and.html" title="Lesson 12: Switch-Case, Break; and Continue;" /><author><name>Vurdlak</name><uri>http://www.blogger.com/profile/08849999795183163370</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="20" height="32" src="http://img3.imageshack.us/img3/5296/saxophone35qd.jpg" /></author><thr:total>8</thr:total></entry><entry><id>tag:blogger.com,1999:blog-22017830.post-114092354119207553</id><published>2006-02-26T04:12:00.000+01:00</published><updated>2006-11-05T08:44:12.563+01:00</updated><title type="text">Lesson 11: Infinite and Finite Loops</title><content type="html">Seems to me that submitting new lessons every two days became a rutine lately. Let’s hope it stays that way. Today I posted new lesson which will put some light on programming loops - you surely have heard about those. So from now on, when you watch Futurama and hear Beneder blabring something about being stuck in an infinite loop, you’ll understand his problem in details: from one – to zero. Hehe, let’s start...


Iteration with previously known number of repeats.
  

Syntax:
 
for (expression1; expression2; expression3) {
        .
         .
         .
   }


expression1 is an expression which will be executed only once, before entering into the first iteration. It’s most commonly used for counters initialization. If more then one expression is needed in this field, they are separated by comma.
expression2 is calculated as logical condition (0 - false, !=0 - true), and the iteration is executed number of times expression2 is true. Testing of condition is done before any iteration is processed.
expression3 is executed after each iteration (executed loop). It’s most common use is to increase counter’s value. If more then one expression is needed to be executed, they are separated by comma.
either one of expressions (expression1; expression2; expression3) can be left out. If expression 2 is left out, loop is executed as if logical value of the expression were TRUE.


Common use:

for (i = start; i &amp;lt;= end; i = i + k)  {
       .
        .
        .     
   }



Example of “for” loop with 2 counters:

for (hi = 100, lo = 0; hi &amp;gt;= lo; hi--, lo++) {
       .
        .
        .
   }



Example:

Write your own program that will calculate arithmetic middle of n given numbers.


#include &amp;lt;stdio.h&amp;gt;

void main() {

  int    i, n, sum, x;
   float  arit_midd;

   printf("For how many numbers do you wish to calc. their arithmetic middle : ");
   scanf("%d", &amp;n );

   sum = 0;
   for(i=0; i&amp;lt;n; i++) {

      printf("Give %d. number : ", i);
       scanf("%d",...&lt;br/&gt;
&lt;br/&gt;
Visit the link for full lesson</content><link rel="replies" type="application/atom+xml" href="http://visualcplus.blogspot.com/feeds/114092354119207553/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=22017830&amp;postID=114092354119207553" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114092354119207553" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/22017830/posts/default/114092354119207553" /><link rel="alternate" type="text/html" href="http://visualcplus.blogspot.com/2006/02/lesson-11-infinite-and-finite-loops.html" title="Lesson 11: Infinite and Finite Loops" /><author><name>Vurdlak</name><uri>http://www.blogger.com/profile/08849999795183163370</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="20" height="32" src="http://img3.imageshack.us/img3/5296/saxophone35qd.jpg" /></author><thr:total>1</thr:total></entry></feed>

