Format Specifiers in C | |
%i or %d | int |
%c | char |
%f | float |
%lf | double |
%s | string |
%hi | short |
%ld | long int |
%d,%hu | unsinged short |
%u | unsinged int |
- \n (newline)
- \t (tab)
- \v (vertical tab)
- \f (new page)
- \b (backspace)
- \r (carriage return)
Format Specifiers in C | |
%i or %d | int |
%c | char |
%f | float |
%lf | double |
%s | string |
%hi | short |
%ld | long int |
%d,%hu | unsinged short |
%u | unsinged int |
/*
* FormatSpecifiers.c
* Copyright 2013 Afiz <afiz@afiz-Extensa-4620>
*/
#include <stdio.h>
int main(int argc, char **argv)
{
int a =109990909;
short b = 23;
printf("%d,%hi\n",a,b);
return 0;
}
Bubble sort: comparisons O(n2), Swaps O(n2)
Selection Sort: Comparisons O(n2), swaps O(n)
Insertion Sort: Comparisons O(n2) , no swaps
Insertion sort is best basic sorts.
/*
This is a basic program of Selection sort.
Author: Afiz
Date:
*/
#include<stdio.h>
main()
{
int a[5]={9,7,4,8,1};// array with 5 elements.
int out,in,min,i;// local variable declarations
for(out =0;out<4;out++)// outer loop
{
min =out;
for(in=out+1;in<5;in++)// inner loop
{
if(a[in]<=a[min])
min=in;
}
int tmp = a[min]; // swap ....
a[min]=a[out];
a[out]=tmp;
}
//printing array
for(i=0;i<5;i++)
{
printf("%d\n",a[i]);
}
}
/*
This is a basic program of Insertion sort.
Author: Afiz
Date:
*/
#include<stdio.h>
main()
{
int a[5]={9,7,4,8,1};// array with 5 elements.
int out,in,min,i;// local variable declarations
for(out=1;out<5;out++) // outer loop
{
temp = a[out];
in =out;
while(in>0 && a[in-1]>=temp) // inner loop
{
a[in]=a[in-1];
--in;
}
a[in]=temp;
}
//printing array ..
for(i=0;i<5;i++)
{
printf("%d\n",a[i]); //
}
}
/*
This is a basic program of Bubble sort.
Author: Afiz
Date:
*/
#include<stdio.h>
main()
{
int a[5]={5,5,1,7,-1}; // array with 5 elements.
int i,j; // local variable declarations
for(i=0;i<5;i++)// outer loop
{
for(j=1;j<5-i;j++) // outter loop
{
if(a[j-1]>=a[j])
{
int tmp = a[j-1]; // swap
a[j-1]=a[j];
a[j]=tmp;
}
}
}
//printing array
for(i=0;i<5;i++)
{
printf("%d\n",a[i]);
}
}
/* Doubly linked list */
/* This program seg,ent creates a doubly linked list then prints in forward and backword */
/* Double_l.c */
#include <stdio.h>
#include <malloc.h>
void main(void)
{
int i;
struct ListEntry {
int number;
struct ListEntry *next;
struct ListEntry *previous;
} start, *node;
start.next = NULL; /* Empty list */
start.previous = NULL;
node = &start; /* Point to the start of the list */
for (i = 1; i <= 10; i++)
{
node->next = (struct ListEntry *) malloc(sizeof(struct ListEntry));
node->next->previous = node;
node = node->next;
node->number = 50+i;
node->next = NULL;
}
/* Display the list */
node = start.next;
do {
printf("%d ", node->number);
node = node->next;
} while (node->next); /* Show 60 only one time */
do {
printf("%d ", node->number);
node = node->previous;
} while (node->previous);
}