JAVA, C#, VB.6.0, SQL, C, Computer Sci Free Computer Programming Tutorials: http://bagadhicomputersciencetutorials.blogspot.com/
Wednesday, 13 June 2018
Tower of Hanoi using recursion
#include<stdio.h>
void TOH(int num, char x, char y, char z);
int main() {
int num;
printf("\nEnter number of plates:");
scanf("%d", &num);
TOH(num - 1, 'A', 'B', 'C');
return (0);
}
void TOH(int num, char x, char y, char z) {
if (num > 0) {
TOH(num - 1, x, z, y);
printf("\n%c -> %c", x, y);
TOH(num - 1, z, y, x);
}
}
OUTPUT:-
void TOH(int num, char x, char y, char z);
int main() {
int num;
printf("\nEnter number of plates:");
scanf("%d", &num);
TOH(num - 1, 'A', 'B', 'C');
return (0);
}
void TOH(int num, char x, char y, char z) {
if (num > 0) {
TOH(num - 1, x, z, y);
printf("\n%c -> %c", x, y);
TOH(num - 1, z, y, x);
}
}
OUTPUT:-
C Program to Write inline assembly language code in C Program
#include<stdio.h>
void main() {
int a = 9, b = 9, c;
asm {
mov ax,a
mov bx,a
add ax,bx
mov c,ax
}
printf("%d",c);
}
OUTPUT:- 18
void main() {
int a = 9, b = 9, c;
asm {
mov ax,a
mov bx,a
add ax,bx
mov c,ax
}
printf("%d",c);
}
OUTPUT:- 18
C Program for sorting the list of names OR Strings
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main() {
char *str[5], *temp;
int i, j, n;
printf("\nHow many names do you want to have?");
scanf("%d", &n);
for (i = 0; i < n; i++) {
printf("\nEnter the name %d: ", i);
flushall();
gets(str[i]);
}
for (i = 0; i < n; i++) {
for (j = 0; j < n - 1; j++) {
if (strcmp(str[j], str[j + 1]) > 0) {
strcpy(temp, str[j]);
strcpy(str[j], str[j + 1]);
strcpy(str[j + 1], temp);
}
}
}
flushall();
printf("\nSorted List : ");
for (i = 0; i < n; i++)
puts(str[i]);
return (0);
}
OUTPUT:-
#include<string.h>
#include<stdlib.h>
int main() {
char *str[5], *temp;
int i, j, n;
printf("\nHow many names do you want to have?");
scanf("%d", &n);
for (i = 0; i < n; i++) {
printf("\nEnter the name %d: ", i);
flushall();
gets(str[i]);
}
for (i = 0; i < n; i++) {
for (j = 0; j < n - 1; j++) {
if (strcmp(str[j], str[j + 1]) > 0) {
strcpy(temp, str[j]);
strcpy(str[j], str[j + 1]);
strcpy(str[j + 1], temp);
}
}
}
flushall();
printf("\nSorted List : ");
for (i = 0; i < n; i++)
puts(str[i]);
return (0);
}
OUTPUT:-
Count Number of Words spaces vowels digits and special charecters using C
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<conio.h>
/*low implies that position of pointer is within a word*/
#define low 1
/*high implies that position of pointer is out of word.*/
#define high 0
void main() {
int nob, now, nod, nov, nos, pos = high;
char *str;
nob = now = nod = nov = nos = 0;
clrscr();
printf("Enter any string : ");
gets(str);
while (*str != '\0') {
if (*str == ' ') {
// counting number of blank spaces.
pos = high;
++nob;
} else if (pos == high) {
// counting number of words.
pos = low;
++now;
}
if (isdigit(*str)) /* counting number of digits. */
++nod;
if (isalpha(*str)) /* counting number of vowels */
switch (*str) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
++nov;
break;
}
/* counting number of special characters */
if (!isdigit(*str) && !isalpha(*str))
++nos;
str++;
}
printf("\nNumber of words %d", now);
printf("\nNumber of spaces %d", nob);
printf("\nNumber of vowels %d", nov);
printf("\nNumber of digits %d", nod);
printf("\nNumber of special characters %d", nos);
getch();
}
OUTPUT:-
#include<stdlib.h>
#include<ctype.h>
#include<conio.h>
/*low implies that position of pointer is within a word*/
#define low 1
/*high implies that position of pointer is out of word.*/
#define high 0
void main() {
int nob, now, nod, nov, nos, pos = high;
char *str;
nob = now = nod = nov = nos = 0;
clrscr();
printf("Enter any string : ");
gets(str);
while (*str != '\0') {
if (*str == ' ') {
// counting number of blank spaces.
pos = high;
++nob;
} else if (pos == high) {
// counting number of words.
pos = low;
++now;
}
if (isdigit(*str)) /* counting number of digits. */
++nod;
if (isalpha(*str)) /* counting number of vowels */
switch (*str) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
++nov;
break;
}
/* counting number of special characters */
if (!isdigit(*str) && !isalpha(*str))
++nos;
str++;
}
printf("\nNumber of words %d", now);
printf("\nNumber of spaces %d", nob);
printf("\nNumber of vowels %d", nov);
printf("\nNumber of digits %d", nod);
printf("\nNumber of special characters %d", nos);
getch();
}
OUTPUT:-
C Program to display mouse pointer
#include<stdio.h>
#include<dos.h>
int initmouse();
void showmouseptr();
union REGS i, o;
int main() {
int status;
status = initmouse();
if (status == 0) {
printf("Mouse support not available.n");
} else {
showmouseptr();
}
return 0;
}
int initmouse() {
i.x.ax = 0;
int86(0X33, &i, &o);
return (o.x.ax);
}
void showmouseptr() {
i.x.ax = 1;
int86(0X33, &i, &o);
}
#include<dos.h>
int initmouse();
void showmouseptr();
union REGS i, o;
int main() {
int status;
status = initmouse();
if (status == 0) {
printf("Mouse support not available.n");
} else {
showmouseptr();
}
return 0;
}
int initmouse() {
i.x.ax = 0;
int86(0X33, &i, &o);
return (o.x.ax);
}
void showmouseptr() {
i.x.ax = 1;
int86(0X33, &i, &o);
}
Subscribe to:
Posts (Atom)