c program

1 Comment

C Program to convert IP address to 32-bit long int

Source: Dr. G T Raju, Professor & Head, Dept. of CSE, RNSIT 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 #include <stdio.h> #include <string.h> #include <stdlib.h> union iptolint { char ip[16]; […]

2 Comments

C program to implement linked list

Below given C program implements linked list 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 […]

17 Comments

C program to implement Circular Queue operations

Below C program implements various Circular Queue operations 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 […]

No Comments

Program to arrange the string in alphabetical order

Here is the program to arrange the string in alphabetical order. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 #include "stdio.h" #include "conio.h" #include "string.h" void main() { char str[10],temp; int i,j; clrscr(); printf("\nEnter the string : "); scanf("%s",str); for(i=0;i<strlen(str);i++) for(j=0;j<strlen(str);j++) if(str[i]<str[j]) […]

2 Comments

Binary Search

A binarysearch program locates the position of an item in a sorted array. Logic: The Binary search starts by testing the element at the middle of the array. Let us consider an array ‘a’ with all elements arranged in ascending order. Let low and high are the lower and upper indices of the array ‘a’, respectively. We want to search an item […]

7 Comments

C program to implement tower of Hanoi problem

To implement tower of Hanoi problem. #include<stdio.h> void hanoi_tower(char,char,char,int); void hanoi_tower(char peg1,char peg2,char pege3,int n) { if(n<=0) printf("\n Illegal Entry"); if(n==1) printf ("\n Move disk from %c to %c", pege1,pege3); else { hanoi_tower(peg1,peg3,peg2,n-1); hanoi_tower(peg1,peg2,peg3,1); hanoi_tower(peg2,peg1,peg3,n-1); } } Void main () { int n; printf("\n Input the number of dise:); scanf("%d", &n); printf("\n Tower of Hanoi […]

6 Comments

C program to Implement Morse code to text conversion and vice-versa.

C program to Implement Morse code to text conversion and vice-versa. #include<stdio.h> #include<conio.h> #include<string.h> #include<process.h>   void main() { char str[25],str1[100]; clrscr(); fflush(stdin); printf("enter the String"); gets(str);   int j=0; for(int i=0;i<=strlen(str);++) { switch(toupper(str[i])) { case ‘A’: str1[j++]=’.’; str1[j]=’.’; break;   case ‘b’: str1[j++]=’.’; str1[j++]=’.’; str1[j++]=’.’; str1[j]=’.’; break;   case ‘c’: str1[j++]=’.’; str1[j++]=’.’; str1[j++]=’.’; str1[j]=’.’; […]

1 Comment

C++ program using class to multiply by 10 to every member of a list

Write a program using class which reads a list of N number of integer type in an array. It modifies the list by multiplying 10 to every number of the list. The modified list is displayed. #include<iostream.h> #include<conio.h> class array { public: void readarray(); void multiply(); }; void array::readarray() { int a[10]; cout<<"Enter the elements […]

No Comments

C program to calculate the GCD of a number

Write a program to calculate the Greatest Common Divisor(GCD) of a number #include<stdio.h> #include<conio.h> #include<process.h> int gcd(int m,int n) { int rem; while(n!=0) { rem=m%n; m=n; n=rem; } return(m); } main() { int num1,num2,num3,gcd1,gcd2; clrscr(); printf("Enter three positive integers"); scanf("%d%d%d",&num1,&num2,&num3); if(num1==0 && num2==0 && num3==0) { printf("\n Invalid number"); exit(0); } gcd1=gcd(num1,num2); gcd2=gcd(num3,gcd1); printf("\n GCD […]