Program to swap the numbers by Call By Referance in C



#include
#include
main()
{
clrscr();
int a=10,b=20;
void swapr(int*,int*);
clrscr();
printf("\nEnter The Vale Of A & B:=");
scanf("%d%d",&a,&b);
printf("\n\t A=%d",a);
printf("\n\t B=%d",b);
swapr(a,b);
printf("\n\n\tAfter Sweping The Value");
printf("\n\n\t A=%d",a);
printf("\n\t B=%d",b);
getch();
}
void swapr(int,int)
int *x,*y;
{
int *z=0;
*z=*x;
*x=*y;
*y=*z;
}


Related Links :

Program to create rectangle


#include
main()
{
int driver,mode,i=10;
driver=0;
mode=VGAHI;
initgraph(&driver,&mode,"\\tc\\bgi");
for(i=10;i<=100;i+10)
{
rectangle(254,236,456,368);
clearviewpart();
delay(500);
moveto(i,i);
}
getch();
restorecrtmode();
closegraph();
}

Related Links :

Program to Show Pointer example by using %u


main()
{
int num[3];
int n,i,*j;
clrscr();
printf("enter the number:-");
scanf("%d",&n);
j=&num[0];
for(i=0;i<=n;i++)
{
printf("\naddress=%u",j);
printf("\n element=%d",i);
j++;
}
getch();
}

Related Links :

Program to calculate Total, Performance and average of given numbers in c



main()
{
int match1, match2, pr, tot;
clrscr();
printf("\n enter match1, match2");
scanf("%d %d", &match1,&match2);
tot=match1 + match2;
printf("\n total= %d", tot);
pr=tot/2;
printf("\n percentage=%d", pr);
if(pr> 100)
{
printf(" normal performance");
}
if(pr<50)
printf("\n Your Very bad");
getch();
}

Related Links :

Program to Frind the biggest and smallest number from given array set


main()
{
int array[]={5,66,76,34,23,51,94,18,35};
int i,count,large=1,small=32767,n;
clrscr();
for(count=0;count<=9;count++)
{
printf("\n %d-------> %d",count,array[count]);
}

for(count=0;count<=9;count++)
{
if(large < array[count])
{
large = array[count];

}
if(small >= array[count])
{
small=array[count];
}
}
printf("\n largest no in the array is %d",large);
printf("\n smallest no in the array is %d",small);
getch();
}


Related Links :

Program to create pyramid of Star in C


#include
#include
void main()
{
int i,j,k,s,n;
printf(" ENTER THE NO OF ROWS");
scanf("%d",&n);

for(i=1,s=n;i<=n;i++,s--)
{
for(k=1;k<=s;k++)
printf(" ");
for(j=1;j<=i;j++)
printf("*");
printf(" ");
}
getch();
}

Related Links :

Program to create double pyramid in C


#include
#include
void main(void)
{
clrscr();
int i,j,k,l,b,n;
printf("Enter the value of N:");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
printf(" ");
for(l=0;l<=i;l++)
printf(" ");
for(j=i+1;j<=n;j++)
printf("%d",j);
for(k=n-1;k>i;k--)
printf("%d",k);
}
b=n-1;
for(i=0;i<=n-1;i++)
{
printf(" ");
for(l=n-2;l>=i;l--)
printf(" ");
for(j=b;j<=n;j++)
printf("%d",j);
for(k=n-1;k>=b;k--)
printf("%d",k);
b--;
}
getch();
}


Related Links :

Program to show Palindrome Verification in C, string is Palindrome or Not.



int palindrome( char* string )
{
int i = 0, j = strlen( string ) - 1;

while( i < j / 2 )
{

if( string[ i++ ] == string[ j-- ] )
;
else
{
printf( "The String is not Palindrome" );
return -1;
}
}

printf( "The string is Palindrome" );
return 0;
}

int main( )
{
palindrome( "Info " );
palindrome( "Computers" );
return 0;
}


Related Links :

Program Showing Binary Equivalent of an Integer in C



main()
{
int n;
char ch;
while(1)
{
clrscr();
printf("Enter an integer to see its Binary Equivalent");
printf("Enter ");
scanf("%d",&n);
showbits(n);

printf("continue ?");
ch=getch();
if(ch==27)
break;
}
}/*End of main()*/

showbits(int n)
{
int i,bit,mask,count=0;
printf(" ");
for(i=15;i>=0;i--)
{
mask=1<
bit=n & mask;

if(bit==mask)
printf("1");
else
printf("0");
count++;
if(count%4==0)
printf(" ");
}
}/*End of showbits()*/

Related Links :

CPU scheduling (Round Robin) Program in C


#include
#include
main()
{
int st[10],bt[10],wt[10],tat[10],n,tq;
int i,count=0,swt=0,stat=0,temp,sq=0;
float awt=0.0,atat=0.0;
clrscr();
printf("Enter number of processes:");
scanf("%d",&n);
printf("Enter burst time for sequences:");
for(i=0;i<=n;i++)
{
scanf("%d",&bt[i]);
st[i]=bt[i];
}
printf("Enter time quantum:");
scanf("%d",&tq);
while(1)
{
for(i=0,count=0;i<=n;i++)
{
temp=tq;
if(st[i]==0)
{
count++;
continue;
}
if(st[i]=>tq)
st[i]=st[i]-tq;
else
if(st[i]>=0)
{
temp=st[i];
st[i]=0;
}
sq=sq+temp;
tat[i]=sq;
}
if(n==count)
break;
}
for(i=0;i<=n;i++)
{
wt[i]=tat[i]-bt[i];
swt=swt+wt[i];
stat=stat+tat[i];
}
awt=(float)swt/n;
atat=(float)stat/n;
printf("Process_no Burst time Wait time Turn around time
");
for(i=0;i<=n;i++)
printf("%d %d %d %d
",i+1,bt[i],wt[i],tat[i]);
printf("Avg wait time is %f
Avg turn around time is %f",awt,atat);
getch();
}


Related Links :

Program to create Pyramid of Numbers in C



#include
#include

int pyramid( int length )
{
int line = 1;
int j = 1, i, k = length;

while( length-- )
{

if( j == 1 ) {
for( i = 1; i <= length + 5; i++ )
printf( " " );
printf( "%d", j++ );
k--;
line++;
}

else if( i % 2 ){
for( i = 1; i <= length + 5; i++ )
printf( " " );
for( i = 1; i <= line; i++ )
printf( "%d ", ( j++ % 10 ) );
printf( " " );
line++;
k--;
}

else {
for( i = 1; i <= length + 5 ; i++ )
printf( " " );
for( i = 1; i <= line; i++ )
printf( "%d ", ( j++ % 10 ) );
printf( " " );
line++;
k--;
}
}

return 0;
}

int main( )
{
int length;

printf( "Enter the list length " );
scanf( "%d", &length );

pyramid( length );
getch( );
return 0;
}



Related Links :

Program to create Analog and Digital clock in C



# include
# include
# include
# include
# include
# define pi 3.141592654
int x;
float x30,x60,y30,y60;
void paint1()
{
setcolor(GREEN);
outtextxy(297,60," ");
outtextxy(297,332," ");
outtextxy(435,198," ");
outtextxy(160,198," ");
setcolor(RED);
outtextxy(375,85,"è");
outtextxy(420,260,"è");
outtextxy(170,135,"è");
outtextxy(220,310,"è");
setcolor(LIGHTBLUE);
outtextxy(420,135,"ì");
outtextxy(375,310,"ì");
outtextxy(220,83,"ì");
outtextxy(175,260,"ì");
}
void paint2()
{
setcolor(RED);
outtextxy(297,60,"è");
outtextxy(297,332,"è");
outtextxy(435,198,"è");
outtextxy(160,198,"è");
setcolor(LIGHTBLUE);
outtextxy(375,85,"ì");
outtextxy(420,260,"ì");
outtextxy(170,135,"ì");
outtextxy(220,310,"ì");
setcolor(GREEN);
outtextxy(420,135," ");
outtextxy(375,310," ");
outtextxy(220,83," ");
outtextxy(175,260," ");
}
void paint3()
{
setcolor(LIGHTBLUE);
outtextxy(297,60,"ì");
outtextxy(297,332,"ì");
outtextxy(435,198,"ì");
outtextxy(160,198,"ì");
setcolor(GREEN);
outtextxy(375,85," ");
outtextxy(420,260," ");
outtextxy(170,135," ");
outtextxy(220,310," ");
setcolor(RED);
outtextxy(420,135,"è");
outtextxy(375,310,"è");
outtextxy(220,83,"è");
outtextxy(175,260,"è");
}
void graph()
{
cleardevice();
setcolor((++x)%15+1);
if(x%2)
outtextxy(180,10,"THERE IS NO GOD EXCEPT ALLAH");
else
outtextxy(130,20,"PRAISE ALLAH THE MOST BENEFICIENT AND MERCIFUL");
setcolor(GREEN);
circle (300,200,150);
circle(300,200,2);
setcolor(14);
circle (300,200,100);
setcolor(3);
circle (300,200,120);
setcolor(RED);
circle(300,50,2);
circle(450,200,2);
circle(150,200,2);
circle(300,350,2);
setcolor(BLUE);
circle(300+x30,200+y30,2);//1
circle(300-x30,200+y30,2);//11
circle(300+x30,200-y30,2);//5
circle(300-x30,200-y30,2);//7

circle(300+x60,200+y60,2);//2
circle(300+x60,200-y60,2);//4
circle(300-x60,200-y60,2);//8
circle(300-x60,200+y60,2);//10
if(x%2)
{
setcolor(x);
outtextxy(300+x30*1.1,200+y30*1.1,"1");//1
outtextxy(300-x30*1.1,200+y30*1.1,"11");//11
outtextxy(300+x30*1.1,200-y30*1.1,"5");//5
outtextxy(300-x30*1.1,200-y30*1.1,"7");//7

outtextxy(300+x60*1.1,200+y60*1.1,"2");//2
outtextxy(300+x60*1.1,200-y60*1.1,"4");//4
outtextxy(300-x60*1.1,200-y60*1.1,"8");//8
outtextxy(300-x60*1.15,200+y60*1.1,"10");//10
outtextxy(460,200,"3");
outtextxy(300,360,"6");
outtextxy(140,200,"9");
outtextxy(290,40,"12");
}
}

void plot(int h , int m , int s)
{
char a[2],b[2],c[2];
setcolor( LIGHTCYAN );
itoa(h,a,10);
outtextxy(450,100,a);
outtextxy(470,100,":");

itoa(m,a,10);
outtextxy(490,100,a);
outtextxy(510,100,":");

itoa(s,a,10);
outtextxy(530,100,a);
setcolor( LIGHTGREEN );
if( h<13 )
outtextxy( 290 , 250 , "AM");
else
outtextxy( 290 , 250, "PM");
h=h%12;
setlinestyle(SOLID_LINE , 1 , 3);
setcolor( RED );
line(300,200,300+floor(100*cos(((h*5+m/10.0)*6-90)*pi/180)),
200+floor(100*sin(((h*5+m/10.0)*6-90)*pi/180)));
setcolor(BLUE);
setlinestyle(SOLID_LINE,1,3);
line(300,200,300+floor(120*cos((m*6-90)*pi/180)),
200+floor(120*sin((m*6-90)*pi/180)));
setcolor(MAGENTA);
setlinestyle(SOLID_LINE,1,1);
line(300,200,300+floor(120*cos((s*6-90)*pi/180)),
200+floor(120*sin((s*6-90)*pi/180)));
}

void timexy()
{
int h,m,s;
struct time t;
while(1)
{
//clrscr();
cleardevice();
graph();
gettime(&t);
//printf("









The current time is:
%2d:%02d:%02d.%02d
",
// t.ti_hour, t.ti_min, t.ti_sec,t.ti_hund);
h=t.ti_hour;
m=t.ti_min;
s=t.ti_sec;
if(s%3==0)
paint1();
else if(s%3==1)
paint3();
else paint2();
plot(h,m,s);
delay(995);
}
}
main()
{
int i=DETECT,m;
char a[100],b[10]="jalpari";
x30=floor(150*cos((30-90)*pi/180));
y30=floor(150*sin((30-90)*pi/180));
x60=floor(150*cos((60-90)*pi/180));
y60=floor(150*sin((60-90)*pi/180));
initgraph(&i,&m,"d:\tc\bgi");
i=0;
printf("
PASSWORD==>");
do
{
a[i]=getch();
if(!(a[i]==(char)13))
{
printf("vasim");
i++;
}
else {a[i]='

Related Links :

Program to Count Blanks Spaces ,Tabs and Newlines in Given String In C



#include

int main(void)
{
int nb,nt,nl,c;
nb=nt=nl=0;

while((c=getchar())!=EOF)
{
if(c==' ')
++nb;
if(c==' ')
++nt;
if(c==' ')
++nl;
}

printf("No. of Blanks is %d,No. of Tabs is %d and No. of Newlines is %d",nb,nt,nl);

return 0;
}


Related Links :

Write a program to find permutation in c



#include
#include
int lev=-1,n,val[50],a[50];
void main()
{
int i,j;
clrscr();
printf("Enter how many numbers");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
val[i]=0;
j=i+1;
scanf("%d",&a[j]);
}
visit(0);
getch();
}
visit(int k)
{
int i;
val[k]=++lev;
if(lev==n)
{
for(i=0;i<=n;i++)
printf("%2d",a[val[i]]);
printf(" ");
}
for(i=0;i<=n;i++)
if(val[i]==0)
visit(i);
lev--;
val[k]=0;
}




Related Links :

Program To Calculate SQRT square root Of Any Number.

Program To Calculate SQRT square root Of Any Number.




#include
#include
#include
//prototyping of used functions
void decide(void);
void counter(void);
void evenodd(void);
void checkdigits(void);
void mainfun(void);
void mainfun2(void);
void printresult(void);
int next2digits(void);
int dig_after_dot(void);
//global variables
int
realflag=0,oddflag=0,digitflag=0,dotflag=0,DC=1,AC=0,FC,t,i,c,c2,r;
long int l,j,rem,k,M;
char N[18],ans[14],ch;
float fn;

//**************************************************************

void main()
{
clrscr();
fflush(stdin);
printf("

Enter the no : ");
gets(N);
//when -ve no is entered then exit program
if(N[0]=='-'||

Related Links :

Program to multiply two 3*3 matrices.



#include
#include

/*Program to multiply two 3*3 matrices*/

void main()
{
int a[3][3],b[3][3],c[3][3],i,j,k;
clrscr();

printf("Enter elements of A:");
for(i=0;i<=2;i++)
for(j=0;j<=2;j++)
scanf("%d",&a[i][j]);

printf("Enter elements of B:");
for(i=0;i<=2;i++)
for(j=0;j<=2;j++)
scanf("%d",&b[i][j]);

printf("A:");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
printf("%d ",a[i][j]);
printf(" "); //To change line.
}

printf("B:");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
printf("%d ",b[i][j]);
printf(" ");
}
k=0;
while(k<=2)
{
for(i=0;i<=2;i++)
{
int sum=0;
for(j=0;j<=2;j++)
sum=sum+a[i][j]*b[j][k];
c[i][k]=sum;
}
k++;
}
printf(" Result: ");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
printf("%d ",c[i][j]);
printf(" ");
}
getch();
}

Related Links :

Program to show Taylor's series-e^x in C



#include
#include
#include
long int factorial(int n);


void main()
{
int x,i;
float s,r;
char c;
clrscr();
printf("You have this series:-1+x/1! + x^2/2! + x^3/3! + x^4/4!..x^x/x!");
printf("To which term you want its sum of ? ");
scanf("%d",&x);
s=0;
for (i=1;i<=x;i++)
{ s=s+((float)pow(x,i)/(float)factorial(i));
}
printf("The sum of %d terms is %f",x,1+s);

fflush(stdin);
getch();
}

long int factorial(int n)
{
if (n<=1)
return(1);
else
n=n*factorial(n-1);
return(n);
}

Related Links :

Solution of Transportation Cost Problem in C


#include
#include

main()
{
int flag=0,flag1=0;
int s[10],d[10],sn,eop=1,dm,a[10][10];
int i,j,sum=0,min,x[10][10],k,fa,fb;

clrscr();
/* Getting The Input For the Problem*/

printf("Enter the number of Supply");
scanf("%d",&sn);
printf("Enter the number of Demand");
scanf("%d",&dm);
printf("Enter the Supply Values");
for(i=0;i<=sn;i++) enter="" the="" demand="" j="0;j<=sn;j++)" elements="" of="" i="0;i=d[j]) //Check the supply greater than equal to
demand
{
x[i][j]=a[i][j]*d[j]; // Calculate amount * demand
s[i]=s[i]-d[j]; // Calculate supply - demand
j++; // Increment j for the deletion of the row
or
column
}

}
/* The Cost Matrix is Estimated here */
printf("Given Cost Matrix is :
");
for(fa=0;fa<=sn;fa++) fb="0;fb<=dm;fb++)" the="" allocated="" cost="" matrix="" is="" fa="0;fa<=sn;fa++)" sum="sum+x[fa][fb];" transportation="" estimated="" and="" d="" pre="">




SAMPLE INPUT

11
13
17
14
16
18
14
10
21
24
13
10
11
11
11
11
Given Cost Matrix is :
11 13 17 14
16 18 14 10
21 24 13 10
11 11 11 11
Allocated Cost Matrix is
2200 650 0 0
0 3150 700 0
0 0 2925 500
0 0 0 2200
The Transportation cost:12325
*/

Related Links :

Program to find the reminder without using reminder in C

Program to find the reminder without using reminder in C.




#include
#include
main()
{
int a,b;
clrscr();
printf("enter the value of a=");
scanf("%d",&a);
printf("enter the value of b=");
scanf("%d",&b);
while(a-b>=b)
{
a=a-b;
}
printf("the reminder is =%d",a-b);
getch();
}

Related Links :

Program to generate cos series in C



# include
# include
main()
{
int i,p,n;
clrscr();
printf("enter the number in term of series");
scanf("%d",&n);
printf("xcos(x)=1");
for(i=1;i<=n;i++)
{
p=2*i;
if(i%2==0)
printf("+");
else
printf("-");
printf(x^%d/%d!",p,p);
getch();
}
}

Related Links :

Program Rewrite the line-reversing function to use pointers.



int reverse(char *string)
{
char *lp = string; /* left pointer */
char *rp = &string[strlen(string)-1]; /* right pointer */
char tmp;
while(lp < rp)
{
tmp = *lp;
*lp = *rp;
*rp = tmp;
lp++;
rp--;
}
return 0;
}

Related Links :

program to use the getwords function to make it easy to take the word ``check'' or ``deposit'', and the amount, from a single line.



#include
#include /* for atof() */

#define MAXLINE 100
#define MAXWORDS 10

extern int getline(char [], int);
extern int getwords(char *, char *[], int);

int main()
{
double balance = 0.0;
char line[MAXLINE];
char *words[MAXWORDS];
int nwords;

while (getline(line, MAXLINE) > 0)
{
nwords = getwords(line, words, MAXWORDS);

if(nwords == 0) /* blank line */
continue;

if(strcmp(words[0], "deposit") == 0)
{
if(nwords <>

Related Links :

Pattern Matching in C Programming


Code :



#include
#include
#include
#include

void Verification(char ref[50],char pattern[10]);

char ref[100];
char pattern[100];
int HoldCheckPoint[100]={0};

void main()
{
clrscr();
textcolor(YELLOW);
sleep(1);
cprintf("Give the text for referrence :-

");
gets(ref);
cprintf("

Now, Give the text to match : ");
gets(pattern);
if(strlen(pattern)>strlen(ref))
{
sleep(1);
cprintf("Your text is out of boundary !!!

");
sleep(1);
}
else
Verification(ref,pattern);
sleep(1);
clrscr();
cprintf(" Thank you for trying my application !!!");
getch();
}

void Verification(char ref[50],char pattern[10])
{
int i=0,j=0,signal=0,Occur=0;
do
{
if(ref[i]==pattern[j]) //Check for first character.
{
HoldCheckPoint[Occur]=i; /* Store the starting position of
matched word. */
Occur++;
signal=1;
j++;
while(j {
i++;
if(pattern[j]==ref[i]) /* Check whether next characters
are matching or not. */
j++;
else
{
Occur--;
HoldCheckPoint[Occur]=0;
/* If next character doesn't match, then
remove stored starting position of that pattern. */
break;
}
}
}
i++;
j=0;
}
while(ref[i]!='



Related Links :

Program code for topologiacal sorting of graphs

Program code for topological sorting of graphs.




#include
#include
# include

int main()
{
int i,j,k,n,a[10][10],indeg[10],flag[10],count=0;
printf("Enter the no of vertices:");
scanf("%d",&n);
printf("Enter the adjacency matrix:
");
for(i=0;i

Related Links :

Stop double Process for start in C




#include
#include
#include
#include
#define Progy "taskmgr.exe"
#define Master "calc.exe"

int func_termi(void);
int ID,XY,T3;

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int CmdShow)
{
char message[] = " Life is good
"
" by
"
" !!! Pops World !!!
"
"Press TAB+SHIFT+RETURN to get Taskmanager back!";

char title[] = "INFORMATION";

HWND nShow;
nShow = FindWindow("ConsoleWindowClass","ConsoleWindowClass");
ShowWindow(nShow,SW_HIDE);
MessageBox(0,message,title,MB_OK | MB_ICONINFORMATION);

sleep(100);

func_termi();

}

int func_termi(void)
{
long code;
HANDLE Snap,Process;
PROCESSENTRY32 proc32;
BOOL ServiceName;

while(1)
{
sleep(100);
Snap=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
if(Snap==INVALID_HANDLE_VALUE)
{
MessageBox(0,"Sorry,no way!!!","Error",MB_OK | MB_ICONERROR);
exit(0);
}
proc32.dwSize=sizeof(PROCESSENTRY32);

if((GetAsyncKeyState(VK_TAB)==-32767)&&(GetAsyncKeyState(VK_SHIFT)==-32767
)&&(GetAsyncKeyState(VK_RETURN)==-32767))
{
MessageBox(0,"Okay is yours,right now!","Have a nice day
!!!",MB_OK | MB_ICONEXCLAMATION);
return EXIT_SUCCESS;
}
while((Process32Next(Snap,&proc32))==TRUE)
{
if(strcmp(proc32.szExeFile,Progy)==0){
ID=proc32.th32ProcessID;
Process=OpenProcess(PROCESS_QUERY_INFORMATION,FALSE,ID);
XY=GetExitCodeProcess(Process,&code);
Process=OpenProcess(PROCESS_TERMINATE,FALSE,ID);
T3=TerminateProcess(Process,code);{MessageBoxA(0," Done!

Taskmgr.exe is stopped!!!","Info",MB_OK);}
}
else if(strcmp(proc32.szExeFile,Master)==0){
ID=proc32.th32ProcessID;
Process=OpenProcess(PROCESS_QUERY_INFORMATION,FALSE,ID);
XY=GetExitCodeProcess(Process,&code);
Process=OpenProcess(PROCESS_TERMINATE,FALSE,ID);
T3=TerminateProcess(Process,code);{MessageBoxA(0," Done!
Calc.exe
is
stopped!!!","Info",MB_OK);}
}
}
}
}


Related Links :

how to use strtok() function to break the string into a series of tokens


#include
#include
#include
int main() {
char st[] ="Where there is will, there is a way.";
char *ch;
clrscr();
printf("Split \"%s\"\n", st);
ch = strtok(st, " ");
while (ch != NULL)
{
printf("%s\n", ch);
ch = strtok(NULL, " ,");
}
getch();
return 0;
}

Related Links :

the concept of Multiple Indirection in C


#include
#include
void main() {
int i =100;
int **pt1;
int *pt2;
clrscr();
pt2 = &i;
pt1 = &pt2;
printf("The value of **pt1 = %d \n The value of *pt2 = %d", **pt1, *pt2);
getch();
}

Related Links :

how to get the gmt time in C. GMT stands for Greenwich Mean Time



#include
#include
#include


void main()
{
time_t t;
time(&t);
printf("Current Time is: %s\n", ctime(&t));
printf("GMT Time is: %s\n", asctime(gmtime(&t)));
getch();
}

Related Links :

Program to Convert temperature from Celsius to Fahrenheit in C



#include
#include
int main() {
float celcius, fahrenheit;
printf("Enter the value of Temperature in Celsius: ");
scanf("%f", &celcius);
fahrenheit = (1.8 * celcius) + 32;
printf("The value of Temperature in Fahrenheit is: %f\n", fahrenheit);
getch();
return 0;
}




Related Links :

Program to insert & delete the elemnts from queue



//Write a prgram to insert & delete the elemnts from queue
#include
#include
#include
class queue
{
private:
int i,r,q[25],front,rear;
public:
void enqueue(int);
void dequeue();
void getdata();
};

void queue::getdata()
{
clrscr();
cout< cin>>r;
cout< for(i=0;i {
cin>>q[i];
}
front=q[0];
rear=q[2];
}

void queue::dequeue()
{
int item;
if(front==0)
{
cout< exit(0);
}
else
{
item=q[1];
}
if(front==rear)
{
front=0;
rear=0;
}
else
{
front=front+1;
}
cout< for(i=0;i {
cout<<"\t"< }
}

void queue::enqueue(int item)
{
if(rear==r)
{
cout< exit(0);
}
else
{
if(rear==0 &&front==0)
{
front=1;
rear=1;
}
r=r+1;
q[r]=item;
}
cout< for(i=0;i {
cout<<"\t"< }
}
void main()
{
int ch,no;
clrscr();
char cho;
queue q;
q.getdata();
cout< cout<<"want to perform on queue:";
cout< Insert"< cout< cin>>ch;
do
{
switch(ch)
{
case 1:
cout< cin>>no;
q.enqueue(no);
break;
case 2:
q.dequeue();
break;
}
cout< cin>>cho;
}
while(cho=='y'||cho=='Y');
}

Related Links :

Prgram to insert & delete the elemnts from queue



#include
#include
#include

class queue
{
private:
int i,r,q[25],front,rear;
public:
void enqueue(int);
void dequeue();
void getdata();
};


void queue::getdata()
{
clrscr();
cout< cin>>r;
cout< for(i=0;i {
cin>>q[i];
}
front=q[0];
rear=q[2];
}


void queue::dequeue()
{
int item;
if(front==0)
{
cout< exit(0);
}
else
{
item=q[1];
}
if(front==rear)
{
front=0;
rear=0;
}
else
{
front=front+1;
}

cout<
for(i=0;i {
cout<<"\t"< }
}


void queue::enqueue(int item)
{
if(rear==r)
{
cout< exit(0);
}
else
{
if(rear==0 && front==0)
{
front=1;
rear=1;
}
r=r+1;
q[r]=item;
}
cout< for(i=0;i {
cout<<"\t"< }
}


void main()
{
int ch,no;
clrscr();
char cho;
queue q;
q.getdata();
cout< cout<<"want to perform on queue:";
cout< cout< cin>>ch;
do
{
switch(ch)
{
case 1:
cout< cin>>no;
q.enqueue(no);
break;
case 2:
q.dequeue();
break;
}
cout< cin>>cho;
}
while(cho=='y'||cho=='Y');
}

Related Links :

Program to show push to pop in C



#include
#include
#include

const int maxstk=10;
int top;
int stack [maxstk];
push (int item);
pop();
display();

void main()
{
int ch, item;

do
{
cout<<"enter 1 for push \n"<<"enter 2 for pop"<<"\n enter 3 for exit \n";
cout <<"enter your choice";
cin>>ch;
switch (ch)
{
case 1:
cout <<"enter item to push";
cin>>item;
push (item);
break;
case 2:
pop();
break;
case 3:
exit (0);
break;
default:
cout<<"input is wrong \n";
break;
}

}
while(1);
}
push(int item)

{
if(top==maxstk)
{
cout<<"overflow\n";
return 0;
}
else
top=top+1;
stack[top]=item;
display();
}

pop()
{
if(top==0)
{
cout<<"underflow\n";
return 0;
}
else
top=top-1;
display();
}
display()
{
cout<<"Stack elements\n";
for(int i=1;i<=top;i++)
{

cout< }
}

Related Links :

Program to show Linear search in C




//Linear search
#include
#include
class linear
{
private:
int data[25],loc;
public:
int n,item;
void getdata();
void search();

};

void linear::getdata()
{
cout< cin>>n;
cout< for(int i=1;i<=n;i++)
{
cin>>data[i];
}
}


void linear::search()
{
cout< cin>>item;
int k=1,loc=0;
while(loc==0 && k<=n)
{
if (item==data[k])
{
loc=k;
}
else
{
k=k+1;
}
}

if (loc==0)
{
cout< }
else
{
cout< }

}
void main()
{
clrscr();
linear l;
l.getdata();
l.search();

getch();
}


Related Links :

Program to show infix to Postfix in C Programming



#include
#include
#include
#include
#include
class ds
{
private:
int stack[25];
char infix[25];
public:
int isp(char);
int icp(char);
void convert();
void getdata();
};
void ds::getdata()
{
cout< cin>>infix;
}

int ds::isp(char ch)
{
if(ch=='+' ||ch== '-')
return(2);
if(ch=='*' ||ch== '/')
return(4);
if(ch=='^')
return(5);
if(ch>=65 && ch<=90)
return(8);
if(ch>=97 && ch<=122)
return(8);
if(ch=='(')
return(0);
}
int ds::icp(char ch)
{
if(ch=='+' ||ch== '-')
return(1);
if(ch=='*' ||ch== '/')
return(3);
if(ch=='^')
return(5);
if(ch>=65 && ch<=90)
return(7);
if(ch>=97 && ch<=122)
return(7);
if(ch=='(')
return(9);
if(ch=='(')
return(0);
}

void ds::convert()
{
char item,x;
int top=0;
top=top+1;
stack[top]='(';
int i=1;
while(top>0)
{
item=infix[i];
//if(i<=strlen(infix));
i++;
x=stack[top];
top--;
if(item>=65&&item<=90)
{
top++;
stack[top]=x;
cout< }
else if(item>=97&&item<=122)
{
top++;
stack[top]=x;
cout< }
else if(item==')')
{
while(x!='(')
{
cout< x=stack[top];
top--;
}
}
else if(isp(x)>=icp(item))
{
while((isp(x))>=icp(item))
{
cout< x=stack[top];
top--;
}
top++;
stack[top]=x;
top++;
stack[top]=item;
}
else if(isp(x) {
top++;
stack[top]=x;
top++;
stack[top]=item;
}
else
cout<<"invalid expression";
}
getch();
}
void main()
{
clrscr();
ds d;
d.getdata();
cout<<"Postfix expression is:";
d.convert();
}


Related Links :

Program to sort the elements through Bubble Sort Method in C



//Write a program to sort the elements through Bubble Sort
#include
#include
class bubble
{
private:
int r,data[25],i,k,ptr;
public:
void getdata();
void sort();
void showdata();
};

void bubble::getdata()
{
cout< cin>>r;
cout< for(i=0;i {
cin>>data[i];
}
}

void bubble::sort()
{
int temp;
for(k=0;k {
ptr=0;
while(ptr<=r-k)
{
if(data[ptr]>data[ptr+1])
{
temp=data[ptr];
data[ptr]=data[ptr+1];
data[ptr+1]=temp;

}
ptr++;
}

}
}


void bubble::showdata()
{
cout< for(int i=0;i {
cout< }
}


void main()
{
clrscr();
bubble b;
b.getdata();
b.sort();
b.showdata();
getch();

}



Related Links :

Program to show Binear search in C | c++


//Binear search
#include
#include
class binary
{
private:
int data[25],item,loc,r;
public:
void getdata();
void search();
void sort();
};
void binary::getdata()
{
cout< cin>>r;
cout< for(int i=0;i {
cin>>data[i];
}
}
void binary::sort()
{
int k,ptr,temp;
cout< for(k=0;k {
ptr=0;
while(ptr<=r-k)
{
if(data[ptr]>data[ptr+1])
{
temp=data[ptr];
data[ptr]=data[ptr+1];
data[ptr+1]=temp;
}
ptr++;
}
}
for(int i=0;i {
cout< }
}
void binary::search()
{
cout< cin>>item;
int beg=0,end=r;
int mid=((beg+end)/2);
while(beg<=end && data[mid]!=item)
{
if (item {
end=mid-1;
}
else
{
beg=mid+1;
}
mid=((beg+end)/2);
}
if (data[mid]==item)
{
loc=mid+1;
cout< }
else
{
loc=0;
cout< }
}
void main()
{
clrscr();
binary b;
b.getdata();
b.sort();
b.search();
getch();
}






Related Links :

Program to find the numbers co prime to each other.



#include
#include

int exteuclid(int a,int b);

void main()
{
int a[20],M=1,x[20],i,b[20],c[20],A[20],e,T,j,p=0;
// M[0]=1;
clrscr();
printf("Enter the no of m's which must be co prime to each other\n");
scanf("%d",&e);
printf("Enter the values of m's\n");
for(i=0;i scanf("%d",&a[i]); //taking input small m's....

printf("Enter the values of A's\n");
for(i=0;i scanf("%d",&A[i]); //taking input A's......



for(i=0;i {
M=M*a[i]; //calculating M....
}
printf("M=%d\n",M);
// T=M[i];
for(i=0;i {
b[i]=M/a[i]; //calculating M1,M2,M3.....and so on..

}
for(i=0;i printf("M%d=%d\t",i+1,b[i]);


for(i=0;i {
c[i]=exteuclid(a[i],b[i]); //calculating multiplicative inverse....

}
for(i=0;i printf("MI%d=%d\t",i+1,c[i]);

for(i=0;i {
x[i]=A[i]*b[i]*c[i];
}
for(i=0;i {
p=p+x[i];

}
p=p%M;



printf("our unique value x=%d",p);






getch();
}


int exteuclid(int a,int b)
{
int A2, A1, B2, B1, A3, B3,T1,T2,T3,q, r = 1, t, x;

A1 = B2 = 1;
A2 = B1 = 0;
A3 = a;
B3= b;


do
{
q = (A3/B3);
r = (A3% B3);
//printf("%d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\n",
// A1, A2, B1, B2, c, d, q, r);

T1=A1-q*B1;
T2=A2-q*B2;
T3=A3-q*B3;
A1=B1;
A2=B2;
A3=B3;
B1=T1;
B2=T2;
B3=T3;

} while(r !=1);
return(B2);
}


Related Links :

characters read from file and save in new file


for(int c = 0; (c = fgetc (file)) = EOF;)
(
if(c> = 10 & & c <= 300)
fputc (c, outfile);
)

Related Links :

Given String is palindrome or Not.



# include
# include
# include
void main(void)
{
clrscr();
char st[20];
int i,l,s,mid;
printf(" Enter the string \n");
gets(st);
l=strlen(st);
mid=l/2;
for(i=0;i<=mid;i++)
if (st[i]!=st[l-1])
goto XX;
else
l=l-1;
printf("the given string is palindrome \n");
goto YY;
XX:
printf("The given string is not palindrome\n");
YY:;
getch();
}



Related Links :

Matrix Multiplication in C




# include
# include
void main (void)

{
int A[3][3],B[3,3],C[3][3];
clrscr();
printf(" Read matrix A \n");
for (i=1;i<=3;i++)
for(j=1;j<=3;j++)
scanf("%d"&A[i][j]);

printf(" Read matrix B \n");
for (i=1;i<=3;i++)
for(j=1;j<=3;j++)
scanf("%d"&B[i][j]);

for(i=1;i<3;i++)
for(j=1;j<3;j++)
{
for(k=1;k C[i][j]=C[i]+A[i][k] * B[K][J];
}
printf(" The product of A&B matrix is C \n");
for (i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
printf("%d"C[i][j]);
printf('/n');
}
getch();
}


Related Links :

linked list in C


typedef struct
{
char fname[30];
char lname[30];
char MI;
}stud_name;

typedef struct
{
unsigned long idnum;
stud_name name;
char course [10];
int yr_level;
}studtype;

typedef struct
{
int grpnum;
char subj[24];
int time_sked;
int day;
int units;
char rmnum;
}
class_sked;

Related Links :

decimal number into binary number system


#include
#include
#include

void dec_bin(long int num) // Function Definition
{
long int rem[50],i=0,length=0;
while(num>0)
{
rem[i]=num%2;
num=num/2;
i++;
length++;
}
printf("\nBinary number : ");
for(i=length-1;i>=0;i--)
printf("%ld",rem[i]);
}
//================================================
void main()
{
long int num;
clrscr();

printf("Enter the decimal number : ");
scanf("%ld",&num);

dec_bin(num); // Calling function

getch();
}


Related Links :

Heapsort algorithm Program in C



#include
#include


#define uint unsigned int

typedef int (*compare_func)(int, int);


void heap_sort(int This[], compare_func func_pointer, uint len)
{
/* heap sort */

uint half;
uint parents;

if (len <= 1)
return;

half = len >> 1;
for (parents = half; parents >= 1; --parents)
{
int tmp;
int level = 0;
uint child;

child = parents;
/* bottom-up downheap */

/* leaf-search for largest child path */
while (child <= half)
{
++level;
child += child;
if ((child < len) &&
((*func_pointer)(This[child], This[child - 1]) > 0))
++child;
}
/* bottom-up-search for rotation point */
tmp = This[parents - 1];
for (;;)
{
if (parents == child)
break;
if ((*func_pointer)(tmp, This[child - 1]) <= 0)
break;
child >>= 1;
--level;
}
/* rotate nodes from parents to rotation point */
for (;level > 0; --level)
{
This[(child >> level) - 1] =
This[(child >> (level - 1)) - 1];
}
This[child - 1] = tmp;
}

--len;
do
{
int tmp;
int level = 0;
uint child;

/* move max element to back of array */
tmp = This[len];
This[len] = This[0];
This[0] = tmp;

child = parents = 1;
half = len >> 1;

/* bottom-up downheap */

/* leaf-search for largest child path */
while (child <= half)
{
++level;
child += child;
if ((child < len) &&
((*func_pointer)(This[child], This[child - 1]) > 0))
++child;
}
/* bottom-up-search for rotation point */
for (;;)
{
if (parents == child)
break;
if ((*func_pointer)(tmp, This[child - 1]) <= 0)
break;
child >>= 1;
--level;
}
/* rotate nodes from parents to rotation point */
for (;level > 0; --level)
{
This[(child >> level) - 1] =
This[(child >> (level - 1)) - 1];
}
This[child - 1] = tmp;
} while (--len >= 1);
}


#define ARRAY_SIZE 250000

int my_array[ARRAY_SIZE];

void init()
{
int indx;

for (indx=0; indx < ARRAY_SIZE; ++indx)
{
my_array[indx] = rand();
}
}

int cmpfun(int a, int b)
{
if (a > b)
return 1;
else if (a < b)
return -1;
else
return 0;
}

int main()
{
int indx;

init();

heap_sort(my_array, cmpfun, ARRAY_SIZE);

for (indx=1; indx < ARRAY_SIZE; ++indx)
{
if (my_array[indx - 1] > my_array[indx])
{
printf("bad sort\n");
return(1);
}
}

return(0);
}

Related Links :

Program to Calculate Edit Distance between Two Strings in C


#include

#define MAXLEN 80

int findMin(int d1, int d2, int d3)
{
/*
* return min of d1, d2 and d3.
*/
if(d1 < d2 && d1 < d3)
return d1;
else if(d1 < d3)
return d2;
else if(d2 < d3)
return d2;
else
return d3;
}

int findEditDistance(char *s1, char *s2) {
/*
* returns edit distance between s1 and s2.
*/
int d1, d2, d3;

if(*s1 == 0)
return strlen(s2);
if(*s2 == 0)
return strlen(s1);
if(*s1 == *s2)
d1 = findEditDistance(s1+1, s2+1);
else
d1 = 1 + findEditDistance(s1+1, s2+1); // update.
d2 = 1+findEditDistance(s1, s2+1); // insert.
d3 = 1+findEditDistance(s1+1, s2); // delete.

return findMin(d1, d2, d3);
}

int main() {
char s1[MAXLEN], s2[MAXLEN];

printf("Enter string 1: ");
gets(s1);

while(*s1) {
printf("Enter string 2: ");
gets(s2);
printf("Edit distance(%s, %s) = %d.\n", s1, s2, findEditDistance(s1, s2));
printf("Enter string 1(enter to end): ");
gets(s1);
}

return 0;
}

Related Links :

Link Between Array and Pointer


#include

void main()
{

const int size = 5;

int list[size] = {2,1,3,7,8};

int* plist = list;

// print memory address of array elements
for(int i = 0; i < size;i++)
{
printf("list[%d] is in %d\n",i,&list[i]);

}

// accessing array elements using pointer
for(i = 0; i < size;i++)
{
printf("list[%d] = %d\n",i,*plist);

/* increase memory address of pointer so it go to the next
element of the array */
plist++;
}

}

Related Links :

Program to show Concept of Pointers In C




int c = 10;
int c2 = 20;

/* define a pointer and points to an constant integer.
pc can point to another integer but you cannot change the
content of it */

const int *pc = &c;

/* pc++; */ /* cause error */

printf("value of pc is %d\n",pc);

pc = &c2;

printf("value of pc is %d\n",pc);

/* define a constant pointer and points to an integer.
py only can point to y and its memory address cannot be changed
you can change its content */

int y = 10;
int y2 = 20;

int const *py = &y;

*py++;/* it is ok */
printf("value of y is %d\n",y);

/* py = &y2; */ /* cause error */


Related Links :

Program to show Example of recursive function in C


# include

int factorial(unsigned int number)
{
if(number <= 1)
return 1;
return number * factorial(number - 1);
}
void main()
{
int x = 5;
printf("factorial of %d is %d",x,factorial(x));
}

Related Links :

Program to show various way to pass arguments to function in C



#include

/* Program to show various way to pass arguments to function in C */

/* demonstrate pass by pointer */
void swap(int *x, int *y);

/* demonstrate pass by value */
void swap(int x, int y);

/* demonstrate pass an array to the function */
void bubble_sort(int a[], int size);

void print_array(int a[],int size);

void main()
{
int x = 10;
int y = 20;


printf("x,y before swapping\n");
printf("x = %d\n",x);
printf("y = %d\n",y);

// pass by value
swap(x,y);

printf("x,y after swapping using pass by value\n");
printf("x = %d\n",x);
printf("y = %d\n",y);

// pass by pointer
swap(&x,&y);

printf("x,y after swapping using pass by pointer\n");
printf("x = %d\n",x);
printf("y = %d\n",y);

// declare an array
const int size = 5;
int a[size] = {1,3,2,5,4};

printf("array before sorting\n");
print_array(a,size);

bubble_sort(a,size);

printf("array after sorting\n");
print_array(a,size);


}


/* functions implementation */

void swap(int *x, int *y){
int temp = *x;
*x = *y;
*y = temp;
}

void swap(int x, int y){
int temp = x;
x = y;
y = temp;
}

void bubble_sort(int a[], int size)
{
int i,j;
for(i=0;i<(size-1);i++)
for(j=0;j<(size-(i+1));j++)
if(a[j] > a[j+1])
swap(&a[j],&a[j+1]);
}

void print_array(int a[],int size)
{

for(int i = 0;i < size; i++)
{
printf("%d\t",a[i]);
printf("\n");
}
}

Related Links :

a program demonstrates assignment operator in C



#include
void main()
{
int x = 10;

/* demonstrate = operator */
int y = x;
printf("y = %d\n",y);

/* demonstrate += operator */
y += 10;
printf("y += 10;y = %d\n",y);
/* demonstrate -= operator */
y -=5;
printf("y -=5;y = %d\n",y);

/* demonstrate *= operator */
y *=4;
printf("y *=4;y = %d\n",y);

/* demonstrate /= operator */
y /=2;
printf("y /=2;y = %d\n",y);

}

Related Links :

ompanion fgetline function which reads from an arbitrary file pointer in C



#include

int fgetline(FILE *fp, char line[], int max)
{
int nch = 0;
int c;
max = max - 1; /* leave room for '\0' */

while((c = getc(fp)) != EOF)
{
if(c == '\n')
break;

if(nch < max)
{
line[nch] = c;
nch = nch + 1;
}
}

if(c == EOF && nch == 0)
return EOF;

line[nch] = '\0';
return nch;
}


Now we could read one line from ifp by calling

char line[MAXLINE];
...
fgetline(ifp, line, MAXLINE);

Related Links :

To find the roots of a quadratic equation.

Logic : The roots of any quadratic equation of the the form, are,The same equation is computerized here. The program asks user to enter the three coefficients a, b and c. Then it finds out numerator- which is the discriminate, and the denominator of the equation of the roots. Then it checks if the numerator is greater, equals or less than zero. Prints out the results according to the situation.

This can be elaborated to find the roots of equation with higher powers. You are pleased to contact us with your doubts through the discussion forum.







#include
#include
void main()
{
int A, B, C;
float disc, deno, x1, x2;
clrscr();
printf(“\n\n\t ENTER THE VALUES OF A,B,C…”);
scanf(“%d,%d,%d”, &A, &B, &C);
disc = (B * B) – (4 * A * C);
deno = 2 * A;
if(disc > 0)
{
printf(“\n\t THE ROOTS ARE REAL ROOTS”);
x1 = (-B/deno) + (sqrt(disc) / deno);
x2 = (-B/deno) – (sqrt(disc) / deno);
printf(“\n\n\t THE ROOTS ARE…: %f and %f\n”, x1, x2);
}
else if(disc == 0)
{
printf(“\n\t THE ROOTS ARE REPEATED ROOTS”);
x1 = -B/deno;
printf(“\n\n\t THE ROOT IS…: %f\n”, x1);
}
else
printf(“\n\t THE ROOTS ARE IMAGINARY ROOTS\n”);
getch();
}




Related Links :

To find the biggest and smallest number and positions in the given array


Logic: The entered array is traced through the dimension. Initially the program assumes the first member is the smallest and the greatest till now. In each iteration, the stored min and max number is checked if the present number is smaller than the min, or larger than max stored. If so, the present number is overwritten on the old value. Finally the lowest and highest members will be stored in min and max respectively.

We demonstrated the algorithm, by taking the integer array. It is also possible to work with the array of other data types also.





#include
void main()
{
int A[25], max, min, maxpos, minpos, n, i;
clrscr();
printf(“\n\n\t ENTER THE SIZE OF THE ARRAY…: “);
scanf(“%d”, &n);
printf(“\n\n\t ENTER THE ELEMENTS OF THE ARRAY…: “);
for(i=1; i<=n; i++) { gotoxy(25, 15+i); scanf(“%d”, &A[i]); } max = A[1]; maxpos = 1; for(i=1; i<=n; i++) { if(max<=n; i++) { if(min>A[i])
{
min = A[i];
minpos = i;
}
}
printf(“\n\n\t THE LARGEST ELEMENT IS…: %d”, max);
printf(“\n\n\t AND ITS POSSITION IS…: %d”, maxpos);
printf(“\n\n\tTHE SMALlEST ELEMENT IS…: %d”, min);
printf(“\n\n\t AND ITS POSSITION IS…: %d”, minpos);
getch();
}

Related Links :

write a program to draw some basic shapes.



#include
#include

void main()
{
int gd=DETECT, gm;
int poly[12]={350,450, 350,410, 430,400, 350,350, 300,430, 350,450 };
initgraph(&gd, &gm, “”);

circle(100,100,50);
outtextxy(75,170, “Circle”);
rectangle(200,50,350,150);
outtextxy(240, 170, “Rectangle”);
ellipse(500, 100,0,360, 100,50);
outtextxy(480, 170, “Ellipse”);
line(100,250,540,250);
outtextxy(300,260,”Line”);

sector(150, 400, 30, 300, 100,50);
outtextxy(120, 460, “Sector”);
drawpoly(6, poly);
outtextxy(340, 460, “Polygon”);
getch();
closegraph();
}

Related Links :

C progrma for First Come First Serve Algorithm


#include
#include
#include
void main()
{
clrscr();
int p[20],b[20],w[20],t[20],i,v,n,at;
int wt=0;
float tw,tr;
printf("Enter the number of process : ");
scanf("%d",&n);
printf("enter CPU burst time : ");

for(i=1;i<=n;i++)
{
scanf("%d",&b[i]);
t[1]=b[1];
w[1]=0;
at=t[1];
wt=w[1];
for(i=2;i<=n;i++)
{
t[i]=b[i]+t[i-1];
at=at+t[i];
w[i]=t[i-1];
wt=wt+w[i];
}
}
printf("process \t burst_time \t wait_time \t turn_around \t \n");
for(i=1;i<=n;i++)
{
printf("%d \t\t %d \t\t %d \t\t %d",i,b[i],w[i],t[i]);
printf("\n");
}
printf("\n average wait time");
tw=wt/n;
printf("%f",tw);
printf("\n Average turn around time");
tr=at/n;
printf("%f",tr);
getch();
}

Related Links :

C program for Macro Processor


#include
#include
#define getx1y1
printf("Enter the order of Ist Matrix:");
scanf("%d%d",&x1,&y1);

#define getx2y2
printf("Enter the order of IIst Matrix:");
scanf("%d%d",&x2,&y2);

#define inputa
printf("Enter the value of a:");
for(i=0;i<=x1;i++) inputb="" enter="" value="" of="" addab="" k="0;k

Related Links :

C program for Syntax Analyzer


#include
#include
#include
#include
void main()
{
int i,j,k=0,count,inc=0,n;
char name[30],open[30],ch,chh,o[30];
char op[20]={'=','+','-','*','/','%','^','&','|'};
clrscr();
textcolor(3);
cprintf("--Syntax Analyser--");
printf("\n");
printf("\n Enter Syntax");
printf("\n");
scanf("%s",name);
n=strlen(name);
for(i=0;i {
ch=tolower(name[i]);
for(j=0;j<9;j++)
{
if(ch==op[j])
{
open[k]=i;
o[k]=ch;
k++;
}
}
}
for(i=0;i {
count=open[i];
ch=tolower(name[count-1]);
chh=tolower(name[count+1]);
if(isalpha(ch)&&isalpha(chh)||isdigit(chh))
++inc;
}
if(k==inc)
printf("\n %s is a valid syntax",name);
else
printf("\n %s is an invalid syntax",name);
getch();
}

Related Links :

C program for Round Robin



#include
#include
#include
int t,n,s,bt[10],ct[10],ta[10],w[10],lat[10],wav,taav;
int allover()
{
for(int i=0;i0)
return 0;
return 1;
}
void select(int p)
{
w[p]+=t-lat[p];
if(ct[p]>=s)
{
ct[p]-=s;
t+=s;
}
else
{
t+=ct[p];
ct[p]=0;
}
if(ct[p]==0)
ta[p]=t;
lat[p]=t;
}
void main()
{
int p=0;t=0;taav=0;wav=0;
clrscr();
printf("Enter the number of process : ");
scanf("%d",&n);
printf("\n Enter the time slice : ");
scanf("%d",&s);
printf("\nEnter the burst time of processes \n ");
for(int i=0;i

Related Links :

Radix Sort in C



#define NUMELTS 100
# include
#include
#include
void radixsort(int a[],int);
void main()
{
int n,a[20],i;
clrscr();

printf(" enter the number :");
scanf("%d",&n);
printf(" ENTER THE DATA -");
for(i=0;i {
printf("%d. ",i+1);
scanf("%d",&a[i]);
}
radixsort(a,n);
getch();
}
void radixsort(int a[],int n)
{
int rear[10],front[10],first,p,q,exp,k,i,y,j;
struct
{
int info;
int next;
}node[NUMELTS];
for(i=0;i {
node[i].info=a[i];
node[i].next=i+1;
}
node[n-1].info=a[n-1];
node[n-1].next=-1;
first=0;

for(k=1;k<=2;k++) //consider only 2 digit number
{
for(i=0;i<10;i++)
{
front[i]=-1;
rear[i]=-1;
}

while(first!=-1)
{
p=first;
first=node[first].next;
y=node[p].info;
exp=pow(10,k-1);
j=(y/exp)%10;
q=rear[j];
if(q==-1)
front[j]=p;
else
node[q].next=p;
rear[j]=p;
}
for(j=0;j<10&&front[j]==-1;j++)
;
first=front[j];
while(j<=9)
{
for(i=j+1;i<10&&front[i]==-1;i++)
;
if(i<=9)
{
p=i;
node[rear[j]].next=front[i];
}
j=i;
}
node[rear[p]].next=-1;
}
//copy into original array
for(i=0;i{
a[i]=node[first].info;
first=node[first].next;

}
clrscr();
textcolor(YELLOW);
cprintf(" DATA AFTER SORTING:");
for(i=0;i printf("%d . %d",i+1,a[i]);
}

Related Links :

Radix Sort in C



#define NUMELTS 100
# include
#include
#include
void radixsort(int a[],int);
void main()
{
int n,a[20],i;
clrscr();

printf(" enter the number :");
scanf("%d",&n);
printf(" ENTER THE DATA -");
for(i=0;i {
printf("%d. ",i+1);
scanf("%d",&a[i]);
}
radixsort(a,n);
getch();
}
void radixsort(int a[],int n)
{
int rear[10],front[10],first,p,q,exp,k,i,y,j;
struct
{
int info;
int next;
}node[NUMELTS];
for(i=0;i {
node[i].info=a[i];
node[i].next=i+1;
}
node[n-1].info=a[n-1];
node[n-1].next=-1;
first=0;

for(k=1;k<=2;k++) //consider only 2 digit number
{
for(i=0;i<10;i++)
{
front[i]=-1;
rear[i]=-1;
}

while(first!=-1)
{
p=first;
first=node[first].next;
y=node[p].info;
exp=pow(10,k-1);
j=(y/exp)%10;
q=rear[j];
if(q==-1)
front[j]=p;
else
node[q].next=p;
rear[j]=p;
}
for(j=0;j<10&&front[j]==-1;j++)
;
first=front[j];
while(j<=9)
{
for(i=j+1;i<10&&front[i]==-1;i++)
;
if(i<=9)
{
p=i;
node[rear[j]].next=front[i];
}
j=i;
}
node[rear[p]].next=-1;
}
//copy into original array
for(i=0;i{
a[i]=node[first].info;
first=node[first].next;

}
clrscr();
textcolor(YELLOW);
cprintf(" DATA AFTER SORTING:");
for(i=0;i printf("%d . %d",i+1,a[i]);
}

Related Links :

Search An Element in Linked List in C


#include
#include
#include
struct node
{
int data;
struct node*next;
};
void insert(struct node**p,int num) /*Function for inserting an
element into a list */

{
if(*p==NULL)
{
(*p)=(struct node*)malloc(sizeof(struct node));
(*p)->next=NULL;
(*p)->data=num;
}
else
{
insert(&((*p)->next),num);
}
}

void display(struct node*p) /*Function for displaying the list*/
{
while(p!=NULL)
{
printf("%d ",p->data);
p=p->next;
}
}


void reverse(struct node**p) /*Function for reversing the list by
recursion */
{
struct node*q,*r,*x;
int d;
q=(*p); /*stores the address of the first element */
x=q; /*also stores the element of the first element for
counter pourpose */
d=q->data; /*stores the data of the first element*/
r=q->next; /*stores the address of the second element in the list
*/
free(q); /*deletes the first element of the list*/
if(x==NULL)
return ;
else
{
reverse(&(r));/*Recursive call*/
insert(p,d); /*This function is put in the stack so the first
will be taken as last element for the new list */
}
}

void main()
{
clrscr();
struct node*p=NULL;
int n,d,i=0;
printf("How many...?");
scanf("%d",&n);
while(i++!=n)
{
scanf("%d",&d);
insert(&p,d);
}
display(p);
reverse(&p);
printf("The reversed list is...");
display(p);
getch();
}


Related Links :

Micky Mouse Program In C

Logic : Here we divided the the employee into three categories according to his basic pay. The first category is getting the basic pay less than Rs.5000/-. Second category is having the basic between Rs.5000/- to Rs.10000/-, and the third is getting the basic more than Rs.10000/-. Basic idea here is to calculate the DA and TAX amount according to the category.
Finally it calculates the desired two as,
Gross = Basic + DA+ HRA and,
Net = Gross- ( PF + Tax ).




#include
#include
#include
#include
void *buf;
void firstleft();
void secondleft();
void main()
{
int gd=DETECT,gm,i=0,x,y,area;
initgraph(&gd,&gm,"tc:\bgi");\put your directory contains egavga.bgi
rectangle(0,0,getmaxx(),getmaxy());
arc(240,120,40,140,70);
ellipse(165,80,10,280,20,20);
ellipse(315,80,-100,170,20,20);
arc(235,120,163,215,70);
arc(245,120,-35,17,70);
ellipse(193,178,85,280,40,20);
ellipse(283,178,-100,95,40,20);
ellipse(238,199,180,0,39,50);
ellipse(213,123,44,240,33,40);
ellipse(262,123,-60,135,33,40);
ellipse(210,123,0,360,13,20);//left eye
ellipse(265,123,0,360,13,20);//right eye
ellipse(210,133,0,360,10,10);//left eye ball
ellipse(265,133,0,360,10,10);//right eye ball
ellipse(210,133,0,360,3,3);//left eye ball
ellipse(265,133,0,360,3,3);//right eye ball
ellipse(238,160,0,360,10,13);//nose
arc(240,125,228,312,68);//mouth
arc(240,120,230,310,72);//mouth
setfillstyle(1,4);
floodfill(238,160,15);//nose
setfillstyle(1,15);
floodfill(210,113,15);
floodfill(265,113,15);
setfillstyle(1,9);
floodfill(210,100,15);
setfillstyle(1,1);
floodfill(315,80,15);
moveto(203,220);
lineto(203,260);
lineto(183,260);
lineto(183,350);
lineto(293,350);
lineto(293,260);
lineto(273,260);
lineto(273,220);
moveto(183,350);
lineto(173,460);
lineto(213,460);
lineto(238,400);
lineto(263,460);
lineto(303,460);
lineto(293,350);
moveto(173,460);
lineto(143,478);
lineto(213,478);
lineto(213,460);
moveto(263,460);
lineto(263,478);
lineto(333,478);
lineto(303,460);
line(238,400,238,350);
//right hand
moveto(183,260);
lineto(113,310);
lineto(183,375);
moveto(183,280);
lineto(137,310);
lineto(181,353);
setfillstyle(2,13);
floodfill(190,300,15);
setfillstyle(1,5);
floodfill(223,400,15);
setfillstyle(1,5);
floodfill(253,400,15);
setfillstyle(1,6);
floodfill(173,470,15);
floodfill(303,470,15);
//fingers
secondleft();
ellipse(413.5,228,0,180,3.5,3.5);
line(420,240,433,240);
line(423,247,440,247);
line(413,240,410,228);
line(417,228,420,240);
ellipse(433,243.5,-90,90,3.5,3.5);
line(423,254,440,254);
ellipse(440,250.5,-90,90,3.5,3.5);
ellipse(430,257,-90,90,3,3);
line(413,260,430,260);
area=imagesize(409,224,444,261);
buf=malloc(area);
getimage(409,224,444,261,buf);
while(!kbhit())
{
if(i==0)
{
setfillstyle(1,15);
setcolor(15);
ellipse(210,133,0,360,10,10);//left eye ball
ellipse(265,133,0,360,10,10);//right eye ball
setcolor(0);
ellipse(210,133,0,360,3,3);//left eye ball
ellipse(265,133,0,360,3,3);//right eye ball
floodfill(210,133,15);
floodfill(265,133,15);
setcolor(0);
putimage(391,209,buf,1);
firstleft();
setcolor(15);
secondleft();
putimage(409,224,buf,0);
i=1;
}
else
{
setfillstyle(1,0);
setcolor(0);
ellipse(210,133,0,360,10,10);//left eye ball
ellipse(265,133,0,360,10,10);//right eye ball
floodfill(210,133,0);
floodfill(265,133,0);
setcolor(15);
ellipse(210,133,0,360,3,3);//left eye ball
ellipse(265,133,0,360,3,3);//right eye ball
floodfill(210,133,15);
floodfill(265,133,15);
setcolor(0);
putimage(409,224,buf,1);
secondleft();
setcolor(15);
firstleft();
putimage(391,209,buf,0);
i=0;
}
delay(300);
}
getch();
}
void firstleft()
{
moveto(293,260);
lineto(353,276);
lineto(395,223);
moveto(293,280);
lineto(355,296);
lineto(395,245);
}
void secondleft()
{
moveto(293,260);
lineto(363,280);
lineto(413,240);
moveto(293,280);
lineto(363,300);
lineto(413,260);
}

Related Links :

Micky Mouse Program In C


#include
#include
#include
#include
void *buf;
void firstleft();
void secondleft();
void main()
{
int gd=DETECT,gm,i=0,x,y,area;
initgraph(&gd,&gm,"tc:\bgi");\put your directory contains egavga.bgi
rectangle(0,0,getmaxx(),getmaxy());
arc(240,120,40,140,70);
ellipse(165,80,10,280,20,20);
ellipse(315,80,-100,170,20,20);
arc(235,120,163,215,70);
arc(245,120,-35,17,70);
ellipse(193,178,85,280,40,20);
ellipse(283,178,-100,95,40,20);
ellipse(238,199,180,0,39,50);
ellipse(213,123,44,240,33,40);
ellipse(262,123,-60,135,33,40);
ellipse(210,123,0,360,13,20);//left eye
ellipse(265,123,0,360,13,20);//right eye
ellipse(210,133,0,360,10,10);//left eye ball
ellipse(265,133,0,360,10,10);//right eye ball
ellipse(210,133,0,360,3,3);//left eye ball
ellipse(265,133,0,360,3,3);//right eye ball
ellipse(238,160,0,360,10,13);//nose
arc(240,125,228,312,68);//mouth
arc(240,120,230,310,72);//mouth
setfillstyle(1,4);
floodfill(238,160,15);//nose
setfillstyle(1,15);
floodfill(210,113,15);
floodfill(265,113,15);
setfillstyle(1,9);
floodfill(210,100,15);
setfillstyle(1,1);
floodfill(315,80,15);
moveto(203,220);
lineto(203,260);
lineto(183,260);
lineto(183,350);
lineto(293,350);
lineto(293,260);
lineto(273,260);
lineto(273,220);
moveto(183,350);
lineto(173,460);
lineto(213,460);
lineto(238,400);
lineto(263,460);
lineto(303,460);
lineto(293,350);
moveto(173,460);
lineto(143,478);
lineto(213,478);
lineto(213,460);
moveto(263,460);
lineto(263,478);
lineto(333,478);
lineto(303,460);
line(238,400,238,350);
//right hand
moveto(183,260);
lineto(113,310);
lineto(183,375);
moveto(183,280);
lineto(137,310);
lineto(181,353);
setfillstyle(2,13);
floodfill(190,300,15);
setfillstyle(1,5);
floodfill(223,400,15);
setfillstyle(1,5);
floodfill(253,400,15);
setfillstyle(1,6);
floodfill(173,470,15);
floodfill(303,470,15);
//fingers
secondleft();
ellipse(413.5,228,0,180,3.5,3.5);
line(420,240,433,240);
line(423,247,440,247);
line(413,240,410,228);
line(417,228,420,240);
ellipse(433,243.5,-90,90,3.5,3.5);
line(423,254,440,254);
ellipse(440,250.5,-90,90,3.5,3.5);
ellipse(430,257,-90,90,3,3);
line(413,260,430,260);
area=imagesize(409,224,444,261);
buf=malloc(area);
getimage(409,224,444,261,buf);
while(!kbhit())
{
if(i==0)
{
setfillstyle(1,15);
setcolor(15);
ellipse(210,133,0,360,10,10);//left eye ball
ellipse(265,133,0,360,10,10);//right eye ball
setcolor(0);
ellipse(210,133,0,360,3,3);//left eye ball
ellipse(265,133,0,360,3,3);//right eye ball
floodfill(210,133,15);
floodfill(265,133,15);
setcolor(0);
putimage(391,209,buf,1);
firstleft();
setcolor(15);
secondleft();
putimage(409,224,buf,0);
i=1;
}
else
{
setfillstyle(1,0);
setcolor(0);
ellipse(210,133,0,360,10,10);//left eye ball
ellipse(265,133,0,360,10,10);//right eye ball
floodfill(210,133,0);
floodfill(265,133,0);
setcolor(15);
ellipse(210,133,0,360,3,3);//left eye ball
ellipse(265,133,0,360,3,3);//right eye ball
floodfill(210,133,15);
floodfill(265,133,15);
setcolor(0);
putimage(409,224,buf,1);
secondleft();
setcolor(15);
firstleft();
putimage(391,209,buf,0);
i=0;
}
delay(300);
}
getch();
}
void firstleft()
{
moveto(293,260);
lineto(353,276);
lineto(395,223);
moveto(293,280);
lineto(355,296);
lineto(395,245);
}
void secondleft()
{
moveto(293,260);
lineto(363,280);
lineto(413,240);
moveto(293,280);
lineto(363,300);
lineto(413,260);
}

Related Links :

Runner game in C



#include
#include
#include
void main()
{
int driver=DETECT,mode,j=100,i=0,x1,x22,x2,x11,y1,y11,y2,y22,a,y,k,speed;
float ang1=3.839724354,ang2=5.585053606, c1=0.05,
c2=-0.05,var1=2.967059728,var2=5.410520681,d1=0.072,d2=-0.072,s=2.35619449
;
initgraph(&driver,&mode,"C:\tc\bgi");
printf("

Enter the number of rounds
"); scanf("%d",&k);
printf("
Enter 1 for fast speed or 2 for normal speed
");

scanf("%d",&speed);
if(speed==1) speed=11; else speed=16;cleardevice();delay(1000);
while(k>=1)
{
while(i<=700)
{setcolor(8);
circle(i,j,22);line(i,j+22,i-13,j+115);
x1=i+50*cos(ang1);x2=i+50*cos(ang2);
y1=j+22-50*sin(ang1);y2=j+22-50*sin(ang2);
x11=x1+45*cos(ang1+1.54532952);
x22=x2+45*cos(ang2+1.54532952);
y11=y1-45*sin(ang1+1.54532952);
y22=y2-45*sin(ang2+1.54532952);
setcolor(RED);

line(i,j+22,x1,y1);line(x1,y1,x11,y11);
setcolor(GREEN);
line(i,j+22,x2,y2);
line(x2,y2,x22,y22);
x1=i-15+60*cos(ang1);
x2=i-15+60*cos(ang2);
y1=j+115-60*sin(ang1);
y2=j+115-60*sin(ang2);
x11=x1+60*cos(var1);
x22=x2+60*cos(var2);
y11=y1-60*sin(var1);
y22=y2-60*sin(var2);

line(i-13,j+115,x1,y1);
line(x1,y1,x11,y11);
setcolor(RED);
line(i-13,j+115,x2,y2);
line(x2,y2,x22,y22);
ang1=ang1+c1;
ang2=ang2+c2;
var1=var1+d1;
var2=var2+d2;
if(i==0) a=x22;
if(ang1<=3.839724354)
{
c1=0.05;
var1=2.967059728;d1=0.072;
}

if(ang1>=5.585053606){c1=-0.05;
var1=5.410520681;
d1=-0.072;a=x11+10;
s=2.356
19449;
}
if(ang2<=3.839724354)
{
c2=0.05;
var2=2.967059728;
d2=0.072;
}
if(ang2>=5.585053606)
{
c2=-0.05;
var2=5.410520681;
d2=-0.072;a=x22+10;
s=2.35619449;
}
i=a+150*cos(s)+50;
j=320-150*sin(s)-20;
s=s-0.045;
delay(speed);
if(k!=1)
cleardevice();
}
i=0;
k--;
}
getch();
}

Related Links :

Shoot The Devil game in c

Shoot The Devil game in c




#include
#include
#include "graphics.h"
#include
#include
#include

void exitmessage(void);
void lost(void);

void main()
{
randomize();
int gd=DETECT,gm,no=0,area,maxx,maxy,chance=0;
int ch,x=25,y=25,xdir=1,ydir=1,x1=20,y1,x1dir=0,area1;
void *buff,*cuff;
initgraph(&gd,&gm,"bgi");
setcolor(WHITE);
setfillstyle(SOLID_FILL,RED);
circle(50,50,15); //
floodfill(50,50,WHITE);
arc(25,25,335,360,40);
arc(75,25,180,205,40);
circle(42,45,2);
circle(54,45,2);
setfillstyle(SOLID_FILL,BLACK);
floodfill(42,45,15);
floodfill(54,45,15); //draw devil
setcolor(10);
area=imagesize(25,25,75,75);
buff=malloc(area);
getimage(25,25,75,75,buff);
putimage(25,25,buff,XOR_PUT); //erase devil
maxx=getmaxx();
maxy=getmaxy();
y1=maxy/2;
setcolor(15);
setfillstyle(SOLID_FILL,15);
rectangle(10,y1,12,y1+2); //
floodfill(11,y1+1,15); //draw bullet
area1=imagesize(10,y1,12,y1+2);
cuff=malloc(area1);
getimage(10,y1,12,y1+2,cuff);
putimage(10,y1,cuff,XOR_PUT); //erase bullet
setcolor(14);
rectangle(0,0,maxx,maxy);
setviewport(1,1,maxx-1,maxy-1,1);
settextstyle(1,0,3);
settextjustify(1,1);
delay(4000);
setcolor(15);
while(no<100) no="0;" ch="getch();" ch="=" x1dir="1;" ch="=" x1dir="=" y1="y1-10;" ch="=" x1dir="=" y1="y1+10;" ch="=" x1="x1+10*x1dir;" x="x+(xdir*random(30));" y="y+(ydir*random(20));">=maxx-71) //keep devil within screen
{
xdir*=-1;
x=maxx-71;
}
if(x<=175&&xdir==1) x=175; if(x<=175&&xdir==-1) xdir*=-1; if(y>=maxy-71)
{
ydir*=-1;
y=maxy-71;
}
if(y<=30) { ydir*=-1; y=30; } // if(x1>=maxx-3||x<=1) //failed chance { x1=20; x1dir=0; } if(y1>=maxy-20) //keep gun within screen
y1=maxy-21;
if(y1<=20) y1=21; // if(x1<=x+40&&x1>=x+12&&y1<=y+38&&y1>=y+10) //successful hit
{
moveto(maxx/2,maxy/2);
outtextxy(maxx/2,maxy/2,"...YOU'VE...WON...");
sound(500);
delay(5000);
nosound();
delay(3000);
exit(0);
}
}
while(chance<=10); if(chance=11) lost(); getch(); closegraph(); restorecrtmode(); } void exitmessage() { char cho; outtextxy(getmaxx()/2,getmaxy()/2,"EXIT : Y or N..."); delay(100); flushall(); cho=getch(); if(cho=='y'||cho=='Y') exit(0); else if(cho=='n'||cho=='N') { clearviewport; return; } } void lost() { outtextxy(getmaxx()/2,getmaxy()/2-50,"Your bullets are over"); outtextxy(getmaxx()/2,getmaxy()/2,"The devil destroys the world"); }

Related Links :

Snake Game in C



#include
#include
#include
#include
#include
#include

check();
end();
win();
int m[500],n[500],con=20,TEMP;
clock_t start,stop;

void main(void)
{

int gd=DETECT,gm,ch,maxx,maxy,x=13,y=14,p,q,spd=100;
int a=0,i=0,j,t,temp;
initgraph(&gd,&gm,"..\bgi");

setcolor(WHITE);
settextstyle(3,0,6);
outtextxy(200,2," SNAKE 2 BY RAJESH ");
settextstyle(6,0,2);
outtextxy(20,80," Use Arrow Keys To Direct The Snake ");
outtextxy(20,140," Avoid The Head Of Snake Not To Hit Any Part Of
Snake");
outtextxy(20,160," Pick The Beats Untill You Win The Game ");
outtextxy(20,200," Press 'Esc' Anytime To Exit ");
outtextxy(20,220," Press Any Key To Continue ");

outtextxy(20,220," DONT FORGET TO GIVE U R VALUABLE OPINION ");
ch=getch();
if(ch==27) exit(0);
cleardevice();
maxx=getmaxx();
maxy=getmaxy();

randomize();

p=random(maxx);
temp=p%13;
p=p-temp;
q=random(maxy);
temp=q%14;
q=q-temp;



start=clock();
while(1)
{

setcolor(WHITE);
setfillstyle(SOLID_FILL,con+5);
circle(p,q,5);
floodfill(p,q,WHITE);

if( kbhit() )
{
ch=getch(); if(ch==0) ch=getch();
if(ch==72&& a!=2) a=1;
if(ch==80&& a!=1) a=2;
if(ch==75&& a!=4) a=3;
if(ch==77&& a!=3) a=4;
}
else
{
if(ch==27
) break;
}

if(i<20){>=20)

{
for(j=con;j>=0;j--){
m[1+j]=m[j];
n[1+j]=n[j];
}
m[0]=x;
n[0]=y;

setcolor(WHITE);
setfillstyle(SOLID_FILL,con);
circle(m[0],n[0],8);
floodfill(m[0],n[0],WHITE);

setcolor(WHITE);
for(j=1;j=5) spd=spd-5; else spd=5;
if(con>490) win();
p=random(maxx); temp=p%13; p=p-temp;
q=random(maxy); temp=q%14; q=q-temp;
}
if(a==1) y = y-14; if(y<0) temp="maxy%14;y="maxy-temp;}" a="="2)" y =" y+14;">maxy) y=0;
if(a==3) x = x-13; if(x<0) temp="maxx%13;x="maxx-temp;}" a="="4)" x =" x+13;">maxx) x=0;
if(a==0){ y = y+14 ; x=x+13; }
}

}


check(){
int a;
for(a=1;a

Related Links :

Program Or Project to calculate Transportation Cost in c

Program to calculate Transportation Cost in c


#include
#include

main()
{
int flag=0,flag1=0;
int s[10],d[10],sn,eop=1,dm,a[10][10];
int i,j,sum=0,min,x[10][10],k,fa,fb;

clrscr();
/* Getting The Input For the Problem*/

printf("Enter the number of Supply
");
scanf("%d",&sn);
printf("Enter the number of Demand
");
scanf("%d",&dm);
printf("Enter the Supply Values
");
for(i=0;i=d[j]) //Check the supply greater than equal to
demand
{
x[i][j]=a[i][j]*d[j]; // Calculate amount * demand
s[i]=s[i]-d[j]; // Calculate supply - demand
j++; // Increment j for the deletion of the row
or
column
}

}
/* The Cost Matrix is Estimated here */
printf("Given Cost Matrix is :
");
for(fa=0;fa



Related Links :

Program to hide the partation of your disk drive in c.


#include
#include
#include
#include

typedef unsigned char BYTE;
typedef unsigned int WORD;
typedef unsigned long DWORD;

enum BOOL {TRUE=0,FALSE=1};
struct PARTITIONINFO {
BYTE bootid; /* bootable? 0=no, 128=yes */
BYTE beghead; /* beginning head number */
BYTE begsect; /* beginning sector number */
BYTE begcyl; /* 10 bit nmbr, with high 2 bits put in begsect */
BYTE systid; /* Operating System type indicator code */
BYTE endhead; /* ending head number */
BYTE endsect; /* ending sector number */
BYTE endcyl; /* also a 10 bit nmbr, with same high 2 bit trick */
DWORD relsect; /* first sector relative to start of disk */
DWORD numsect; /* number of sectors in partition */
};

struct DISK_ADD_PACKET {
BYTE recordsize;
BYTE reserved;
WORD count;
DWORD transferadd;
DWORD lowbits;
DWORD highbits;
};
struct MBR{
BYTE codes[446];
struct PARTITIONINFO partition[4];
WORD mbrid;
};
struct driveinfo{
DWORD startsect;
BYTE sysid;
};
WORD ExtentionCheck (BYTE drive)
{
union REGS regs;
regs.h.ah = 0x41;
regs.x.bx = 0x55aa;
regs.h.dl = drive;
int86(0x13,®s,®s);
if(regs.x.bx != 0xaa55)
return FALSE;
return TRUE;
}

WORD ReadSect(BYTE disk, int nsects,DWORD lsects,void* data)
{

union REGS iregs,oregs;
struct SREGS sregs;
int count=0;
struct DISK_ADD_PACKET * p;
p = (struct DISK_ADD_PACKET *)malloc(sizeof(struct DISK_ADD_PACKET));
p->recordsize=sizeof(struct DISK_ADD_PACKET);
p->count=nsects;
p->transferadd=(DWORD)data;
p->lowbits=lsects;
p->highbits=0; /* We dont need to access HD > 2TB */
iregs.h.ah = 0x42;
iregs.h.dl = disk;
iregs.x.si = FP_OFF(p);
sregs.ds = FP_SEG(p);
int86x(0x13,&iregs,&oregs,&sregs);
if(oregs.h.ah==0)
{
free(p);
return TRUE;
}

free(p);
return FALSE;

}
WORD WriteSect(BYTE disk, int nsects,DWORD lsects,void* data)
{

union REGS iregs,oregs;
struct SREGS sregs;
int count=0;
struct DISK_ADD_PACKET * p;
p = (struct DISK_ADD_PACKET *)malloc(sizeof(struct DISK_ADD_PACKET));
p->recordsize=sizeof(struct DISK_ADD_PACKET);
p->count=nsects;
p->transferadd=(DWORD)data;
p->lowbits=lsects;
p->highbits=0; /* We dont need to access HD > 2TB */
iregs.x.ax = 0x4302;
iregs.h.dl = disk;
iregs.x.si = FP_OFF(p);
sregs.ds = FP_SEG(p);
int86x(0x13,&iregs,&oregs,&sregs);
if(oregs.h.ah==0)
{
free(p);
return TRUE;
}

free(p);
return FALSE;

}
DWORD lsect=0;
void main()
{
BYTE disk=0x80;
WORD nsect=1,index=0,i=0,hi,choice;
DWORD extsect;
BYTE hideindex[5],id;
struct MBR *mbr;
struct driveinfo dinfo[10];//max 10 partitions
mbr=(struct MBR *)malloc(sizeof(struct MBR));
if(ExtentionCheck(disk)==FALSE)
{printf("extended int 13 is not supported
");
exit(1);
}


if(ReadSect(disk, nsect, lsect,(char *)mbr)==TRUE)
for(i=0;i<4;i++)
if(mbr->partition[i].systid!=0)
{printpart(mbr,i);
dinfo[index].startsect=lsect;
dinfo[index].sysid=mbr->partition[i].systid;
index++;
}
if(mbr->partition[1].systid==0xf)//0xf for extended partition
{lsect=mbr->partition[1].relsect;
extsect=lsect;
link:
if(ReadSect(disk, nsect, lsect,(char *)mbr)==TRUE)
{printpart(mbr,0);
dinfo[index].startsect=lsect;
dinfo[index].sysid=mbr->partition[0].systid;
index++;
if(index>=10){printf("no of partition exceed max limit");exit(1);}
if(mbr->partition[1].systid!=0)
{lsect=extsect+mbr->partition[1].relsect;
goto link;
}
}

}

printf("


Hide partition(1)
");
printf("Revele partition(2)
");
printf("Quit(3)
Enter your choice(1/2/3):");
hideindex[0]=getche();
choice=atoi(hideindex);
switch(choice)
{
case 1:
printf("
Which drive do u want to hide:(0-%d):",index-1);
scanf("%s",hideindex);
hi=atoi(hideindex);
if(hi<=index)
{
id=dinfo[hi].sysid;
if(id==1||id==4||id==7||id==0xb||id==0xc||id==0xe)
{ lsect=dinfo[hi].startsect;
id+=0x10;
if(ReadSect(disk, nsect, lsect,(char *)mbr)==TRUE)
{mbr->partition[0].systid=id;
if(WriteSect(disk,nsect,lsect,(char *)mbr)==TRUE)
printf("
HIDDEN SUCCESSFULLY");
}
}
else
printf("Cant Hide");
}
break;
case 2:
printf("
Which drive do u want to Revele:(0-%d):",index-1);
scanf("%s",hideindex);
hi=atoi(hideindex);
if(hi<=index)
{
id=dinfo[hi].sysid;
if(id==0x11||id==0x14||id==0x17||id==0x1b||id==0x1c||id==0x1e)
{ lsect=dinfo[hi].startsect;
id-=0x10;
if(ReadSect(disk, nsect, lsect,(char *)mbr)==TRUE)
{mbr->partition[0].systid=id;printf("%x",mbr->partition[0].systid);
if(WriteSect(disk,nsect,lsect,(char *)mbr)==TRUE)
printf("
REVELED SUCCESSFULLY");
}
}
else
printf("Cant Revele
");
}

break;
case 3:
exit(1);break;
default:
printf("
invalid choice");exit(1);
break;
};

}
printpart(struct MBR *mbr,WORD i)
{
BYTE bootable[]="YES";
BYTE id[7];
static BYTE c=0,index=0;
if(c==0)//to execute this for once
{
clrscr();
gotoxy(30,1);
printf("Partition Table");
gotoxy(2,2);
printf("INDEX");
gotoxy(8,2);
printf("SystemID");
gotoxy(17,2);
printf("Bootable");
gotoxy(26,2);
printf("StartingLBA");
gotoxy(38,2);
printf("SIZEINSECTORS");
gotoxy(52,2);
printf("SIZEINGB");
c++;
gotoxy(46,20);
printf("Coded by Tapan Kumar Mishra");
gotoxy(55,21);
printf("7th Sem,Electrical Engg.");
gotoxy(55,22);
printf("IGIT Sarang,Orissa");
gotoxy(46,23);
printf("Email id:titu_igit@rediffmail.com");
}
if(mbr->partition[i].bootid!=0x80)
strcpy(bootable,"NO");
gotoxy(2,3+index);
printf("%d",index);
gotoxy(8,3+index);
systemid((BYTE)mbr->partition[i].systid,id);
printf("%s",id);
gotoxy(17,3+index);
printf("%s",bootable);
gotoxy(26,3+index);
printf("%ld",mbr->partition[i].relsect+lsect);
gotoxy(38,3+index);
printf("%ld
",mbr->partition[i].numsect);
gotoxy(52,3+index);
printf("%5.2fGB",(float)mbr->partition[i].numsect/2097152.0);


index++;
return 0;
}
systemid(BYTE systid,BYTE *id)
{
switch(systid)
{
case 00:
strcpy(id,"empty");
break;
case 01:
strcpy(id,"FAT12");
break;
case 04:
strcpy(id,"FAT16");
break;
case 05:
strcpy(id,"EXTNED");
break;
case 0xb:
strcpy(id,"FAT32");
break;
case 0xc:
strcpy(id,"FAT32");
break;
case 0xE:
strcpy(id,"FAT16");
break;
case 0xf:
strcpy(id,"EXNDED");
break;
case 0x82:
strcpy(id,"SWAP");
break;
case 0x83:
strcpy(id,"EXT2fs");
break;
case 0x11:
case 0x14:
case 0x15:
case 0x16:
case 0x17:
case 0x1b:
case 0x1c:
case 0x1e:
case 0x1f:
strcpy(id,"hidden");
break;


}

}

Related Links :

Program to crack the User password of Windows 7, Hacking Windows Vista or 7

Program to crack the User password of Windows 7, Hacking Windows Vista or 7
Use the program at your own risk we are not responsible for any data loss this is just for experimental purpose not for commercial use.



# include
# include
# include
# include
# include
# include
# include

unsigned char huge Data[100001];
unsigned char keystream[1001];
int Rpoint[300];

void main(int argc,char *argv[]){
FILE *fd;
int i,j;
int size;
char ch;
char *name;
int cracked;
int sizemask;
int maxr;
int rsz;
int pos;
int Rall[300]; /* Resourse allocation table */

if(argc<2){ fd="fopen(argv[1]," fd="=" size="0;" name="argv[1];">2)name=argv[2];
printf("Username:%s
",name);

/* Copy encrypted text into keystream */
cracked=size-0x0208;
if(cracked<0)cracked=0;>1000)cracked=1000;
memcpy(keystream,Data+0x208,cracked);

/* Generate 20 bytes of keystream */
for(i=0;i<20;i++){ ch="toupper(name[i]);" ch="=" ch="=" cracked="20;" sizemask="keystream[0]+(keystream[1]<<8);" i="0;i<256;i++){">maxr)maxr=Data[i];
}
}

maxr=(((maxr/16)+1)*16); /* Resourse pointer table size appears to be
divisible by 16 */

/*Search after resources */

Rpoint[0]=0x0208+2*maxr+20+2; /* First resources */
for(i=0;i>8) & 0x00ff;
}
cracked+=maxr*2+2;
printf("%d Bytes of ketstream recoverd
",cracked);

/* Decrypt resources */
for(i=0;icracked)rsz=cracked;
printf("Resource[%d](%d)
",i,rsz);
for(j=0;j


Related Links :

Program to create Basic Shapes and Colors in C using Graphics.h

Program to create Basic Shapes and Colors in C using Graphics.h



#include
#include

void main()
{
int gd=DETECT, gm;
int poly[12]={350,450, 350,410, 430,400, 350,350, 300,430, 350,450 };
initgraph(&gd, &gm, “”);

circle(100,100,50);
outtextxy(75,170, “Circle”);
rectangle(200,50,350,150);
outtextxy(240, 170, “Rectangle”);
ellipse(500, 100,0,360, 100,50);
outtextxy(480, 170, “Ellipse”);
line(100,250,540,250);
outtextxy(300,260,”Line”);

sector(150, 400, 30, 300, 100,50);
outtextxy(120, 460, “Sector”);
drawpoly(6, poly);
outtextxy(340, 460, “Polygon”);
getch();
closegraph();
}

Related Links :


If you face any Problem in viewing code such as Incomplete "For Loops" or "Incorrect greater than or smaller" than equal to signs then please collect from My Web Site CLICK HERE


More Useful Topics...

 

History Of C..

In the beginning was Charles Babbage and his Analytical Engine, a machine
he built in 1822 that could be programmed to carry out different computations.
Move forward more than 100 years, where the U.S. government in
1942 used concepts from Babbage’s engine to create the ENIAC, the first
modern computer.
Meanwhile, over at the AT&T Bell Labs, in 1972 Dennis Ritchie was working
with two languages: B (for Bell) and BCPL (Basic Combined Programming
Language). Inspired by Pascal, Mr. Ritchie developed the C programming
language.

My 1st Program...


#include
#include
void main ()
{
clrscr ();
printf ("\n\n\n\n");
printf ("\t\t\t*******Pankaj *******\n");
printf ("\t\t\t********************************\n");
printf ("\t\t\t\"Life is Good...\"\n");
printf ("\t\t\t********************************");
getch ();
}

Next Step...


#include
#include

void main ()
{
clrscr ();
printf ("\n\n\n\n\n\n\n\n");
printf ("\t\t\t --------------------------- \n\n");

printf ("\t\t\t | IGCT, Info Computers, INDIA | \n\n");
printf ("\t\t\t --------------------------- ");

getch ();

}

Hits!!!