Академический Документы
Профессиональный Документы
Культура Документы
sohbingchang90@hotmail.com
Friday, October 30, 2009
void main() { int i,f=0; struct date { int date; int month; int year; }; struct date d[2]; for(i=0;i<2;i++) { printf("\nEnter day for the %d) date\n",i+1); scanf("%d",&d[i].date); printf("\nEnter the month for the %d) date\n",i+1); scanf("%d",&d[i].month); printf("\nEnter the year for the %d) date\n",i+1); scanf("%d",&d[i].year); }
if(d[0].date==d[1].date) { if(d[0].month==d[1].month) { if(d[0].year==d[1].year) { f=1; } } } if(f==1) printf("\nThe dates are equal"); else printf("\nThe dates are not equal"); }
Posted bybbbat9:27 AM0 comments
int code; char name[20]; char datej[8]; }; struct em e[5]; for(i=0;i<5;i++) { printf("\nKey in code, name and date(ddmmyyy) of employment for %d) employee\n",i+1); scanf("%d%s%s",&e[i].code,e[i].name,e[i].datej); if(strlen(e[i].datej)!=8) { printf("\nYou keyed the date wrongly, key again"); i--; continue; } } while(1) { clrscr(); printf("\nEnter current date\n"); scanf("%s",date);
for(i=0;i<5;i++) { k=0; k=funccheck(date,e[i].datej); if(k==1) printf("\nEmployee code= %d Employee name= %s has tenure more than or equal 3 years",e[i].code,e[i].name); } printf("\nKey q to quit or any other key to continue\n");
scanf("%s",j); if(j[0]==113) break; } } funccheck(char *date,char *datej) { int a,a1,i,t; for(i=7,t=1,a=0;i>3;i--,t*=10) { a=a+((*(date+i)-48)*t); } for(i=7,t=1,a1=0;i>3;i--,t*=10) { a1=a1+((*(datej+i)-48)*t); } if(a-a1>3) return(1); else if(a-a1<0) return(0); for(i=3,a=0,t=1;i>1;i--,t*=10) { a=a+((*(date+i)-48)*t); } for(i=3,a1=0,t=1;i>1;i--,t*=10) { a1=a1+((*(datej+i)-48)*t); } if(a-a1>0) return(1);
else if(a-a1<0) return(0); for(i=1,a=0,t=1;i>=0;i--,t*=10) { a=a+((*(date+i)-48)*t); } for(i=1,a1=0,t=1;i>=0;i--,t*=10) { a1=a1+((*(datej+i)-48)*t); } if(a-a1>=0) return(1); else if(a-a1<0) return(0); }
Posted bybbbat9:25 AM0 comments
/* for(i=0,letter=65;i<2;i++,letter++) { for(j=0;j<9;j++) { printf("\Key in values for year,material and quantity respectively for part %c%c%d\n",letter,letter,j+1); scanf("%d%s%d",&p[i][j].year,&p[i][j].material,&p[i][j].qty); } } */ while(1) { clrscr(); printf("\nKey in the part number to retrieve the information from\n"); scanf("%s",m); printf("\nKey the part number till the information is retrieved(End)\n"); scanf("%s",n); a=((m[0]-65)*9+(m[2]-49)); b=((n[0]-65)*9+(n[2]-49)); printf("\na is %d,\nb is %d,\nm[0] is %d, n[0] is %d",a,b,m[0],n[0]); c=a; d=a; while(c>=9) { c-=9; } printf("\nc after while is %d",c); while( d>9) d-=9;
for(i=a;i<=b;i++,c++,d++) { if(c==9)
{ m[0]+=1; c=0; } if(d==9) { d=0; } printf("\nPart: %c%c%d, Year: %d, Material: %s, Quantity: %d",m[0],m[0],d+1,p[i].year,p[i].material,p[i].qty); }
void main() { char j[1]; int yearc,rollc,i; struct book { int roll; char name[20]; char department[20]; char course[20]; int year;
}; struct book b[5]={ {1,"MrA","Science","Physics",2009}, {2,"MrB","Science","Maths",2008}, {3,"MrC","Arts","History",2009}, {4,"MrsD","Arts","History",2010}, {5,"MrsE","Science","Maths",2009} }; while(1) { clrscr(); printf("\nEnter a year(2000 or 2001)\n"); scanf("%d",&yearc); for(i=0;i<5;i++) { if(yearc==b[i].year) printf("\nName: %s Year: %d",b[i].name,b[i].year); } printf("\nEnter a roll number(1-5)\n"); scanf("%d",&rollc); for(i=0;i<5;i++) { if(rollc==b[i].roll) { printf("\nRoll number: %d, Name: %s, Department: %s\nCourse: %s,Year: %d",b[i].roll,b[i].name,b[i].department,b[i].course,b[i].year); break; } } printf("\nPress q to quit or any key to continue\n"); scanf("%s",j);
void main() { char sent[]="Pleases read this application and give me gratuity"; int i,c; for(i=0,c=0;sent[i]!='\0';i++) { if((sent[i]==97||sent[i]==101||sent[i]==105||sent[i]==117)&&(sent[i+ 1]==97||sent[i+1]==101||sent[i+1]==105||sent[i+1]==111||sent[i+1] ==117)) c++; } printf("\nThere are %d occurences of two vowels in succession",c); }
Posted bybbbat8:57 AM0 comments
int i,j,c,k,f,len,a; for(i=0;i<5;i++) { for(j=0;names[i][j]!=0;j++) { len=strlen(&names[i][0]); for(k=len;k>0;k--) { if(names[i][k]==32) { a=k; break; } } if(j==0) { c=j;
for(k=0,f=0;names[i][k]!=0;k++) { if(names[i][k]==32||f==1) { names[i][j+1]=names[i][k]; f=1; j++; } } names[i][j+1]='\0'; j=c; } else if(j==a) break; else if(names[i][j]==32&&names[i][j+2]!=32) { c=j; for(k=j+2,j=j+2,f=0;names[i][k]!=0;k++) { if(names[i][k]==32||f==1) { names[i][j]=names[i][k]; f=1; j++; } } names[i][j]='\0'; j=c; } } } for(i=0;i<5;i++) printf("\n%s",&names[i][0]);
}
Posted bybbbat8:51 AM0 comments
Write a program to delete all vowels from a sentence. Assume that the sentence is not more than 80 characters long. void main() { char sent[]="She sells seashells on the seashore"; int i; for(i=0;sent[i]!=0;i++) { if(sent[i]==97||sent[i]==101||sent[i]==105||sent[i]==111||sent[i]==1 17) { for(;sent[i+1]!=0;i++) sent[i]=sent[i+1]; sent[i]='\0'; i=-1; } } printf("\n%s",sent); }
Posted bybbbat8:45 AM1 comments
Note that according to the Gregorian calendar 01/01/1900 was Monday. With this as the base the calendar should be generated. Modify the above program suitably so that once the calendar for a particular month and year has been displayed on the screen, then using arrow keys the user must be able to change the calendar in the following manner: Up arrow key : Next year, same month Down arrow key : Previous year, same month Right arrow key : Same year, next month Left arrow key : Same year, previous month If the escape key is hit then the procedure should stop. Hint: Use the getkey( ) function discussed in Chapter 8, problem number [L](c).
#include "dos.h" void main() { int f=0,year,month,mod,i,j,k,m; char z[1]; clrscr(); while(1) { if(f==0) { gotoxy(20,2); printf("\nKey in the year"); scanf("%d",&year); gotoxy(20,4); printf("\nKey in the month(digits)"); scanf("%d",&month); clrscr(); if(year<1900||year>3500) { printf("\nCalendar out of range"); continue; }
month=month-1; if(m==77) month=month+1; if(month==13) { month=1; year=year+1; } if(month==0) { month=12; year=year-1; } if(year<1900) break; clrscr(); creategrid(); header(year,month);
printf("%c",218); gotoxy(i,22); printf("%c",192); } else if(i==59) { gotoxy(i,1); printf("%c",191); gotoxy(i,22); printf("%c",217); } else { gotoxy(i,1); printf("%c",196); gotoxy(i,22); printf("%c",196); } } for(i=20;i<=56;i++) { if(i==20) { gotoxy(i,4); printf("%c",218); gotoxy(i,21); printf("%c",192); } else if(i==56) { gotoxy(i,4); printf("%c",191); gotoxy(i,21); printf("%c",217); } else {
gotoxy(i,4); printf("%c",196); gotoxy(i,21); printf("%c",196); } } for(i=2;i<=21;i++) { gotoxy(17,i); printf("%c",179); gotoxy(59,i); printf("%c",179); } for(i=5;i<=20;i++) { gotoxy(20,i); printf("%c",179); gotoxy(56,i); printf("%c",179); } gotoxy(22,7); printf("Mon"); gotoxy(27,7); printf("Tue"); gotoxy(32,7); printf("Wed"); gotoxy(37,7); printf("Thu"); gotoxy(42,7); printf("Fri");
gotoxy(47,7); printf("Sat"); gotoxy(52,7); printf("Sun"); gotoxy(21,23); printf("%c=Next year",30); gotoxy(39,23); printf("%c=Previous year",31); gotoxy(21,24); printf("%c=Next month",16); gotoxy(39,24); printf("%c=Previous month",17); } getkey() { union REGS i,o; while(!kbhit()) ; i.h.ah=0; int86(22,&i,&o); return(o.h.ah); } header(int year,int month) { int len; char *m; switch(month) { case 1:
m="January"; break; case 2: m="February"; break; case 3: m="March"; break; case 4: m="April"; break; case 5: m="May"; break; case 6: m="June"; break; case 7: m="July"; break; case 8: m="August"; break; case 9: m="September"; break; case 10: m="October"; break;
case 11: m="November"; break; case 12: m="December"; break; } len=strlen(m)+5; len=len/2; gotoxy(38-len,5); printf("%s %d",m,year); } dayofmonth(int year,int month) { int leap,mod,check=0,i,diff; float days; long days1; if((year%4==0&&year%100!=0)||year%400==0) check=1;
else if(i==1) continue; else if(i==3) { if(check==0) days=days+28; else if(check==1) days=days+29; } else if(i<9) { if(i%2==0) days=days+31; else days=days+30; } else if(i==9) days=days+31; else if(i>9) { if(i%2==0) days=days+30; else days=days+31; } } days1=days; mod=days1%7; return(mod);
} daysinmonth(int year,int month) { int days; if(((year%4==0&&year%100!=0)||year%400==0)&&month==2) days=29; else if(month==2) days=28; else if(month<8) { if(month%2==0) days=30; else days=31; } else if(month==8) days=31; else if(month>8) { if(month%2==0) days=31; else days=30; } return(days); } gotoarr(int i) { int row,col,x,y; row=((i-1)/7)+1;
void main() { char *s[]={ "To err is human...", "But to really mess things up...", "One needs to know C!!" };
int i;
for(i=0;i<3;i++) xstrrev(s[i]); for(i=0;i<3;i++) printf("\n%s",s[i]); } xstrrev(char *m) { char *temp1; char *temp2; char *clear; int i,len,j; *clear='\0'; len=strlen(m)-1; for(i=0,j=len;;i++,j--) { printf("\n b4 *(m+i) is %c",*(m+i)); *temp1=*(m+i); *temp2=*(m+j); *(m+i)=*clear; *(m+j)=*clear; *(m+i)=*temp2; *(m+j)=*temp1; /* printf("\n i is %d, j is %d",i,j); */ if((j-i)==1||j==i) break; printf("\n After *(m+i) is %c",*(m+i));
} }
Posted bybbbat8:08 AM0 comments
int i,j; for(i=0;i<10;i++) { printf("\nKey in the %d) word",i+1); scanf("%s",&words[i][0]); } for(i=0;i<9;i++) { for(j=0;words[i][j]!=0;j++) { if(words[i][j]>words[i+1][j]) { strcpy(temp,&words[i][0]); strcpy(temp2,&words[i+1][0]); strcpy(&words[i][0],clear); strcpy(&words[i+1][0],clear); strcpy(&words[i][0],temp2); strcpy(&words[i+1][0],temp); i=-1;
} else if (words[i][j]==words[i+1][j]) continue; else break; } } for(i=0;i<10;i++) { printf("\n%s",&words[i][0]); } } Note: This code only works for small letters. If you want to use uppercase letters then create a function to convert all uppercase to lowercase first then do the main code then at the end convert back to uppercase and print.
Posted bybbbat8:03 AM0 comments
For example if str1 contains "mountain" and str2 contains "car", then the second string in str should get changed to "Move a car".
Note: There is a limitation to this code *** Except for the first sentence if the word you want to replace is longer than the original word the program doesn't work ideally. So the replace function seem in the program works only on single line
sentences(i.e One dimension char array). The reason for this is that a longer word pushes the location of the last letter of the sentence into the next sentence.For example if a is replace with two in the mountain sentence then the last letter "n" of mountain gets pushed to a location at around "e" in "Level" in the next sentence. The code in replace only accounts for longer words in one sentence. If you want to overcome this limitation then add a new string array. "replace" function becomes replace(char *m,int j,char *n,char *new) where char *new is a blank array defined in main(). Then pass this blank array to char *new in replace function.
Posted bybbbat7:31 AM0 comments
void main() { char sent[]="Grim return to the planet of apes!!"; int i; for(i=0;sent[i]!=0;i++) { if(sent[i]==32&&sent[i+1]==32) {
i=0;
} printf("\n%s",sent); }
Posted bybbbat7:26 AM0 comments
Write a program that extracts part of the given string from the specified position. For example, if the sting is "Working with strings is fun", then if from position 4, 4 characters are to be extracted then the program should return string as "king". Moreover, if the position from where the string is to be extracted is given and the number of characters to be extracted is 0 then the program should extract entire string from the specified position.
void main() { char stri[]="Working with string is fun"; char stri2[10]; int a,flag=0,i=0,b; printf("\nEnter a position for sentence: Working with string is fun"); scanf("%d",&a); while(flag==0) { if(i==(a-1)) { if(stri[i]==32) { i++; for(b=0;;b++,i++) { if(stri[i]==32||stri[i]=='\0') { stri2[b]='\0'; break; } stri2[b]=stri[i]; } }
while(word[i]!='\0') {
void main() { char source[]="Folks!"; char target[30]="Hello"; scat(target,source); printf("\nSource string = %s",source); printf("\nTarget string = %s",target); } scat(char *m,char *n) { char *p; p=m; while(*n!='\0') { if(*m=='\0'||m>p+6) { *m=*n; n++; } m++;
} *m='\0'; }
Posted bybbbat7:09 AM0 comments
c=sqrt((a*a)+(b*b)); return(c); }
Posted bybbbat7:07 AM0 comments
#include math.h (include arrows) void main() { float arr[10][2]={ 3.0,1.5, 4.5,2.0, 5.5,3.5, 6.5,5.0, 7.5,6.0, 8.5,7.5, 8.0,9.0, 9.0,10.5, 9.5,12.0, 10.0,14.0 }; int i,j; float sx=0,sy=0,sx2=0,sxy=0,my,mx,a,b; /* for(i=0;i<10;i++) { for(j=0;j<2;j++) { printf("\nKey in the [%d][%d] value",i+1,j+1); scanf("%f",&arr[i][j]); } } */ /*calculating summation x*/ for(i=0;i<10;i++) sx=sx+arr[i][0];
/*calculating summation y*/ for(i=0;i<10;i++) sy=sy+arr[i][1]; /*calculating summation x2*/ for(i=0;i<10;i++) sx2=sx2+(arr[i][0]*arr[i][0]);
/*calculating summation xy*/ for(i=0;i<10;i++) sxy=sxy+(arr[i][0]*arr[i][1]); my=sy/i; mx=sx/i; b=((i*sxy)-(sx*sy))/((i*sx2)-(sx*sx)); a=my-(b*mx); printf("\nThe value of a is %f\nThe value of b is %f",a,b); }
Posted bybbbat7:02 AM0 comments
#include math.h (include arrows) void main() { float arr[11][2]={ 34.22,102.43, 39.87,100.93, 41.85,97.43, 43.23,97.81,
40.06,98.32, 53.29,98.32, 53.29,100.07, 54.14,97.08, 49.12,91.59, 40.71,94.85, 55.15,94.65 }; int i,j; float sx=0,sy=0,sx2=0,sy2=0,sxy=0,b,r;
/*calculating summation x*/ for(i=0;i<11;i++) sx=sx+arr[i][0]; printf("\nsummation x is %f",sx); /*calculating summation y*/ for(i=0;i<11;i++) sy=sy+arr[i][1]; printf("\nsummation y is %f",sy); /*calculating summation x2*/ for(i=0;i<11;i++) sx2=sx2+(arr[i][0]*arr[i][0]); printf("\nsummation x2 is %f",sx2); /*calculating summation y2*/ for(i=0;i<11;i++) sy2=sy2+(arr[i][1]*arr[i][1]); printf("\nsummation sy2 is %f",sy2); /*calculating summation xy*/ for(i=0;i<11;i++) sxy=sxy+(arr[i][0]*arr[i][1]); printf("\nsummation sxy is %f",sxy);
/*calculating bottom part*/ b=(i*sx2-(sx*sx))*(i*sy2-(sy*sy)); printf("\nbottom is %f",b); /*calculating coefficient r*/ r=(sxy-(sx*sy))/(sqrt(b)); printf("\n The correlation coefficient is %f",r); }
Posted bybbbat6:58 AM0 comments
int i,j,d; float area,c=0; for(i=0;i<6;i++) { for(j=0;j<3;j++) { printf("\nKey in the [%d][%d] value",i+1,j+1); scanf("%f",&arr[i][j]); } } for(i=0;i<6;i++)
{ area=(1.0/2.0)*arr[i][0]*arr[i][1]*sin(arr[i][2]); if(area>c) { printf("\n1"); c=area; d=i; } } printf("\nThe biggest plot of land is plot no. %d with area %f",d+1,c); }
Posted bybbbat6:52 AM0 comments
Very often in fairs we come across a puzzle that contains 15 numbered square pieces mounted on a frame. These pieces can be moved horizontally or vertically. A possible arrangement of these pieces is shown below:
As you can see there is a blank at bottom right corner. Implement the following procedure through a program:
Draw the boxes as shown above. Display the numbers in the above order. Allow the user to hit any of the arrow keys (up, down, left, or right). If user hits say, right arrow key then the piece with a number 5 should move to the right and blank should replace the original position of 5. Similarly, if down arrow key is
hit, then 13 should move down and blank should replace the original position of 13. If left arrow key or up arrow key is hit then no action should be taken. The user would continue hitting the arrow keys till the numbers arent arranged in ascending order. Keep track of the number of moves in which the user manages to arrange the numbers in ascending order. The user who manages it in minimum number of moves is the one who wins. How do we tackle the arrow keys? We cannot receive them using scanf( ) function. Arrow keys are special keys which are identified by their scan codes. Use the following function in your program. It would return the scan code of the arrow key being hit. Dont worry about how this function is written. We are going to deal with it later. The scan codes for the arrow keys are: up arrow key 72 down arrow key 80 left arrow key 75 right arrow key 77 /* Returns scan code of the key that has been hit */ #include "dos.h" getkey( ) { union REGS i, o ; while ( !kbhit( ) ) ; i.h.ah = 0 ; int86 ( 22, &i, &o ) ; return ( o.h.ah ) ; }
ANS: #include "dos.h" void main() { void creategrid(); int g,c; int arr[16]={1,4,15,7,8,10,2,11,14,3,6,13,12,9,5,0};
clrscr(); creategrid(); printarray(arr); for(g=15,c=0;;) { int k,a,b,i; k=getkey(); if(k==80) { if((g-4)<0) a="arr[g-4];" b="arr[g];" k="="72)">15) continue; a=arr[g+4]; b=arr[g]; arr[g+4]=b; arr[g]=a; go(g); printf("%d",arr[g]); go(g+4); printf("%c%c",0,0); go(g+4); c++; g+=4; } if(k==75) { if(g==3g==7g==11g==15) continue; a=arr[g+1]; b=arr[g]; arr[g+1]=b; arr[g]=a; go(g); printf("%d",arr[g]);
go(g+1); printf("%c%c",0,0); go(g+1); c++; g+=1; } if(k==77) { if(g==0g==4g==8g==12) continue; a=arr[g-1]; b=arr[g]; arr[g-1]=b; arr[g]=a; go(g); printf("%d",arr[g]); go(g-1); printf("%c%c",0,0); go(g-1); c++; g-=1; } for(i=0;i<15;i++) { if(arr[i]!=i+1) break; if(arr[i]==(i+1)&&i==14) { gotoxy(6,24); printf("\nNumber of moves to complete is %d",c); exit(); } } }
} go(int g) { switch(g) { case 0: gotoxy(8,5); break; case 1: gotoxy(12,5); break; case 2: gotoxy(16,5); break; case 3: gotoxy(20,5); break; case 4: gotoxy(8,9); break; case 5: gotoxy(12,9); break; case 6: gotoxy(16,9); break; case 7: gotoxy(20,9); break; case 8: gotoxy(8,13); break; case 9:
gotoxy(12,13); break; case 10: gotoxy(16,13); break; case 11: gotoxy(20,13); break; case 12: gotoxy(8,17); break; case 13: gotoxy(12,17); break; case 14: gotoxy(16,17); break; case 15: gotoxy(20,17); break; } }
getkey() { union REGS i,o; while(!kbhit()) ; i.h.ah=0; int86(22,&i,&o); return(o.h.ah); } printarray(int *m) { int a,b,i,j;
void creategrid() { int a,b; for(a=3;a<=19;a+=4) { for(b=6;b<=22;b++) { if(b==6(b-6)%4==0) { if(a==3) { if(b==6) { gotoxy(6,3); printf("%c",218); } else if(b==22) { gotoxy(22,3); printf("%c",191); }
else { gotoxy(b,3); printf("%c",194); } } else if(a==19) { if(b==6) { gotoxy(6,19); printf("%c",192); } else if(b==22) { gotoxy(22,19); printf("%c",217); } else { gotoxy(b,19); printf("%c",193); } } else { if(b==6) { gotoxy(6,a); printf("%c",195); } else if(b==22) {
gotoxy(22,a); printf("%c",180); } else { gotoxy(b,a); printf("%c",197); } } } else { printf("%c",196); } } } for(b=6;b<=22;b+=4) { for(a=4;a<=18;a++) { if((a-3)%4==0) continue; else { gotoxy(b,a); printf("%c",179); } } } }
Posted bybbbat6:04 AM0 comments
Write a program to obtain transpose of a 4 x 4 matrix. The transpose of a matrix is obtained by exchanging the elements of each row with the elements of the corresponding column.
void main() { int arr[4][4]; int i,j,a,b,f; printf("\nInput numbers to 4*4 matrix"); for(i=0;i<4;i++) { for(j=0;j<4;j++) { printf("\nKey in the [%d][%d]) value",i+1,j+1); scanf("%d",&arr[i][j]); } } for(i=0;i<4;i++) { for(j=0,f=0;j<4;j++) { if(i!=j&&f==0) continue; a=arr[i][j]; b=arr[j][i]; arr[i][j]=b; arr[j][i]=a; f=1; } } for(i=0;i<4;i++) { for(j=0;j<4;j++)
{ 7,8,9, 10,11,12 }, { 13,14,15, 16,17,18 } }; printf("\nFirst element of array is %d\nLast element of the array is %d",threed[0][0][0],threed[2][1][2]); }
Posted bybbbat5:54 AM0 comments
Chap8[I]d
Write a program which performs the following tasks: initialize an integer array of 10 elements in main( ) pass the entire array to a function modify( ) in modify( ) multiply each element of array by 3 return the control to main( ) and print the new array elements in main( )
void main() { int arr[25]; int i,*j,k; j=arr; printf("\nInput 25 integers"); for(i=0;i<25;i++,j++) { printf("\nKey in the %d) value",i+1); scanf("%d",&*j); }
With Pointers void main() { int arr1[5]={1,2,3,4,5}; int arr2[5]; int *m; int i,*j,k,l=5;
j=arr1; m=arr2; func(j,m,l); for(i=0;i<5;i++) printf("\nValue of arr2[%d] is %d",i,arr2[i]); } func(int *j, int *m, int l) { int i; for(j=j+4,i=0;i<5;i++,j--,m++) *m=*j; }
Posted bybbbat5:31 AM0 comments
printf("\nInput 25 numbers into the array"); for(i=0;i<25;i++) { printf("\nKey in the %d) value",i); scanf("%d",&arr[i]); } printf("\nStarting insertion sort"); for(a=1;a<25;a++) { b=arr[0]; c=arr[a]; arr[0]=c; arr[a]=b; } printf("\nInsertion sort done");
/*Bubble sort*/ void main() { int arr[25]; int a,b,c,d,i; printf("\nInput 25 numbers into the array"); for(i=0;i<25;i++) {
printf("\nKey the %d) value",i); scanf("%d",&arr[i]); } printf("\nStarting bubble sort"); for(i=24;i>0;i--) { for(b=0,c=b+1;c<=i;b++,c++) { a=arr[b]; d=arr[c]; arr[b]=d; arr[c]=a; } } printf("\nBubble sort done"); for(i=0;i<25;i++) printf("\n%d value is %d",i,arr[i]); }
Posted bybbbat5:02 AM0 comments
/* Selection sort */ void main() { int arr[25]; int a,b,d,i; printf("\nInput 25 numbers into array"); for(i=0;i<25;i++) {
printf("\nKey the %d) value",i); scanf("%d",&arr[i]); } printf("\nStarting selection sorting"); for(i=0;i<24;i++) { for(d=i+1;d<25;d++) { a=arr[i]; b=arr[d]; arr[i]=b; arr[d]=a; } } printf("\nSelection sorting done"); for(i=0;i<25;i++) printf("\n%d) value is %d",i,arr[i]); }
Posted bybbbat4:57 AM1 comments
Chap8[D]b Finding +tive -tive zeros, odd and even numbers in array
Twenty-five numbers are entered from the keyboard into an array. Write a program to find out how many of them are positive, how many are negative, how many are even and how many odd. void main() { int arr[25]; int a,b,c,d,e,i; a=0; b=0; c=0;
d=0; e=0; for(i=0;i<25;i++) { printf("\nKey the %d) value",i); scanf("%d",&arr[i]); } for(i=0;i<25;i++) { if(arr[i]>0) a++; if(arr[i]<0) b++; if(arr[i]==0) c++; if(arr[i]%2==0) d++; else e++; } if(a>0) printf("\nThere are %d positive integers",a); if(b>0) printf("\nThere are %d negative integers",b); if(c>0) printf("\nThere are %d zeros",c); if(d>0) printf("\nThere are %d even numbers",d);
void main() { float sin(float); float d,e; printf("\nInput x value into sin(x) to find its result"); scanf("%f",&d); e=sin(d); printf("\nThe result is %f",e); } float fact(float x) { int f; if(x==1) return(1); else f=x*fact(x-1); return(f); } float power(float y,float z) { float w; if(z==0) return(1); if(z==1) return(y); w=y*(power(y,z-1));
return(w); } float sin(float a) { float fact(float); float b; float power(float,float); b=a-(power(a,3)/fact(3.0))+(power(a,5)/fact(5.0))(power(a,7)/fact(7.0))+(power(a,9)/fact(9.0)); return(b); }
Posted bybbbat4:47 AM0 comments
void main() { int d,e; d=25; e=naturaln(d); printf("\nThe sum of the first %d digits is %d",d,e); } naturaln(int x) { int a; if(x==1) return(1); else { a=x+naturaln(x-1); return(a); }
}
Posted bybbbat4:46 AM0 comments
Fibonacci Sequence
Write a recursive function to obtain the first 25 numbers of a Fibonacci sequence. In a Fibonacci sequence the sum of two successive terms gives the third term. Following are the first few terms of the Fibonacci sequence: 1 1 2 3 5 8 13 21 34 55 89... void main() { void Fib(float,float,float); float e,d; /* i put d=24 because the function will start off by printing 1 and starts counting its recursion only after the first digit so if i want 25 numbers its 25-1=24*/ d=24; e=1; printf("\Display Fibonacci sequence"); Fib(d,e,1.0); }
void Fib(float x,float a,float b) { if(a==1) printf("\n1"); if(x==0) exit(); printf("\n%f",a); if(x==1) exit(); b=a+b; printf("\n%f",b);
Fib(x-2,a+b,b); }
Posted bybbbat4:44 AM0 comments
void main() { int a,b,c,full; float av,perc; printf("\nEnter the marks received by the student in 3 subjects and the total possible marks for 1 paper"); scanf("%d%d%d%d",&a,&b,&c,&full); calc(a,b,c,full,&av,&perc); printf("\nThe average marks is %f.\nThe percentage is %f",av,perc); } calc(int i,int j,int k,int full,float *ave,float *perce) { *ave=(i+j+k)/3.0; *perce=(*ave/full)*100.0; }
Posted bybbbat4:38 AM0 comments
*std=sqrt((((a-*av)*(a-*av))+((b-*av)*(b-*av))+((c-*av)*(c*av)))/5.0); }
Posted bybbbat4:37 AM0 comments
void main() { int x; printf("\nInput an integer\n"); scanf("%d",&x); prime(x); } prime(int x) { int a; for(a=2;a<=x;a++) { if(x%a==0) { printf("%d ",a); prime(x/a); break; } } }
without recursion void main() { int x; printf("\nInput an integer\n"); scanf("%d",&x); prime(x); } prime(int x) { int a;
Power function
Write a function power ( a, b ), to calculate the value of a raised to b.
void main() { float power(float,float); float x,y,z; printf("\nInput the first value and second of which the first is raised to the power of the second value"); scanf("%f%f",&x,&y); z=power(x,y); printf("\nThe answer is %f",z); }
float power(float a,float b) { float c; if(b==0) return(1); if(b==1) return(a); else c=a*power(a,b-1); return(c); }
Posted bybbbat4:30 AM0 comments
Finding Factorial
Write a function to calculate the factorial value of any integer entered through the keyboard. void main() {
float fact(float); float a,a1; printf("\nInput a number to find the factorial"); scanf("%f",&a); a1=fact(a); printf("\nThe factorial of %f is %f",a,a1); } float fact(float x) { float f; if(x==1) return(1); else f=x*fact(x-1); return(f); }
Posted bybbbat4:25 AM0 comments
CHAP 1[H]i Sum of first and last digit CHAP 1[H]h Reversing number CHAP 1[H]g Caculating sum of digits CHAP 1[H]f Interchanging values CHAP 1[H]e Finding area , perimeter of circle and ... CHAP 1[H]d Converting Fahrenheit to Centigrade de... CHAP 1[H]c Finding aggregate and percentage marks CHAP 1[H]b Converting distance in km to m,inches,c... CHAP 1[H]a Calculating gross salary CHAP 2[C]L Checking if coordinate lies on,x,y axi... CHAP 2[C]j Checking if three coordinates form a st... CHAP 2[C]i Checking if area is bigger than perime... CHAP 2[C]g Checking for valid triangle(using sum ... CHAP 2[C]f Determining youngest age CHAP 2[C]e Reverse the number input CHAP 2[C]d Finding day on first of Jan on a parti... CHAP 2[C]c Checking for leap year CHAP 2[C]b Checking for odd or even number CHAP 2[C]a Determine profit from cost and sell pr... CHAP 2[F]j Checking customers order CHAP 2[F]i Qualifying for degree problem CHAP 2[F]h Checking efficiency of worker CHAP 2[F]f Checking whether triangle is valid CHAP 2[F]e Library fine CHAP 2[F]d Grade of steel CHAP 2[F]b Detecting capital,small letter ,digit... CHAP 3[E](m) Approximating natural log CHAP 3[E]L Calculating total amount after intere... CHAP 3[E]k Finding optimum life of machine CHAP 3[E]i Print a number triangle pattern CHAP 3[E]h Printing multiplication tables CHAP 3[E]g Printing diamond and hearts CHAP 3[E]f Making alphabet patterns CHAP 3[E]d Permutations of a 3-digit number CHAP 3[E]c Adding first seven terms of some serie... CHAP 3[E]b Printing smiling faces
o o
CHAP 3[E]a Printing prime numbers from 1 to 300 CHAP 3[B]f Playing with matchsticks CHAP 3[B]e Printing armstrong numbers CHAP 3[B]d Printing ASCII characters using while... CHAP 3[B]c Finding power of a value CHAP 3[B]b Finding Factorial CHAP 3[B](a) Calculating overtime pay CHAP 4[D] Case Control Structure (using switch) CHAP 14[A](b) Newspaper Problem (Using bits and FI... CHAP 14[A]a Rainbow problem Jan 23(1) Reading multiple words from text file
2009(69) November(13) Nov 30(1) Nov 15(3) Nov 14(1) Nov 12(1) Nov 11(4) Nov 04(2) Nov 01(1) October(56) Oct 30(51) Chap10[D]g Use structure to check dates Chap10[D]e Displaying data in structure with condi... Chap10[D]d Play Cricket Chap10[D]c Automobile has weird serial numbers Chap10[D]b Structure data of bank Chap10[D]a Printing specfic datas in structures Chap9[F]k Removing two vowels in succession Chap9[F]j Abbreviating names Chap9[F]i Deleting of all occurences of "the" Chap9[F]h Deleting all vowels from a sentence Chap9[F]e Creating a dynamic calendar Chap9[F]c Reversing strings Chap9[F]b Arrange words alphabetically
Chap9[F]a Replacing words in sentences Chp9[D]f Removing two or more spaces in a strin... Chap9[D]e Converting string digits to integers Chap 9[D]d Working with strings is fun Chap9[D]c Converting all lowercase to uppercase ... Creating your own strcat() Chap8[L]s Summation from first coordinate to las... Chap8[L]r Computing straight line Chap8[L]q Computing correlation coefficient Chap8[L]p Area of triangle and largest plot of l... Chap8[L]o Standard deviation and mean Chap8[L]L Finding norm of matrix Chap8[L]d Creating grid puzzle Chap8[L]c Transpose 4X4 matrix Chap8[L]b Pick largest number from matrix Chap8[L]a Initialising 3D array Chap8[I]d Chap8[I]c Finding smallest number in array using... Chap8[I]b Check similar integers in array Chap8[I]a Reversing contents and copy to another ... Chap8[D]d Sieve of Eratosthenes Chap8[D]c Insertion sort Chap8[D]c Buuuubbbble sort Chap8[D]c Selection sort Chap8[D]b Finding +tive -tive zeros, odd and even... Chap 8[D]a Search quantity of instances in Arra... Evaluating Sin(x) series Running sum of first 25 numbers Fibonacci Sequence Sum of 5 digits using recursion Average and percentage 5[F]c Sum,Average Standard deviation 5[F]b Product of float and integer 5[F]a Finding prime numbers Checking for leap year Power function
About Me
bbb Email: sohbingchang90@hotmail.com View my complete profile