C Program to show method of Insertion Sort

C Program to show method of Insertion Sort



#include
#include
#include

/* The Insertion Sort. */
void insert(char *items, int count)
{

register int a, b;
char t;

for(a=1; a < count; ++a) {
t = items[a];
for(b=a-1; (b >= 0) && (t < items[b]); b--)
items[b+1] = items[b];
items[b+1] = t;
}
}


int main(void)
{

char s[255];

printf("Enter a string:");
gets(s);
insert(s, strlen(s));
printf("The sorted string is: %s.\n", s);

return 0;
}


C Program to swap two numbers

C Program to swap two numbers




#include
#include
void main()
{
int a,b,t;
clrscr();
printf("enter the value of a and b");
scanf("%d%d",&a,&b);
t=a;
a=b;
b=t;
printf("a=%d,b=%d",a,b);
getch();
}


C Program to Print Acsii Value of Given Number

C Program to Print Acsii Value of Given Number

#include
#include
void main()
{
char ch;
clrscr();
printf("enter any character");
scanf("%c",&ch);
printf("ch=%d",ch);
getch();
}



C Program to find absolute value of given number

C Program to find absolute value of given number




#include
#include
void main()
{
int a,b;
clrscr();
printf("enter the value of a");
scanf("%d",&a);
if(a<0)
{
b=a*-1;
printf("\nabsolute value of %d is %d",a,b);
}
else
{
printf("\nabsolute value=%d",a);
}
getch();
}