Saturday, 3 August 2013

Facebook Page of Innovators With C

After huge demand of students, we have recently created Facebook Page of Innovators With C for C/C++ programming. On this page we will be updating the information and posts about this website. If you are on facebook, you can like this page just by clicking on LIKE button on the right side of Facebook Page. Innovators With C Programming Facebook Page will provide you material about Programming Language and other related references about C/C++ programming and concepts

Join us on Facebook Now :)

break and continue Statement

There are two statement built in C, break; and continue; to interrupt the normal flow of control of a program. Loops performs a set of operation repeatedly until certain control variable fails but, it is sometimes desirable to skip some statements inside loop and terminate the loop immediately without checking the test expression. In such cases, break and continue statements are used.

C break statement:
In C programming, break is used in terminating the loop immediately after it is encountered. The break statement is used with conditional if statement.

Syntax of break statement:

break; 
 
The break statement can be used in terminating all three loops for, while and do...while loops.


For better understanding of how break statements works in C programming loops. Analyze the illustration of exiting a loop with break statement below.


C continue statement:
It is sometimes desirable to skip some statements inside the loop. In such cases, continue statements are used. Continue statements are only used in while, do...while and for loops in C programming.

Syntax of continue statement:
continue; 
 
Just like break, continue is also used with conditional if statement.

 For better understanding of how continue statements works in C programming. Analyze the illustration of bypassing and continuing in loops below.



Program to Implement Bubble Sort

#include<stdio.h>
#include<conio.h>
void main()
{           
int a[10],i,j,n,temp;
clrscr();
printf(“Enter the size of arrary\n”);
scanf(“%d”,&n);
printf(“Enter %d elements \n”);
for(i=1;i<=n;i++)
{
scanf(“%d”,&a[i]);
}
for(i=1;i<=n;i++)
{
for(j=1;j>i;j--)
{
if(a[j]<a[j-1])
{
temp=a[j];
a[j]=a[j-1];
a[j-1]=temp;
}
}
}
printf(“The sorted Array is\n”);
for(j=1;j<=n;j++){
printf(“%d”,a[j]);
}
getch();

}

Program to Implement Binary Search

#include<stdio.h>
#include<conio.h>
void main()
{
int beg, mid, end,a[20],item,loc,i,n;
clrscr();
printf(“Enter the size\n”);
scanf(%d”,&n);
printf(“Enter the elements\n”);
for(i=1;i<=n;i++)
{
scanf(“%d”,&a[i]);
}
beg=1;
end=n;
mid=(beg+end)/2;
printf(“Enter the item to be searched\n”);
scanf(“%d”,&item);
while((beg<=end)&&(a[mid]!=item))
{
if(item<a[mid])
{
end=mid-1;
}
else
{
beg=mid+1;
}
mid=(beg+end)/2;
}
printf(“The item is at mid = %d”,mid);
if(beg>end)
{
loc=0;
}
else
{
loc=mid;
}
printf(“The location of the item\n”);
printf(“%d”, loc);
getch();

Program to Implement the Link List

#include<stdio.h>
#include<conio.h>
#include<alloc.h>
struct Node
{
int info;
struct Node *link;
};
struct Node *first;
void main()
{
create();
traverse();
insert();
}
void create()
{
struct Node *ptr, *cpt;
char ch;
ptr=(struct Node *) malloc(size of(struct Node));
printf(“Enter the first Node”);
scanf(“%d”,&ptr->info);
first=ptr;
}
do
{
cpt=(struct Node*) malloc(size of(struct Node));
printf(“Enter the next node”);
scanf(“%d”,&cpt->info);
ptr->link=cpt;
ptr=cpt;
printf(“Enter Y to continue”);
scanf(“%c”,&ch);
}
while(ch==’Y’);
ptr->link=first;
}
void traverse()
{
struct Node *ptr;
printf(“Traverse is”);
ptr=first;
while(ptr!=first);
{
printf(“%d”,ptr->info);
ptr=ptr->link;
}
}
void insert()
{
struct Node *ptr;
ptr=(struct Node*)malloc(size of(struct Node));
if(ptr==NULL)
}
printf(“Overflow”);
return;
}
printf(“Enter the info into new”);
scanf(“%d”,&ptr->info);
ptr->link=start;
start=ptr;

}

Algorithm for Searching

This algorithm finds the location LOC of the node where ITEM first appear in the LIST.
  1. PTR=START
  2. Repeat Step 3 and 4 while PTR !=NULL
  3. If ITEM=INFO[PTR]Set LOC = PTR and ExitElsePTR=LINK[PTR]Set LOC=NULL
  4. Exit

Algorithm for Traversing a Link List

Let LIST be a link list, START point to first node in the link list and NULL should be the end of LIST. A pointer variable PTR which point to the node i.e. currently being in process, LINK[PTR] point to the nest node to be process i.e. PTR=LINK[PTR] moved the pointer to the next node in the list.
  1. PTR=START
  2. Repeat Step 3 and 4 while PTR != NULL
  3. Apply process to INFO[PTR]
  4. PTR=LINK[PTR]
  5. Exit

Program to perform an operation on Queue

#include<stdio.h>
#include<conio.h>
void main()
{
int a[5],i,F=0,R=0,n,m,item;
clrscr();
do
{
printf(“Enter your choice 1-Insertion\n 2-Deletion\n 3-Display\n”);
scanf(“%d”,&n);
switch(n)
{
case 1:
{
if(R==0)
{
printf(“Overflow”);
exit (0);
}
else if(F==0 && R==0)
{
F=1;
R=1;
printf(“Enter the element to Insert\n”);
scanf(“%d”,&item);
a[R]=item;
}
else
{
printf(“Enter the element to insert\n”);
scanf(“%d”,&item);
R=R+1;
a[R]=item;
}
break;
}
case 2:
{
if(R==0)
{
printf(“Underflow”);
}
else
{
item=a[F];
F=F+1;
printf(“The deleted element is \n %d\n”,item);
}
break;
}
case 3:
{
for(i=R;i>=F;i--)
{
printf(“%d\n”,a[i]);
}
break;
}
default:
{
printf(“Invalid Input”);
break;
}
}
printf(“Press 5 to continue:\n”);
scanf(“%d”,&n);
}
while(m==5)
getch();

}