Category: Programs

Binary Search Program in C using Recursive and Non-Recursive Methods

/* Binary search program in C using both recursive and non recursive functions */ include define MAX_LEN 10 /* Non-Recursive function*/void b_search_nonrecursive(int l[],int num,int ele){int l1,i,j, flag = 0;l1 = 0;i = num-1;while(l1 <= i){j = (l1+i)/2;if( l[j] == ele){printf(“\nThe element %d is present at position %d in list\n”,ele,j);flag =1;break;}elseif(l[j] < ele)l1 = j+1;elsei = …

Start reading Binary Search Program in C using Recursive and Non-Recursive Methods

Decimal to Binary Conversion Using C

void binary(int val);int main(){int a,b;printf(“Enter the number in decimal:”);scanf(“%d”,&a);printf(“Number in Binary form: “);binary(a);return 0;}void binary(int val){int r;r=val%2;val=val/2;if(val==0){printf(“%d”,r);}else{binary(val);printf(“%d”,r);}} OUTPUT: Enter the number in decimal:10Number in Binary form: 1010

Start reading Decimal to Binary Conversion Using C

Compute Factorial of Large Numbers using C

int main(){int a[200],n,counter,temp,i;a[0]=1;counter=0;printf(“Enter the number to Find Factorial: “);scanf(“%d”,&n);for(; n>=2; n–){temp=0;for(i=0; i<=counter; i++) { temp=(a[i]*n)+temp; a[i]=temp%10; temp=temp/10; } while(temp>0){a[++counter]=temp%10;temp=temp/10;}}for(i=counter; i>=0; i–)printf(“%d”,a[i]);return 0;}OUTPUT: Enter the number to Find Factorial: 10093326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000

Start reading Compute Factorial of Large Numbers using C

C Program to Implement RADIX SORT

// Function to find largest elementint largest(int a[], int n){int large = a[0], i;for(i = 1; i < n; i++){if(large < a[i])large = a[i];}return large;} // Function to perform sortingvoid RadixSort(int a[], int n){int bucket[10][10], bucket_count[10];int i, j, k, remainder, NOP=0, divisor=1, large, pass; } //program starts hereint main(){int i, n, a[10];printf(“Enter the number of …

Start reading C Program to Implement RADIX SORT

Implementation of Stack Using Array in C

PUSH function in the code is used to insert an element to the top of stack, POP function used to remove the element from the top of stack. Finally, the display function in the code is used to print the values. All stack functions are implemented in C Code. include int stack[100],choice,n,top,x,i;void push(void);void pop(void);void display(void);int …

Start reading Implementation of Stack Using Array in C

Page Replacement Programs in C

int n,nf;int in[100];int p[50];int hit=0;int i,j,k;int pgfaultcnt=0; void getData(){printf(“\nEnter length of page reference sequence:”);scanf(“%d”,&n);printf(“\nEnter the page reference sequence:”);for(i=0; i<n; i++)scanf(“%d”,&in[i]);printf(“\nEnter no of frames:”);scanf(“%d”,&nf);} void initialize(){pgfaultcnt=0;for(i=0; i<nf; i++)p[i]=9999;} int isHit(int data){hit=0;for(j=0; j<nf; j++){if(p[j]==data){hit=1;break;} } int getHitIndex(int data){int hitind;for(k=0; k<nf; k++){if(p[k]==data){hitind=k;break;}}return hitind;} void dispPages(){for (k=0; k<nf; k++){if(p[k]!=9999)printf(” %d”,p[k]);} } void dispPgFaultCnt(){printf(“\nTotal no of page faults:%d”,pgfaultcnt);} void fifo(){initialize();for(i=0; …

Start reading Page Replacement Programs in C

C Program for Fibonacci Series using While Loop

int main(){int f1=0,f2=1,f3,i=3,len;printf(“enter length of the fibonacci series:”);scanf(“%d”,&len);printf(“%d\t%d”,f1,f2); // It prints the starting two valueswhile(i<=len) // checks the condition{f3=f1+f2; // performs add operation on previous two valuesprintf(“\t%d”,f3); // It prints from third value to given lengthf1=f2;f2=f3;i=i+1; // incrementing the i value by 1}return 0;} Output for Fibonacci Series Program enter length of the fibonacci series:100 …

Start reading C Program for Fibonacci Series using While Loop

C Program to Find Sum of Individual Digits of a Positive Integer Number

The following C program describes the sum of individual digits of a given positive integer.  Example: 456 as 4+5+6 = 15 include include void main(){int n,sum=0;printf(“enter a +ve integer”); // enter a integer valuescanf(“%d”,&n);while(n>0) // checks the condition{sum=sum+n%10; // sum + remainder valuen=n/10; } OUTPUT: enter a +ve integer456 sum of individual digits of a …

Start reading C Program to Find Sum of Individual Digits of a Positive Integer Number