Loops in C While Loop

Monday, April 7, 2014

0 comments
Loop in C++
It is a statement that is used to repeat set of statements up to a fixed number of times or until a given condition is satisfied.
There are two types of loops:
  • Conditional Loop (while and do-while Loop)
  • Counter Loop (for loop)
Conditional Loop
It is a loop that executes a set of statements as long as a given condition remains true.
Counter Loop
It is used to repeat a set of statements for a specified number of times.
While Loop
It is used to repeat a set of statements until a given condition is satisfied.
Syntax:
while loop
  • When while statement is executed, the compiler checks the given condition written in parentheses.
  • If the given condition is true then the statements enclosed in the braces ( body of loop) are  executed.
  • After the completion of first iteration control is shifted to while and the condition is again tested.
  • This process is repeated until the condition is true.
  • If the condition is false then control is transferred the statement that comes after the body of loop.
Infinite loop
If the condition of loop never false then the loop never ends and called infinite loop
Note: Infinite loop in useful where the programmer does not know in advance how many times the body of loop will be executed.

Loop control variable
A variable whose value control the number of iterations of loop is called loop control variable.
  • Loop control variable always initialized before starting of the loop and incremented and decremented inside the loop body. 
    For example: Program to print first 10 natural numbers

#include<iostream>

using namespace std;

int main()

{

    int a=1;              

    while(a<=10)               // Condition of loop

    {

        cout<<a<<endl;

        a++;                    // increment statement

    }

return 0;

}

 Output

1

2

3

4

5

6

7

8

9

10

    Read More..

    Repeaters

    Sunday, April 6, 2014

    0 comments
    Repeaters are also called Re-generator.

    Repeaters is only hardware device.

    Repeaters re-generate the original bit pattern.

    Repeaters in Computer Network to re-generate to weak signal
    Figure: Repeaters in Computer Network

    The purpose of repeater is to extend the LAN segment beyond its physical limits.


    Repeaters are used to connect two physically close building together.

    Repeaters operate at the  "Physical layer" of OSI model.

    Repeaters can join two different physical physical media  but they must use the same access method.

    Repeaters handle only the electrical and physical characteristics of the signal.

    Repeaters works only the same type of physical layer as Ethernet-to-Ethernet.



    Read More..

    PROGRAM TO INSERT AN ELEMENT IN AN ARRAY

    0 comments
    #define MAX 10
    main()
    {
    int a[MAX]={11,22,33,44,55,77,88};
    int n,x;
    printf("Enter an element to be inserted
    ");

    scanf("%d",&x);
    printf("Enter the position at which
    ");

    printf("this element to be inserted
    ");

    scanf("%d",&n);
    insert(a,x,n);
    }


    insert(int *a,int x,int n)
    {
    int i,j=0,*a1,temp;
    a1=(int*)malloc((MAX-n)*sizeof(int));
    for(i=n;i<MAX;i++)
    *(a1+j++)=*(a+i);
    *(a+n)=x;
    for(i=n+1;i<MAX;i++)
    *(a+i)=*(a1++);
    for(i=0;i<MAX;i++)
    printf("%d",*(a+i));
    putchar(
    );

    }

    OUTPUT
    Enter an element to be inserted 
    66
    Enter the position at which
    this element to be inserted 
    3
    11   22   33   66   44   55   77   88   0   0
    Read More..

    Before Make Magazine

    Saturday, April 5, 2014

    0 comments
    In the corner of the factory there was a rather large machine sitting there unused. There was a sort of hodgepodgeness (if thats a word) about it. My boss Bob explained to me that this was a CNC machine that he had built himself. Wow! So before the company had money to purchase the industry standard Excellon drilling and routing machines he had decided it was possible to build his own, and it worked. I think thats really impressive!
    Read More..

    What is Function

    Friday, April 4, 2014

    0 comments
    What is function in C?
    A function is a self-contained block of statement that perform a coherent task of some kind.
    There are two types of function in C:
    1. Library function or In-built function
    2. User define function

    Structure of function in C program

    /* demonstration of function status in program */  

    #include<stdio.h>                                  
    void disp();   /* function prototype declaration */
    int main()                                         
    {                                                  
      disp();      /*function calling*/                
      printf("C is Awesome!!!");                       
      return 0;                                        
    }                                                  
    void disp()    /* function definition */           
    {                                                  
      printf("Hi, ");                                  
    }                                                  

    The output of above program would be:

    Hi, C is Awesome!!!

    Lets grab some useful info from the above program:
    In above program we have 2 function:
    main()
    disp()

    Here you can see and thought:
    1. why main() is used only once in program?
    2. why disp() is used three times in program?

    The answer of first question is "if a c program contains only one function then it must be main()." i.e. every C program must have main() function.

    The answer of second question: lets understand the meaning of every disp() in program:

    void disp();
    this is the first disp() that used in program. It is function prototype.
    This prototype tells the compiler that as:
    What is function type ( i.e. void or not ),
    What is name of function( i.e. in our program function name is disp)
    Both parenthesis () indicate that disp is function.
    keep in mind: void word indicating that "nothing return".

    disp();
    this is the second disp() that used in program. It is function calling.
    Every calling function main work is as:
    when compiler reached at calling function disp(); program control passes to the function disp(), (i.e. activity of main() is temporary suspend ), when disp() function runs out all his statement execute, the control returns to the main() function and begins executing code at the exact point where it is left off.


    void disp()
    {
      printf("Hi, ");
    }

    this is the third disp() that used in program. It is function definition.
    In function definition we can used all C language keywords, operators, variable etc.
    In above program recently we have only 1 printf(); statement.

    Lets exercise, what we learn:

    /*exercise of function calling C program*/
    #include<stdio.h>
    void fun1();
    void fun2();
    void fun3();
    int main()
    {
      printf("
    I am in main function!!"
    );

      fun1();
      fun2();
      fun3();
      return 0;
    }
    void fun1()
    {
      printf("
    I am in fun 1"
    );

    }


    void fun2()
    {
      printf("
    I am in fun 2"
    );

    }


    void fun3()
    {
      printf("
    I am in fun 3"
    );

    }


    The output of above program would be:

    I am in main function!!
    I am in fun 1
    I am in fun 2
    I am in fun 3


    Read More..

    BMW X6 Performance Unlimited Japan Only Special Edition Version

    Tuesday, April 1, 2014

    0 comments

    A bespoke version of the BMW X6 tweaked with bits and pieces from the shelves of the Bavarian firms Performance and Individual divisions has been revealed in Japan. The BMW X6 Performance Unlimited is based off a X6 xDrive35i and will be offered in a strictly limited edition of 20 examples.


    The Japanese-market-only X6 special is coated in a silver-pearl body color from the automakers Individual program and comes with a BMW Performance aero-kit that includes a new front bumper, side skirts, rear diffuser and blacked-out kidney grilles. The unique 21-inch alloy wheels shod in chunkier sport tires and darkened windows round off the exterior package.

    Inside, the X6 Performance Unlimited is distinguished by the aluminum pedal set, special leather seats, brushed aluminum trim and a numbered plaque.

    There are no changes to the 306-horsepower turbocharged straight-six under the hood.

    The BMW X6 Performance Unlimited is available for order in Japan with pricing set at 9,450,000 Yen (about US$108,400 or €86,300).
    Read More..

    Lenovo ThinkPad X100e

    0 comments


    Business owners rejoice! The first affordable ThinkPad ultraportable laptop has arrived. The ThinkPad X100e is an 11-inch notebook packed with a low-voltage AMD processor, powerful ATI integrated graphics, and one of the best keyboards weve tested on an ultraportable laptop. Is this the ideal companion for road warriors? Take a look at our review to find out.

    Lenovo ThinkPad X100e Specifications:


    • 1.6GHz AMD Athlon Neo Single-Core MV-40 Mobile Processor
    • 2GB PC2-5300 DDR2 (667MHz)
    • Windows 7 Professional 32bit
    • 11.6" WXGA HD anti-glare LED Backlit display (1366x768)
    • 250GB 5400RPM SATA Hard Drive
    • ATI Radeon 3200 Graphics
    • 802.11b/g/n, Gigabit LAN
    • 4-in-1 card reader and 0.3-megapixel webcam
    • 6-Cell Li-ion battery
    • Dimensions: (W x L x H) 11.1" x 8.2" x 0.6"/1.2"
    • Weight: 3.3 pounds (with 6-cell battery)
    • Price as configured: $569.00
     Read full review>>
    Read More..

    Copyright © 2014 Information Sharing | Powered By Blogger