Wednesday, 5 November 2014

How to find the sizeof Data type and Display in Decemial,Octal and HexaDecimal format in C

void main() { int i; float r; printf("welcome to kmit\n"); printf("welcome to Telengana\n"); i=15; //i=35.756; r=105643.7564; printf("%d\n",i); printf("%0.4f\n",r); printf("%d\n",sizeof(i)); printf("%d\n",sizeof(r)); printf("%d\n",i);//display in decimal printf("%o\n",i);//display in Octal printf("%0x\n",i);//display in Hexadecimal }

Radix sort program in C

#include <stdio.h> struct radix { struct radix *link; int info; }*start; void display(); int ndig(); int kdig(int,int); void radixsort(); void main() { struct radix *temp,*q; int i,j,k,item; printf("enter no of items : "); scanf("%d",&item); for(i=0;i<item;i++) { printf("enter the item %d :\n",i+1); scanf("%d",&j); temp=(struct radix*)malloc(sizeof(struct radix)); temp->info=j; temp->link=NULL; if(start==NULL) start =temp; else { q=start; while(q->link!=NULL) q=q->link; q->link=temp; } } printf("unsorted list is: \n"); display(); radixsort(); printf("\nsorted list : \n"); display(); } void display() { struct radix *temp; temp=start; while(temp!=NULL) { printf("%d\t",temp->info); temp=temp->link; } } int ndig() { struct radix *temp; int large=0,ndig=0; temp=start; while(temp!=NULL) { if(temp->info>large) large=temp->info; temp=temp->link; } while(large>0) { ndig++; large=large/10; } return(ndig); } int kdig(int num,int k) { int i,dig; for(i=1;i<=k;i++) { dig=num%10; num=num/10; } return dig; } void radixsort() { struct radix *p,*front[10],*rear[10]; int mindig,maxdig,lstsig,maxsig,k,i,dig; lstsig=1; maxsig=ndig(); for(k=lstsig;k<=maxsig;k++) { for(i=0;i<=9;i++) { rear[i]=NULL; front[i]=NULL; } mindig=9; maxdig=0; p=start; while(p!=NULL) { dig=kdig(p->info,k); if(dig>maxdig) maxdig=dig; if(dig<mindig) mindig=dig; if(front[dig]==NULL) front[dig]=p; else rear[dig]->link=p; rear[dig]=p; p=p->link; } printf("\nmindig %d maxdig %d",mindig,maxdig); start=front[mindig]; for(i=mindig;i<maxdig;i++) { if(rear[i+1]!=NULL) rear[i]->link=front[i+1]; else rear[i+1]=rear[i]; rear[maxdig]->link=NULL; } printf("\nnew list\n"); display(); } }