This is a simple computer graphics lab program in c language to display a rainbow. Since BGI (Borland Graphics Interface) supports only 16 colors, the rainbow cannot be shown in correct colors (VIBGYOR). This is because, colors like violet, indigo and orange are not available in BGI. There fore, we just use some available color instead. The following is the program.
Search This Blog
Showing posts with label display. Show all posts
Showing posts with label display. Show all posts
How to Create process and display Process ID (pid) of Both Parent and Child
This program shows how to create process and display Process ID (pid) of Both Parent and Child processes. The process is created using the fork system call in UNIX (Linux) operating systems.
#include<stdio.h>
#include<dirent.h>
main(int argc,char **argv)
{
int pid,i;
for(i=0;i<atoi(argv[1]);i++)
{
pid=fork();
if(pid==0)
{
printf("child process id %d Parent process
id %d\n",getpid(),getppid());
}}}
#include<stdio.h>
#include<dirent.h>
main(int argc,char **argv)
{
int pid,i;
for(i=0;i<atoi(argv[1]);i++)
{
pid=fork();
if(pid==0)
{
printf("child process id %d Parent process
id %d\n",getpid(),getppid());
}}}
C Program to Show Process ID in Linux
This program is to show the process id (pid) in UNIX or Linx
The system call getpid() returns the process id of current process.
#include<stdio.h>
int main()
{
printf("\n Parent Process ID %d",getppid());
}
The system call getpid() returns the process id of current process.
#include<stdio.h>
int main()
{
printf("\n Parent Process ID %d",getppid());
}
C Program to Display SCAN and ASCII Codes of Keys on Keyboard Using 8086 Interrupt
![]() |
| Output (ASCII and SCAN code) when a is pressed |
The interrupt stores scan code in higher byte of accumulator and ASCII code in lower byte of accumulator.
8086 interrupt number 16h (hexadecimal) to read a keystroke from keyboard. The condition for this interrupt is that the higher byte of accumulator (AH) should be 00h.
#include<stdio.h>
#include<dos.h>
#include<conio.h>
void main()
{
union REGS inregs,outregs; //declaring 2 register files
clrscr();
inregs.h.ah=0x0; //pre-requisite for desired operation of interrupt 16h
int86(0x16,&inregs,&outregs); //calling interrupt 16h
printf("\nScan Code :%d\nASCII code:%d\n",outregs.h.ah,outregs.h.al);
getch();
}
Program to Display All Armstrong Numbers upto 1000
This post is for C program to display all Armstrong numbers less than 1000. But before all, I should tell what an Armstrong number is. An Armstrong number is a number that is the sum of its own digits each raised to the power of the number of digits. Consider an example. 153 is an Armstrong number. Since it is a 3 digit number, to check whether it is an Armstrong number or not, we should add the 3rd power digits together. So, in the program, we should have a code to determine number of digits in number, then add the nth powers (where n is the number of digits) of each digit in the number and check whether both the sum and original number are the same.
#include<stdio.h>
#include<math.h>
void main()
{
int n,sum,r,digits;
for(n=1;n<=1000;n++)
 {
digits=0;
r=n;
sum=0;
while(r!=0) //Counting Digits
{
digits++;
r/=10;
}
r=n;
while(r!=0) /*Adding Digits Raised To a Power That Is Equal To Number of Digits *
{
sum+=pow((r%10),digits);
r=r/10;
}
if(sum==n)
{
printf("%5d",sum);
}
}
}
Subscribe to:
Posts (Atom)
