#include <stdio.h>
#include<conio.h>
void main()
{
char letter;
int vowel_count = 0;
clrscr();
for (letter = 'A'; letter <= 'Z'; letter++)
switch (letter) {
case 'A':
case 'E':
case 'I':
case 'O':
case 'U': vowel_count++;
};
printf("The number of vowels is %d\n", vowel_count);
getch();
}
A Program to utilize message queue for implementing the merge sort(Socket Programming)
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <sys/wait.h>
#include<stdlib.h>
#include<stdio.h>
#define MAXLINE 1000
struct mymesg
{
long mtype;
int a[4];
};
void Merge(int a[],int mer[],int ct)
{
if(ct==0)
{
ct+=4;
for(int i=1;i<=ct;i++)
mer[i]=a[i];
}
else
{
for(int i=1;i<=4;i++)
{
int j=1;
while(a[i]>mer[j]&&j<=ct)j++;
if(j>ct)
mer[j]=a[i];
else
{
for(int k=ct;k>=j;k--)
mer[k+1]=mer[k];
mer[j]=a[i];
}
ct++;
}
}
}
int main()
{
int n,pid,mpid,sum,b[17],mer[17],num=16;
mpid=msgget(12,0666|IPC_CREAT);
system("clear");
printf("Elements are...
");
for(int i=1;i<=num;i++)
{
b[i]=rand()%150;
printf("%d ",b[i]);
}
printf("
");
int i,ct=1,gmax;n=4;sum=0;gmax=4;
for(i=1;i<=n;i++)
{
struct mymesg ptr;
ptr.mtype=1;
pid=fork();
if (pid>0)
{
int k=0;
printf("Group %d: ",i);
for(int j=ct;j<=ct+gmax-1;j++)
{
ptr.a[++k]=b[j];
printf("%d ",ptr.a[k]);
}
printf("
");
msgsnd(mpid,&ptr,MAXLINE,IPC_NOWAIT);
waitpid(pid,NULL,0);
msgrcv(mpid,&ptr,MAXLINE,0,IPC_NOWAIT);
printf("Sorted Sub-Group %d: ",i);
for(int j=1;j<=gmax;j++)
printf("%d ",ptr.a[j]);
printf("
");
Merge(ptr.a,mer,ct-1);
if(ct==num+1-gmax)
break;
ct+=gmax;
continue;
}
else
{
msgrcv(mpid,&ptr,MAXLINE,0,IPC_NOWAIT);
for(int j=1;j<=gmax;j++)
{
for(int k=1;k<=gmax-j;k++)
{
if(ptr.a[k]>ptr.a[k+1])
{
int t=ptr.a[k+1];
ptr.a[k+1]=ptr.a[k];
ptr.a[k]=t;
}
}
}
ptr.mtype=2;
msgsnd(mpid,&ptr,MAXLINE,IPC_NOWAIT);
exit(0);
}
}
printf("Merged Sorted Group....
");
for(int i=1;i<=num;i++)
printf("%d ",mer[i]);
printf("
");
return 0;
}
#include<stdio.h>
#include<dos.h>
#include<conio.h>
#include<graphics.h>
void theend();
static int mask[]={/*SCREEN MASK*/
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,
/*CURSOR MASK*/
0x0000,0x0000,0x381c,0x7c3e,0x7c3e,0x7c3e,0x7c3e,
0x3bdc,0x07e0,0x0ff0,0x0ff0,0x0ff0,0x0ff0,0x07e0,
0x03c0,0x0000};
void main()
{int gdriver=DETECT,gmode,buttons;
union REGS regs;
struct SREGS sregs;
initgraph(&gdriver,&gmode,"");
regs.x.ax=0; /*INITIALIZE MOUSE*/
int86(0x33,®s,®s);
setcolor(LIGHTCYAN);
if(regs.x.ax==0)
{outtextxy(0,0,"NO MOUSE AVAILABLE");
getch();
theend();
}
regs.x.ax=9; /*CHANGE CURSOR SHAPE*/
regs.x.bx=5;
regs.x.cx=0;
regs.x.dx=(int)mask;
segread(&sregs);
sregs.es=sregs.ds;
int86x(0x33,®s,®s,&sregs);
regs.x.ax=1; /*SHOW MOUSE POINTER*/
int86(0x33,®s,®s);
do
{regs.x.ax=3;
int86(0x33,®s,®s);
buttons=regs.x.bx & 3;
}while(buttons!=3);
regs.x.ax=2; /*HIDE MOUSE POINTER*/
int86(0x33,®s,®s);
theend();
}
void theend()
{
closegraph();
}