facebook like button

31 March, 2011

program 24: prime number more efficient program

The need:
     In the program 17 to find whether a number is prime or not I told you that I'll be giving you more efficient program do find that after you know certain things. Now you know those things. So here is the program.

The code: 
--------------------------------------------

#include<stdio.h>
#include<math.h>
main()
{
    int i,j,k=0,n;
    double m;
    printf("Enter the number...");
    scanf("%d",&i);    // scanning i as integer
    if(i<2)
    {
    printf("Prime numbers start from 2\n");
    }
    else if(i==2)
    {
    printf("Number is prime\n");
    }
    else
    {
m=sqrt(i);         //m is square root of i
    n=ceil(m);         //ceil function
    for(j=2;j<=n;j++)
    {
         if(i%j==0)
         {
         k++;
         break;
         }
    }
         if(k>=1)
         printf("The number is not a prime number.\n\n");
        else
        printf("The number is a prime number.\n\n");
}
}

-----------------------------------------

The approach:
   A number will be prime if it can not be fully divided by any number except itself and 1. The program finds this by dividing given number by a range of numbers and checking whether it has been fully divided or not. In program 17 that range was taken to be 2 to 'i/2' where 'i' is the number to be checked. But now suppose a number 'x' has factors then we can always make couples of factors. In those couples one will be greater than the square root of 'x' and the other will be less. You cannot find a number both of whose factors are greater than its square root. This implies that to check whether a number 'i' is prime or not I have to check only up to its square root. To be on safe side I am checking up to the smallest integer greater than or equal the square root of 'i'. The ceil() function takes care of this. So 'm' is the smallest integer greater than or equal the square root of 'i'. One new statement used here is break. This is used when we want to break the flow of loop like here when we have find a factor of that number, we need not check further so its better to break loop. To know more about break see program30.


Remark:
    If the number to be checked is greater than 4, the value of 'm' will be less than 'i/2'so number of runs of loop will be less. That's the meaning of 'more efficient' here.
    Ex.  Suppose I have to check whether 10000 is a prime number or not, then program 17 will run loop 10000/2=5000 times while this program will run the loop for sqrt(10000)=100 times.
Therefore you see that number of runs of loop have been reduced.

30 March, 2011

program 23: calculating value of 'e'

The need:
     This is the program to calculate the value of 'e', the base of natural logarithms without using "math.h". I made this program in this way because at that time I wanted to practice loops more and did not know "math.h" that much too.

The code:
---------------------------------------------------
#include<stdio.h>
main()
{
    printf("***program to calculate value of e using its expansion of taylor series***\n");
    int n;
    double i=1,j=1,k=1;
    printf("Up to how many terms of series do you want to calculate the value of e.\n");
    scanf("%d",&n);      //scanning n as integer
    if(n<=0)
    j=0;
    else
    {
      while (k<n)          //while loop runs n times
      {
        i/=k;          // after this statement i holds the (k+1)th term of the series
        j+=i;          // after this statement j holds the sum upto (k+1)th term of the series
        k++;        //incrementing k
      }
    }
    printf("\n value of e = %.15lf\n\n",j);   //print the value upto 15 places of decimal
} 
---------------------------------------------------

The approach:
     We have following Taylor series expansion of ex  
ex = 1+x/1!+x2/2!+x3/3!+....
 If I put x=1 in this series then I can get value of 'e'. So now I have to calculate the value of 
1+1/1!+1/2!+1/3!+.... 
up to given number of terms. For that I have initialized all variables to 1. As written in comment j will be having the value of 'e'. Now program scans value of n, the number of terms to used. Now suppose anybody gives n as 0 or negative this means don't use even a single term so program will set value of j as 0 and skip the while loop hence the value of e printed will be 0. In all other cases while loop will get a chance to run.
      First run of while loop calculates the value of second term in series, adds it to j and and increments k. In each run of loop finally i is holding value of corresponding term which is retained till the next run of loop up to where it is changed. If you know about factorial then its OK, you can observe term, each its being divided by "index" that of term, that's what I have done when I am changing the value of i in the while loop.

program 22: calculating antilog of a number

The need:
     This is the program to calculate the anti-log of any number to the base 10. This program also introduces you to "double", an important data-type of C.

The code:
-----------------------------------------------
#include <stdio.h>
#include <math.h>
main()
{
    printf("******program to calculate antilog P *******\n\n");
    double i,j;
    printf ("enter the value of P to get its antilog...\n\n\n P= ");
    scanf ("%lf",&i);
    printf("i=%lf\n",i);
    j=pow(10,i);
    printf("antilog P=%lf \n",j);
}
-----------------------------------------------
The approach:
     The program uses the basic fact that anti-log of a number to the base 10 is the value of "10 to the power that number". Here you see a data-type double that is new for you. This data-type is used exactly same as float. It gives you high accuracy and large range in calculations but it uses more memory.

Remarks:
     In previous post I said that math.h functions will be given in this post. Some most commonly used functions are given below:
  1.    sqrt(x): "gives square root of x" or in technical terms we say "returns square root of x"; 
  2.    pow(x,y): returns x raised to the power y;
  3.    exp(x): returns e raised to power x where e is base to natural logarithms;
  4.    log(x): returns natural logarithm of x;
  5.    log10(x): returns log x to base 10;
  6.    sin(x): returns sin(x);
  7.    cos(x): returns cos(x);
  8.    tan(x): returns tan(x);
  9.    asin(x): returns sin-1x;
  10.    acos(x): returns cos-1x;
  11.    atan(x): returns tan-1x;
  12.    ceil10(x): returns smallest integer greater than or equal to x;
  13.    floor10(x): returns greatest integer less than or equal to x;
  14.    fabs10(x): returns absolute value of x;
  15.    fmod(x,y): returns remainder when x is divided by y; This function is needed because '%' operator works only when x and both are int data-type.

  Where x and y are double, and all these functions also return data-type double(wherever I haven't specified). If x and y are not double, C automatically convert them into double, this automatic conversion is called "implicit type conversion".

  Wherever angle is used or returned it's unit is radian not degree.


For details of all functions you can refer links below:
http://www.codingunit.com/category/c-language-reference/c-reference-math-h-functions
http://en.wikipedia.org/wiki/Math.h
http://www.java2s.com/Code/C/math.h/Catalogmath.h.htm 

29 March, 2011

program 21: Compound interest (introduction of math.h)

The need:
     This is the same program of previous post. But in previous post I said the purpose of that program you would come to know in next(i mean this post.) So the need of this program is to introduce you one more header file "math.h".

The code:
----------------------------------------------
/*Note that in this program I have
used two header files*/
#include<stdio.h>
#include<math.h>
main()
{
    int p,n;
    float r,ci,q,s;
    printf ("For compound interest enter the values of p,n,r...\n");
    printf("p= ");
    scanf("%d",&p);      //scanning p
    printf("n= ");
    scanf("%d",&n);      //scanning n
    printf("r=");
    scanf("%f",&r);      //scanning r
    s=(1+r/100);     //assigning value of (1+r/100) to s
    q=pow(s,n);      //pow function calculating (s^n)
    ci=q*p-p;
    printf("ci= ");
    printf("%.2f\n",ci);
}
----------------------------------------------

The approach:
     In previous program you have already been told everything about compound interest. There we calculated the value of (1+r/100)^n by multiplying (1+r/100), n times. Here with math.h we directly calculated the value of (1+r/100)^n by using built-in function pow().

Remarks:
   1.  pow() is not only function in "math.h". There are other functions also. In our program we'll be using those whenever we need. Those will be given in next post.
   2. If you are using linux/unix to compile this program, add '-lm'(without quotes) after the compile command. Ex. : if the file name is file.c, give the command: 
"cc file.c -lm"(without quotes)
instead of only "cc file.c"

program 20: Calculating compound interest

The need:
      There are many programs which I wrote just to implement the formulas I had seen in my school days. This program is one of those. But you will understand the purpose of putting this program in this post in next post.

The code:
----------------------------------------------
#include<stdio.h>
main()
{
    int p,n,m;
    float r,ci,q=1;
    printf ("For compound interest enter the values of p,n,r...\n");
    printf("p= ");
    scanf("%d",&p);      //scanning p
    printf("n= ");
    scanf("%d",&n);
      //scanning n
    printf("r=");
    scanf("%f",&r);
      //scanning r
    for (m=n;m >0;m--)   //for loop
    q=q*(1+r/100);
    ci=q*p-p;
    printf("ci= ");
    printf("%.2f\n",ci);
}

----------------------------------------------
The approach:
     This program is simple enough to understand if you know the terms and the formula used to calculate compound interest.

                ci=p((1+r/100)^n - 1);

Where the notations used are:
ci  ===> compound interest;
p  ===> primary amount;
n  ===> number of units of time;
r  ===> rate of interest in % for above unit of time;

for example:
p=10000Rs.
n=2yrs.
r=10% per year.
Then 
ci=2100Rs.
This can be crosschecked with the program.

     Now let me explain how the program is doing this. The for loop is for calculating value of (1+r/100)^n. It multiplies (1+r/100) 'n' times. Here 'm' is the counter used(may be I don't need to tell you next time) and 'q' is a float variable which has been initialized to value 1. So now you can clearly see that after loop is finished 'q' will be having value (1+r/100)^n. Rest all thing are very clear.

28 March, 2011

program 19: finding the GCD/HCF of 2 numbers

The need:
     This program was given to me as a lab assignment.
The code:
---------------------------------------
//Finding HCF
#include<stdio.h>
main()
{
    printf("Enter two integers to get their hcf ..\n");
    long int i,j,k;
    scanf("%ld  %ld",&i,&j);
    ranu:
    k=i%j;
    if(k!=0)
    {i=j;
    j=k;
    goto ranu;}
    else
    printf("The hcf of given numbers is %ld\n\n\n",j);
}
---------------------------------------

The approach:
     In this program I have used the same division method for finding GCD that you use when you calculate GCD with a paper pen(If you have ever used). In the same way in each run of loop I am making remainder the divisor and divisor the dividend if the remainder is not 0. If the remainder is found 0 then loop terminates and corresponding value of divisor is the GCD.
      In this program I used 'goto' because by that time I was not aware of  'for' loop. I think you are smart enough to rewrite this program using 'for' and 'while' loop if you have gone through program12, program13 and program14 of this blog so I am not going to put those programs in this blog.

program 18: Counting the number of digits in a given number

The need:
     This program was given to me as a lab assignment.
The code:
-----------------------------------------
#include<stdio.h>
main()
{
    int s,d=0;
    printf("Enter the number to count its digits\n");
    scanf("%d",&s);     //scanning number into s
    while(s>0)     //while loop
    {
      s=s/10;
      d=d+1;     //you can also write d++ instead of d=d+1
    }
    printf("\nno of digits =\t%d",d);
}
-----------------------------------------

The approach: I hope you know how integer division works (recall example1 in program 5). I also assume that you are very much aware with 'while()' loop if you have gone through previous posts. Now in this while loop here I am dividing s by 10(which simply means each time I am removing left most digit of 's') in each run of loop. Here in this program I am using 'd' as the counter. You can clearly see that as a digit is removed from 's', 'd' is incremented. This while loop runs until value of 's' reaches 0. So its very obvious that when all the digits have been removed 'd' will be having the count of digits.

27 March, 2011

program 17: finding out whether a number is prime or not

The need:
     Till now you have a clear idea about loops. Now lets implement this knowledge to a program that will be doing some more than a calculator or human. Here is a program that will ask the user to enter an integer and will tell whether the number entered is a prime number or not. This program was given as assignment in the lab.

The code: 
--------------------------------------------
#include<stdio.h>
main()
{
    int i,j,k=0;
    printf("Enter the number...");
    scanf("%d",&i);
    for(j=2;j<i/2;j++)
    {
         if(i%j==0)
         k++;
    }
         if(k>=1)
         printf("The number is not a prime number.\n\n");
        else
        printf("The number is a prime number.\n\n");
}-----------------------------------------

The approach:
   A number will be prime if it can not be fully divided by any number except itself and 1. So in this program I have checked for 2 to i/2 where i is the given number because we already know that any number 'i' cannot be fully divided by any other number lying in range of i/2 and i (both exclusive). Except that again I am using a counter 'k' which is incremented whenever a number which completely divide 'i' is found.
   After the loop finishes, value of 'k' is checked. If it(value of k) is more than its value at the start( at starting of program k=0) then in above specified range 'k' numbers that divide 'i' fully has been found which implies that 'i' is a not prime number otherwise if it(value of k) is same as start( at starting of program k=0) then in above specified range no number that divide 'i' fully has been found which implies that 'i' is a prime number.

Remarks:
1. This is basic program to check whether a number is prime or not. This program is not 100% correct and says 2 is not a prime number.
2. I gave this program like this because at that time I made it in this way. You'll come to know more by going sequentially through this blog.
3. The idea was to show the use for loop and not confuse beginners with if and else conditions with looping.
 The more efficient and 100% correct program to find whether a number is prime or not is given in the post referenced by the following link.
program 24.

program 16: addition using 'do......while loop' with a sentinel

The need:
     You have seen in some previous programs we added 'n' numbers using three types of loops. All those program were based on the concept of counter. But generally in real life we don't know how many numbers we'll be adding. The program below illustrates how we enter multiple numbers to get the sum without giving their count before hand. This is the same previous addition program with only difference of 'sentinel' instead of 'counter' with a 'do....while loop'.

The code: 
--------------------------------------------
/*Addition program using do...while loop with a sentinel*/
#include<stdio.h>
main()
{
    float i,sum=0;
    printf("To add numbers keep on giving numbers ...\nPress ENTER after each number...\nEnter 0 after last number to be added\n");
    do      //do while loop
    {
      scanf("%f",&i);     //scanning number
      sum=sum+i;         // adding number to sum
    }
    while(i!=0);
    printf("__________________\n=%f\n\n\n",sum);
}
 
--------------------------------------------

  I have already told you the term 'sentinel' in earliier post. In this post we'll come to know what this is. If you run the given program then we come to know that the program says, 

"To add numbers keep on giving number...
Press ENTER after each number...
Enter 0 after last number to be added"

     After this the program keeps on accepting numbers until we enter 0 and as you enter 0 the program gives the output. Now is you see the code of this program, you'll come to know that while loop will terminate when the number 0 is given as input. This concept when we use some of the input value to limit the number of runs of loop is called 'use of sentinel' and this value is called 'sentinel'.

program 15: addition of n numbers using 'do......while loop'

The need:
     You have seen the previous program how we added 'n' numbers using 'while loop'. The program below illustrates the use of 'do....while loop'. This is the same previous addition program with only difference of while and do...while loop.

The code: 
--------------------------------------------
/*Addition program using do...while loop*/
#include<stdio.h>
main()
{
    int m=0,n;
    float i,sum=0;
    printf("how many numbers do you want to add?\n");
    scanf("%d",&n);
    printf("Now keep on giving numbers ...\nPress ENTER after each number...\n");
    do      //do while loop
    {
      scanf("%f",&i);     //scanning number
      sum=sum+i;         // adding number to sum
      m++;
    }
    while(m<n);
    printf("__________________\n=%f\n\n\n",sum);
}
--------------------------------------------

program 14: addition of n numbers using 'while loop'

The need:
     You have seen the previous program how we added 'n' numbers using 'for loop'. The program below illustrates the use of 'while loop'. This is the same previous addition program with only difference of for and while loop.

The code: 
--------------------------------------------
/*Addition program using while loop*/
#include<stdio.h>
main()
{
    int m=0,n;
    float i,sum=0;
    printf("how many numbers do you want to add?\n");
    scanf("%d",&n);
    printf("Now keep on giving numbers ...\nPress ENTER after each number...\n");
    while(m<n)      //while loop
    {
      scanf("%f",&i);     //scanning number
      sum=sum+i;         // adding number to sum
      m++;
    }
    printf("__________________\n=%f\n\n\n",sum);
}
--------------------------------------------

26 March, 2011

program 13: addition of n numbers using 'for loop'

The need:
     You have seen the previous program how we added 'n' numbers. In the end of post I told you about other loops.The program below illustrates the use of 'for loop'.

The code: 
--------------------------------------------
/*Addition program using for loop*/
#include<stdio.h>
main()
{
    int m,n;
    float i,sum=0;
    printf("how many numbers do you want to add?\n");
    scanf("%d",&n);
    printf("Now keep on giving numbers ...\nPress ENTER after each number...\n");
    for(m=0;m<n;m++)      //for loop
    {
      scanf("%f",&i);     //scanning number
      sum=sum+i;         // adding number to sum
    }
    printf("__________________\n=%f\n\n\n",sum);
}
--------------------------------------------
     'for loop' is most commonly used loop when counter is used and limit to the counter is specified because the for loop body facilitate the increment of the counter. Like the previous program here also I am using variable 'm' as counter. You see in the body of for loop there are three fields separated by semicolon (;). In first field m=0 is written. This field is called initialization field. Here in our program this means that initial value(when first run of the loop is about to start) of our counter 'm' is 0. The second field which has m<n written within it is the field for condition. This tells the program to continue loop until the condition specified in that field holds good. In the third field increment or decrement of the counter takes place. Here m++ is short style of writing m=m+1. Basically it is incrementing value of m.In all other aspects this program is same as previous program. you can refer to link below: 
program 12: addition of n numbers


Remarks:

    a). Note that when we write m++, value of 'm' gets incremented after the corresponding run of loop finishes. This is called post increment. If we write ++m, value of 'm' gets incremented before the corresponding run of loop starts. This is called preincrement.

program 12: addition of n numbers

The need:
     You have already seen our program 3, addition of 2 numbers. What if the count of numbers to be added is 100 or so? Do I need to write 'scan()' statement 100 times in that case? what if the count of the numbers to be added is not fixed for a program? Can it be dependent on user's wish? If it can then how? You have already started guessing that there should be a statement which would cause the single 'scan()' statement to repeat 100 times or say n times. The program below answers all these questions.

The code: 
-------------------------------------------- 
/*Addition program using goto*/
#include<stdio.h>
main()
{
    int m=0,n;
    float i,sum=0;
    printf("how many numbers do you want to add?\n");
    scanf("%d",&n);
    printf("Now keep on giving numbers ...\nPress ENTER after each number...\n");
    again:
    scanf("%f",&i);
    sum=sum+i;
    m=m+1;
    if(m<n)
    goto again;
    printf("__________________\n=%f\n\n\n",sum);
}
--------------------------------------------
   Up till the previous post you have come to know that any C program executes in sequential order. I mean the statement written first gets executed first. Now come to this program. Here in C we have a 'goto' statement which causes the execution of program to shift to some other position in the program. That position is specified by a label (in our case name of label is 'again'). Name of the label can be anything lets say my name 'ranu'. The label is put some where in program code with a colon(:) after it. See the syntax of 'goto' statement. It is usually put after if statement because we want execution of program to jump to a particular location within a program only based on a condition. The reason for that is in following sentence. Assume a situation without a condition in our case each time program encounters 'goto' its execution  goes to label 'again' and in sequential flow of program again 'goto' is encountered because there is no condition so each time program jumps to label 'again' unconditionally.
So the execution of the program is trapped in goto loop and the program will never come to an end.
    Now for our program if you start thinking of a condition(because you need one) you can easily think that the number of scan() statement should be 'n' because we have to take 'n' inputs from the user. So you can think of a counter variable that will count the number of scans. Here 'm' is such a counter variable. Observe initially when not even a single scan is executed, value of 'm' is 0(we say 'm' is initialized to 0). As any scan takes place in the next line 1 is added to 'm'. If m is less than n(count of number to be added given by user) or we can also say that is number of scans is less than n(count of number to be added given by user) then jump to again' else don't. Recall the use of 'if' statement.
 
Remarks:

   a). Now a days use of 'goto' statement is not advisable. You should use avoid using 'goto' statement. If you have question, "How shall we doing iterations?". Answer is: We have alternate loop statements(or loops). There are 3 types of loops in C.
1. 'for' loop.
2. 'while' loop
3. 'do....while' loop
These loops will be demonstrated in upcoming posts.

   b). Concept of 'counter' is very common in loops. These counters help to limit the number of iterations of a loop. There is also a concept of 'sentinel' which also helps in limiting the number of iterations of a loop. which will be explained in upcoming posts.

program 11: Finding simple interest

The need:
     There was no special purpose of this program except for calculating simple interest. I wrote this program just to practice some more. That is why I'll not explain anything in this program. First try to  write program yourself based on previous posts. In case of any difficulty try to understand the below code on your own.

The code:
-------------------------------------------
/*a program for simple interest */
#include<stdio.h>
main()
{
    float i,j,k,si;
    printf("To calculate simple interest enter \np=");
    scanf ("%f",&i);
    printf("r=");
    scanf ("%f",&j);
    printf("n=");
    scanf ("%f",&k);
    si = i*j*k/100;
    printf("\nSimple interest =%.2f\n\n\n",si);
}
-------------------------------------------

program 10: Largest of three integers

The need:
     To find out largest of three numbers given by user. To learn the conditional assignment (the ? : operator) and to learn how to scan more than one variable in a single scan statement. 
The code:
-------------------------------------------

#include<stdio.h>
int main()
{
int i,j,k,l;
printf("Enter three integers\n");
scanf("%d %d %d",&i,&j,&k);
l=(i>j)?i:j;
l=(k>l)?k:l;
printf("The largest integer of the above given is %d\n\n",l);
return 0;
}
-------------------------------------------

   First of all copy the code and run the program. When this program asks for three integers, enter three integers one by one and the program will print the largest number for you. At this point you already know that the first line inside main() is the declaration of 4 integer variables. The second line will print a message on console. The third will scan three integers form keyboard(also called STDIN which stands for standard input) and assign their values to i,j,k respectively.
   There is a fourth variable 'l' that will be holding the value of largest integer at end of the program. The fourth line of main() is a 'conditional assignment' statement. It may be a new term for you but as the name says its an assignment based on some condition. Look at the format of this statement. Just after the '=' sign a parenthesis starts and there is also a closing parenthesis in the same line. This pair of parenthesis encloses our condition for assignment. After closing parenthesis there is '?' and then a value(variable i) then a ':' then a value(variable j). One of these value is to be assigned to 'l'.
   If the condition enclosed in the parenthesis is true then the former value is assigned to 'l' else the latter value is assigned. This follows that if i>j is true then value of i is assigned to 'l' else value of 'j' is assigned to 'l'.  This means after line 4 of main() 'l' will be having larger of 'i' and 'j'. By the same logic after line 5 of main() 'l' will be having larger of 'l' and 'k'. This follows that by the end of line 5 'l' will be having the largest value of i,j and k.

Note:
  1. Instead of giving the value directly we can write any expression that lead to a value or a function that returns a value.
  2. This will be true in all other assignments. In most of the cases variables can be replaced by expressions and functions.
  3. We can not replace a variable that is on the left side of '=' with an expression or a function.

25 March, 2011

program 9: Area of circle and use of #define

The Need:
     To calculate the area and circumference of a circle with given radius. Get to know the '#define' directive.

The code:
--------------------------------------------
#include<stdio.h>
#define PI 3.14159       //defining PI value
main()
{
    float R,C,A;
    printf("Give the radius of circle \nR= ");
      scanf("%f",&R);    //scanning radius
    C=2*PI*R;       //calculating circumference
    A=PI*R*R;       //calculating area
    printf("Circumference=%f    Area=%f\n",C,A);
}
---------------------------------------------

     First of all compile and run this program and see it works. Now notice that in the very second line of code I wrote a statement "#define PI 3.14159" and further in the formulas for calculating area and the circumference in stead of writing value of pi(that is approx. 3.14159) I have used PI word. What are you thinking......? Yeah you are right its just like when you use the word LOL while chatting with your friends and ask them to interpret it as 'Laughing out loud'...". After that your friends will understand what you mean whenever you say 'LOL' in chat.
    As you will be using #define more in your programs, you will come to know that 
1. you cannot change the previously defined value.
2. Its a 'preprocessor directive'. Don't worry about this new term. You will come to know about it in detail later.

program 8: temperature conversion (C to F and vice versa)

The need:
     Here this is a program to do temperature conversion based on the user's wish . Here is a program which will ask the user to choose whether he wants to convert temperature from degree C to degree F or vice-versa.

The Code:
--------------------------------------------------------
#include<stdio.h>
main()
{
    float c,f;
    int x;
    printf("for C to F conversion press 1 and for F to C press any other key\n");
    scanf("%d",&x);      //scanning x
    if (x==1)
    {
      printf("Enter the value of temp in degree C\n");
      scanf("%f",&c);
      f=9*c/5 + 32;     // formula for C to F
      printf("%f C = %f F\n",c,f);
    }
    else
    {
      printf("Enter the value of temp in degree F\n");
      scanf("%f",&f);
      c=5*(f-32)/9;     // formula for F to C
      printf("%.2f F = %f C\n",f,c);
    }
}
--------------------------------------------------------

    The new thing about this program is that the whole block of code that lies inside the braces after if statement is getting executed and not just the single line that follows 'if'(As in the previous post). It is the same case with else. So today we have also come to know that if we want the whole block of code to run as a set in a "loop" or 'after a condition'('if' or 'else')we should enclose that block in a pair of braces. Here you have seen a new term 'loop'. I'll be explaining about this in upcoming posts.