1
C
Programming Training For Freshy
By
α
Computer Engineering 1st 2006 King Mongkut's Institute of Technology Ladkrabang Monday, September 04, 2006
αααααααααααααααααααααααααααααααααααααααααααααααααααααααααααααααααααααααααααα
αααααααααααααααααααααααααααααααααααααααααααααααααααααααααααααααααααααααααααα
αααααααααααααααααααααααααααααααααααααααααααααααααααααααα
αααααααααααααααααααααααααααααααααααααααααααααααααααααααα Present by DrAlpha Powered By
God Jesus and Holy spirit
2 Ex 1. - Ex 14. ผมไมเคยเขียน Flowchart เวลาจะเขียนโปรแกรมอะไรก็เขียนเลย Ex 15. #include<stdio.h> #include
int main() { long double x,y; printf("Enter first number :"); scanf("%Lf",&x); printf("Enter second number :"); scanf("%Lf",&y); printf("Sum of %Lf and %Lf is %Lf\n",x,y,x+y); printf("Different of %Lf and %Lf is %Lf\n",x,y,x-y); printf("Multiply of %Lf and %Lf is %Lf\n",x,y,x*y); printf("Divide of %Lf and %Lf is %Lf\n",x,y,x/y); getch(); return(1); } ----------------------------------------------------------------------------------------------------------------Ex 16. #include<stdio.h> #include int main() { float x,y,BMI; printf("Enter height (m):"); scanf("%f",&x); printf("Enter weight (kg):"); scanf("%f",&y); BMI=y/(x*x); printf("Body Mass Index is %f\n",BMI); if(BMI<18.5) printf("You weight is lower than standard\n."); else if(BMI>=18.5&&BMI<=24.95) printf("You weight is normal.\n"); else if(BMI>24.95&&BMI<30) printf("You weight is higher than standard.\n"); else if(BMI>=30) printf("You are too fat.\n"); getch(); return(1); } -----------------------------------------------------------------------------------------------------------------
Present by DrAlpha
Powered By God Jesus and Holy spirit
3 Ex 17. c=2a+b int a,b,c; c=a*2+b; 5 4 c=a +a +2a3+3a2+4a+3 #include<math.h> Å ตอง include เพิ่มที่หัวโปรแกรม เพื่อใชคําสั่ง power (คําสั่งหาคายกกําลัง) int c,a; c= power(a,5) + power(a,4) + 2*power(a,3) + 3*power(a,2) + 4*a +3; c=2+3a int a,c; c=2 + 3*a; ----------------------------------------------------------------------------------------------------------------Ex 18. #include<stdio.h> #include int main() { char name1[20],sername1[20]; char name2[20],sername2[20]; char name3[20],sername3[20]; long id1,id2,id3; printf("Enter name 1:"); scanf("%s",&name1); printf("Enter sername 1:"); scanf("%s",&sername1); printf("Enter ID 1:"); scanf("%ld",&id1); printf("Enter name 2:"); scanf("%s",&name2); printf("Enter sername 2:"); scanf("%s",&sername2); printf("Enter ID 2:"); scanf("%ld",&id2); printf("Enter name 3:"); scanf("%s",&name3); printf("Enter sername 3:"); scanf("%s",&sername3); printf("Enter ID 3:"); scanf("%ld",&id3); printf("+-------------+------------+-------------+\n"); printf("|%-13s|%-12s|%13ld|\n",name1,sername1,id1); printf("|%-13s|%-12s|%13ld|\n",name2,sername2,id2); printf("|%-13s|%-12s|%13ld|\n",name3,sername3,id3); printf("+-------------+------------+-------------+\n"); getch(); return(1); }
Present by DrAlpha
Powered By God Jesus and Holy spirit
4 Ex 19. #include<stdio.h> #include int main() { char temp[128]; scanf("%[^\n]",&temp); printf("%s",temp); getch(); return(1); } ----------------------------------------------------------------------------------------------------------------Ex 20. #include<stdio.h> #include int main() { float darn,hight; scanf("%f",&darn); printf("%f", darn/4*darn*1.732); getch(); return(1); } ----------------------------------------------------------------------------------------------------------------Ex 21. #include<stdio.h> #include int main() { int a1,a2,a3; printf("Enter 1 number :"); scanf("%d",&a1); printf("Enter 2 number :"); scanf("%d",&a2); printf("Enter 3 number :"); scanf("%d",&a3); if(a1>a2&&a1>a3) printf("Max number is %d",a1); else if(a2>a1&&a2>a3) printf("Max number is %d",a2); else if(a3>a2&&a3>a1) printf("Max number is %d",a3); else printf("Error!"); return(1); }
Present by DrAlpha
Powered By God Jesus and Holy spirit
5 Ex 22. #include<stdio.h> #include int main() { int a1,a2,a3; printf("Enter 1 number :"); scanf("%d",&a1); printf("Enter 2 number :"); scanf("%d",&a2); printf("Enter 3 number :"); scanf("%d",&a3); if(a1 #include int main() { int a1,a2,a3,a4,even=0; printf("Enter 1 number :"); scanf("%d",&a1); if(a1%2==0) even++; printf("Enter 2 number :"); scanf("%d",&a2); if(a2%2==0) even++; printf("Enter 3 number :"); scanf("%d",&a3); if(a3%2==0) even++; printf("Enter 4 number :"); scanf("%d",&a4); if(a4%2==0) even++; printf("Even number is %d",even); return(1); }
Present by DrAlpha
Powered By God Jesus and Holy spirit
6 Ex 24. #include<stdio.h> #include int main() { int a1,a2,a3,answer=0; printf("Enter 1 number :"); scanf("%d",&a1); printf("Enter 2 number :"); scanf("%d",&a2); printf("Enter 3 number :"); scanf("%d",&a3); if(a1a2&&a1>a3) { printf(" and %d",a1); answer+=a1; } else if(a2>a1&&a2>a3) { printf(" and %d",a2); answer+=a2; } else if(a3>a2&&a3>a1) { printf(" and %d",a3); answer+=a3; } else printf("Error!"); printf(" is %d",answer); return(1); } -----------------------------------------------------------------------------------------------------------------
Present by DrAlpha
Powered By God Jesus and Holy spirit
7 Ex 25. #include<stdio.h> #include int main() { int a1,a2,a3; printf("Enter 1 number :"); scanf("%d",&a1); printf("Enter 2 number :"); scanf("%d",&a2); printf("Enter 3 number :"); scanf("%d",&a3); if(a1>a2&&a1>a3) printf("Sum of %d and %d is %d",a2,a3,a2+a3); else if(a2>a1&&a2>a3) printf("Sum of %d and %d is %d",a1,a3,a1+a3); else if(a3>a2&&a3>a1) printf("Sum of %d and %d is %d",a2,a1,a2+a1); else printf("Error!"); return(1); } ----------------------------------------------------------------------------------------------------------------Ex 26. #include<stdio.h> #include int main() { int a1,a2,a3; printf("Enter 1 number :"); scanf("%d",&a1); printf("Enter 2 number :"); scanf("%d",&a2); printf("Enter 3 number :"); scanf("%d",&a3); if(a1
Present by DrAlpha
Powered By God Jesus and Holy spirit
8 Ex 27.
งงโจทยครับ เราใสอะไรก็ตามลงไปมันก็เปนดานของรูปสามเหลี่ยมไดไมใชหรือ??? Ex 28. #include<stdio.h rel="nofollow"> #include #include<math.h> Å include เพื่อ ใชคําสั่ง sqrt (คําสั่งหาคา Square root) int main() { int a,i; do { printf("Enter number :"); scanf("%d",&a); for(i=2;i<=sqrt(a);i++) { if(a%i==0&&i!=a) { printf("%d is not Only number\n",a); i=a+2; } } if(i!=a+3) printf("%d is Only number\n",a); }while(a!=-99); return(1); } ----------------------------------------------------------------------------------------------------------------Ex 29. #include<stdio.h> #include int main() { int a,answer=1; printf("Enter number :"); scanf("%d",&a); do { answer=1; answer*=a/100; answer*=a%100/10; answer*=a%10; printf(" %d * %d * %d = %d\n",a/100,a%100/10,a%10,answer); a=answer; }while(answer!=0); getch(); return(1); } -----------------------------------------------------------------------------------------------------------------
Present by DrAlpha
Powered By God Jesus and Holy spirit
9 Ex 30. #include<stdio.h> #include int main() { int g1,g2,i=1; long double x1,x2; printf("Population of A :"); scanf("%Lf",&x1); printf("Growth rate (%) :"); scanf("%d",&g1); printf("Population of B :"); scanf("%Lf",&x2); printf("Growth rate (%) :"); scanf("%d",&g2); printf("year 0, A=%.2Lf , B=%.2Lf\n",x1,x2); while(x1<=x2) { x1+=g1*x1/100; x2+=g2*x2/100; printf("year %d, A=%.2Lf , B=%.2Lf\n",i,x1,x2); i++; } printf("Duration = %d",i-1); getch(); return(1); } ----------------------------------------------------------------------------------------------------------------Ex 31. #include<stdio.h> #include int main() { int i=0; float height,s; printf("Height = "); scanf("%f",&height); s=height; while(height>1) { height*=0.4; s+=height*2; i++; } printf("Distance = %.2f\nBounce count = %d",s,i); getch(); return(1); }
Present by DrAlpha
Powered By God Jesus and Holy spirit
10 Ex 32. #include<stdio.h> #include int main() { int i=0; float mass,out=.5; printf("Mass (1000 kg) = "); scanf("%f",&mass); while(mass>0) { i++; if(i%10==0&&i!=0) mass+=10; else { mass-=out; out*=1.05; } } printf("car run %d km",i); getch(); return(1); } ----------------------------------------------------------------------------------------------------------------Ex 33. #include<stdio.h> #include int main() { int i=0; float v,t=0; printf("n = "); scanf("%f",&v); while(v>=.5) { t+=v*3; i+=3; v*=.8; } printf("duration time = %d seconds\n",i); printf("whirling about %.0f rounds\n",t+1); getch(); return(1); } -----------------------------------------------------------------------------------------------------------------
Present by DrAlpha
Powered By God Jesus and Holy spirit
11 Ex 34. #include<stdio.h> #include int main() { int i,n; scanf("%d",&n); for(i=0;i #include int main() { int i,j,n; scanf("%d",&n); for(i=0;i
Present by DrAlpha
Powered By God Jesus and Holy spirit
12 Ex 36. #include<stdio.h> #include int main() { int i,j,n; scanf("%d",&n); for(i=0;i #include int main() { int i,j,n; scanf("%d",&n); for(i=0;i
Present by DrAlpha
Powered By God Jesus and Holy spirit
13 Ex 38. #include<stdio.h> #include int main() { int i,j,n; scanf("%d",&n); for(i=0;i #include int main() { int i,j,n; scanf("%d",&n); for(i=0;i
Present by DrAlpha
Powered By God Jesus and Holy spirit
14 Ex 40. #include<stdio.h> #include int main() { int i,j,n; scanf("%d",&n); for(i=0;i=0;i--) { for(j=0;j
Present by DrAlpha
Powered By God Jesus and Holy spirit
15 Ex 41. #include<stdio.h> #include int main() { int i,j,n; scanf("%d",&n); for(i=n-1;i>0;i--) { for(j=0;j
Present by DrAlpha
Powered By God Jesus and Holy spirit
16 Ex 42. #include<stdio.h> #include int main() { int i,j,n; scanf("%d",&n); for(i=n-1;i>0;i--) { for(j=0;j
Present by DrAlpha
Powered By God Jesus and Holy spirit
17 Ex 43. #include<stdio.h> #include int main() { int i; float hight[10],avg=0; for(i=0;i<10;i++) { printf("student no %d hight is =",i+1); scanf("%f",&hight[i]); avg+=hight[i]; } avg/=10; for(i=0;i<10;i++) printf("student no %d hight is %.1f\n",i+1,hight[i]); printf("%f.2",avg); getch(); return(1); } -----------------------------------------------------------------------------------------------------------------
Present by DrAlpha
Powered By God Jesus and Holy spirit
18 Ex 44. #include<stdio.h> #include int main() { int i,n,lpoint[10],pointsum=0; float lgrade[15],gradeavg=0; char lname[15][40]; printf("n = "); scanf("%d",&n); for(i=0;i
Present by DrAlpha
Powered By God Jesus and Holy spirit
19 Ex 45. #include<stdio.h> #include int main() { int i,array[10],result=0; for(i=0;i<10;i++) { scanf("%d",&array[i]); if(array[i]%2==0) result-=(i+1); else result+=(i+1); } printf("data in array is"); for(i=0;i<10;i++) printf(" %d",array[i]); printf("\nresult is %d",result); getch(); return(1); } ----------------------------------------------------------------------------------------------------------------Ex 46.
ผมไมรูเรื่องเมตริกซ Ex 47. #include<stdio.h> #include int main() { int i,array[10]; for(i=0;i<10;i++) { scanf("%d",&array[i]); } printf("data in array is"); for(i=0;i<10;i++) printf(" %d",array[i]); printf("\nresult is"); for(i=1;i<9;i++) { if(array[i-1]%2==1&&array[i+1]%2==1) printf(" %d",array[i]); } getch(); return(1); } -----------------------------------------------------------------------------------------------------------------
Present by DrAlpha
Powered By God Jesus and Holy spirit
20 Ex 48. #include<stdio.h> #include #include<string.h> int main() { int i,j,n; char inp[128],temp[20]; scanf("%[^\n]",inp); for(i=0;i<strlen(inp);i++) { if((inp[i]>='a'&&inp[i]<='z') || (inp[i]>='A'&&inp[i]<='Z')) { for(j=0;j<20;j++) temp[j]=0; for(j=0;(inp[i+j]>='a'&&inp[i+j]<='z') || (inp[i+j]>='A'&&inp[i+j]<='Z');j++)
temp[j]=inp[i+j]; n=strlen(temp); for(j=0;j<(n/2)+(n%2);j++) { if(temp[j]!=temp[n-1-j]&&temp[j]!=temp[n-1-j]+32&&temp[j]+32!=temp[n-1-j])
j=n+2; } if(j!=n+3) { printf("%s ",temp); } i+=n; } } getch(); return(1); } -----------------------------------------------------------------------------------------------------------------
Present by DrAlpha
Powered By God Jesus and Holy spirit
21 Ex 49. #include<stdio.h> #include int main() { int array[10][10]={ {95,68,95,42,65,31,42,51,42,68}, {59,74,21,35,62,14,21,35,26,28}, {29,24,16,25,42,36,25,16,24,25}, {32,12,36,24,15,32,16,95,75,85}, {62,43,19,86,24,37,19,65,53,28}, {64,29,21,53,24,16,58,75,14,25}, {35,62,95,86,47,85,78,14,63,29}, {86,47,68,32,12,36,69,86,74,48}, {46,26,53,69,78,46,14,21,34,26}, {38,69,47,28,34,16,24,28,59,68}}; int i,j; printf("answer is"); for(i=1;i<9;i++) { for(j=1;j<9;j++) { if(array[i][j]<array[i+1][j] &&array[i][j]<array[i-1][j] && array[i][j]<array[i+1][j+1]&&array[i][j]<array[i-1][j+1]&& array[i][j]<array[i+1][j-1]&&array[i][j]<array[i-1][j-1] && array[i][j]<array[i][j+1] &&array[i][j]<array[i][j-1]) { printf(" (%d,%d)",j+1,i+1); } } } getch(); return(1); } -----------------------------------------------------------------------------------------------------------------
Present by DrAlpha
Powered By God Jesus and Holy spirit
22 Ex 50. #include<stdio.h> #include int main() { int array[10][10]={ {95,68,95,42,65,31,42,51,42,68}, {59,74,21,35,62,14,21,35,26,28}, {29,24,16,25,42,36,25,16,24,25}, {32,12,36,24,15,32,16,95,75,85}, {62,43,19,86,24,37,19,65,53,28}, {64,29,21,53,24,16,58,75,14,25}, {35,62,95,86,47,85,78,14,63,29}, {86,47,68,32,12,36,69,86,74,48}, {46,26,53,69,78,46,14,21,34,26}, {38,69,47,28,34,16,24,28,59,68}}; int i,j; printf("answer is"); for(i=1;i<9;i++) { for(j=1;j<9;j++) { if(array[i][j]>array[i+1][j]&&array[i][j]>array[i-1][j]&& array[i][j]>array[i+1][j+1]&&array[i][j]>array[i-1][j+1]&& array[i][j]>array[i+1][j-1]&&array[i][j]>array[i-1][j-1]&& array[i][j]>array[i][j+1]&&array[i][j]>array[i][j-1]) { printf(" (%d,%d)",j+1,i+1); } } } getch(); return(1); } -----------------------------------------------------------------------------------------------------------------
Present by DrAlpha
Powered By God Jesus and Holy spirit
23 Ex 51. #include<stdio.h> #include int main() { int array[10][10]={ {95,68,95,42,65,31,42,51,42,68}, {59,74,21,35,62,14,21,35,26,28}, {29,24,16,25,42,36,25,16,24,25}, {32,12,36,24,15,32,16,95,75,85}, {62,43,19,86,24,37,19,65,53,28}, {64,29,21,53,24,16,58,75,14,25}, {35,62,95,86,47,85,78,14,63,29}, {86,47,68,32,12,36,69,86,74,48}, {46,26,53,69,78,46,14,21,34,26}, {38,69,47,28,34,16,24,28,59,68}}; int i,j,n; printf("n is "); scanf("%d",&n); printf("answer is"); for(i=0;i<10;i++) { for(j=0;j<10;j++) { if(array[i][j]==n) { printf(" (%d,%d)",j+1,i+1); } } } getch(); return(1); } -----------------------------------------------------------------------------------------------------------------
Present by DrAlpha
Powered By God Jesus and Holy spirit
24 Ex 52. #include<stdio.h> #include int main() { int array[10][10]={ {95,68,95,42,65,31,42,51,42,68}, {59,74,21,35,62,14,21,35,26,28}, {29,24,16,25,42,36,25,16,24,25}, {32,12,36,24,15,32,16,95,75,85}, {62,43,19,86,24,37,19,65,53,28}, {64,29,21,53,24,16,58,75,14,25}, {35,62,95,86,47,85,78,14,63,29}, {86,47,68,32,12,36,69,86,74,48}, {46,26,53,69,78,46,14,21,34,26}, {38,69,47,28,34,16,24,28,59,68}}; int i,j,sumb[10],suml[10]; for(i=0;i<10;i++) { sumb[i]=0; suml[i]=0; for(j=0;j<10;j++) { sumb[i]+=array[j][i]; suml[i]+=array[i][j]; } printf("sum of bar %d is %d\n",i+1,sumb[i]); } for(i=0;i<10;i++) printf("sum of line %d is %d\n",i+1,suml[i]); getch(); return(1); } -----------------------------------------------------------------------------------------------------------------
Present by DrAlpha
Powered By God Jesus and Holy spirit
25 Ex 53. #include<stdio.h> #include int main() { int array[10][10]={ {95,68,95,42,65,31,42,51,42,68}, {59,74,21,35,62,14,21,35,26,28}, {29,24,16,25,42,36,25,16,24,25}, {32,12,36,24,15,32,16,95,75,85}, {62,43,19,86,24,37,19,65,53,28}, {64,29,21,53,24,16,58,75,14,25}, {35,62,95,86,47,85,78,14,63,29}, {86,47,68,32,12,36,69,86,74,48}, {46,26,53,69,78,46,14,21,34,26}, {38,69,47,28,34,16,24,28,59,68}}; int i,j,k,l,n; scanf("%d",&n); for(i=0;i<10;i++) { for(j=0;j<10;j++) { for(k=0;k<10;k++) { for(l=0;l<10;l++) { if(array[i][j]+array[k][l]==n) printf(" (%d,%d)(%d,%d) ",j+1,i+1,k+1,l+1); } } } } getch(); return(1); } -----------------------------------------------------------------------------------------------------------------
Present by DrAlpha
Powered By God Jesus and Holy spirit
26 Ex 54. #include<stdio.h> #include #include<string.h> int main() { char inp[128]; int i; scanf("%[^\n]",&inp); for(i=0;i<strlen(inp);i++) { if(inp[i]>='a'&&inp[i]<='z') inp[i]-=32; else if(inp[i]>='A'&&inp[i]<='Z') inp[i]+=32; } printf("%s",inp); getch(); return(1); } ----------------------------------------------------------------------------------------------------------------Ex 55. #include<stdio.h> #include int max(int n[],int a) { int max=0,i; for(i=0;i
Present by DrAlpha
Powered By God Jesus and Holy spirit
27 Ex 56. #include<stdio.h rel="nofollow"> #include int max(int n[],int a) { int max=0,i; for(i=0;i
Present by DrAlpha
Powered By God Jesus and Holy spirit
28 Ex 57. #include<stdio.h rel="nofollow"> #include int onlynum(int n) { int i; for(i=2;i<=n/2;i++) { if(n%i==0) i=n+3; } if(i==n+4) return(0); else return(1); } int main() { int n; scanf("%d",&n); if(onlynum(n)) printf("%d is only number"); else printf("%d is not only number"); getch(); return(1); } -----------------------------------------------------------------------------------------------------------------
Present by DrAlpha
Powered By God Jesus and Holy spirit
29 Ex 58. #include<stdio.h> #include int onlynum(int n) { int i; for(i=2;i<=n/2;i++) { if(n%i==0) i=n+3; } if(i==n+4||n==1) return(0); else return(1); } int main() { int n; do scanf("%d",&n); while(!onlynum(n)); getch(); return(1); } -----------------------------------------------------------------------------------------------------------------
Present by DrAlpha
Powered By God Jesus and Holy spirit
30 Ex 59. #include<stdio.h> #include long fac(int n) { int i; long ans=1; for(i=2;i<=n;i++) ans*=i; return(ans); } int main() { int n; scanf("%d",&n); printf("Fac of %d is %ld",n,fac(n)); getch(); return(1); } ----------------------------------------------------------------------------------------------------------------Ex 60. #include<stdio.h> #include int main() { int i,n; do { scanf("%d",&n); for(i=2;i<=n/2;i++) { if(n%i==0) i=n+3; } } while(i==n+4||n==1); getch(); return(1); } ----------------------------------------------------------------------------------------------------------------Ex 61.
เหมือนขอ 58
Present by DrAlpha
Powered By God Jesus and Holy spirit
31 Ex 62. #include<stdio.h> #include int main() { int n,sum=0; do { scanf("%d",&n); sum+=n; } while(n!=0); printf("Sum is %d",sum); getch(); return(1); } ----------------------------------------------------------------------------------------------------------------Ex 63.
เหมือนขอ 60 Ex 64. #include<stdio.h> #include #include<string.h> int main() { int s[5]={0,0,0,0,0},i; char inp[128]; scanf("%[^\n]",&inp); for(i=0;i<strlen(inp);i++) { if(inp[i]=='a'||inp[i]=='A') s[0]++; else if(inp[i]=='e'||inp[i]=='E') s[1]++; else if(inp[i]=='i'||inp[i]=='I') s[2]++; else if(inp[i]=='o'||inp[i]=='O') s[3]++; else if(inp[i]=='u'||inp[i]=='U') s[4]++; } printf("a is %d\n e is %d\n i is %d\n o is %d\n u is %d\n",s[0],s[1],s[2],s[3],s[4],s[5]); getch(); return(1); } -----------------------------------------------------------------------------------------------------------------
Present by DrAlpha
Powered By God Jesus and Holy spirit
32 Ex 65. #include<stdio.h> #include #include<string.h> int main() { int lcase=0,ucase=0,i; char inp[128]; scanf("%[^\n]",&inp); for(i=0;i<strlen(inp);i++) { if(inp[i]>='a'&&inp[i]<='z') lcase++; else if(inp[i]>='A'&&inp[i]<='Z') ucase++; } printf("Low case is %d\nUp case is %d",lcase,ucase); getch(); return(1); } -----------------------------------------------------------------------------------------------------------------
Present by DrAlpha
Powered By God Jesus and Holy spirit
33 Ex 66. #include<stdio.h> #include int main() { int num1,num2,s,m; scanf("%d",&num1); scanf("%d",&num2); if(num2>num1) s=1; else if(num2num1) m=1; else if(num2
Present by DrAlpha
Powered By God Jesus and Holy spirit
34 Ex 67. #include<stdio.h> #include int main() { int num[5],i,j,k; for(i=0;i<5;i++) scanf("%d",&num[i]); for(i=0;i<5;i++) { for(j=0;j<5;j++) { for(k=j;k<5;k++) { if(num[i]*num[i]==num[j]*num[j]+num[k]*num[k]) printf("%d,%d,%d ",num[i],num[j],num[k]); } } } getch(); return(1); } ----------------------------------------------------------------------------------------------------------------Ex 68. #include<stdio.h> #include int main() { int num[5],i,j,temp; for(i=0;i<5;i++) scanf("%d",&num[i]); for(i=0;i<4;i++) { for(j=i+1;j<5;j++) { if(num[i]>num[j]) { temp=num[i]; num[i]=num[j]; num[j]=temp; } } } printf("Max is %d\nMean is %d\nMin is %d\n",num[0],num[2],num[4]); getch(); return(1); } -----------------------------------------------------------------------------------------------------------------
Present by DrAlpha
Powered By God Jesus and Holy spirit
35 Ex 69. #include<stdio.h> #include int main() { int num1,num2,i,hrm; scanf("%d %d",&num1,&num2); for(i=1;i<=num1&&i<=num2;i++) { if(num1%i==0&&num2%i==0) hrm=i; } printf("hrm is %d",hrm); printf("\nkrn is %d",num1*num2/hrm); getch(); return(1); } ----------------------------------------------------------------------------------------------------------------Ex 70. #include<stdio.h> #include #include<string.h> int main() { char inp[128]; int engchar[26],i,j,max=0,mi;; scanf("%[^\n]",&inp); for(i=0;i<26;i++) { engchar[i]=0; for(j=0;j<strlen(inp);j++) { if(inp[j]=='a'+i||inp[j]=='A'+i) engchar[i]++; } if(engchar[i]>max) { max=engchar[i]; mi=i; } } printf("Max char is %c = %d",'a'+mi,max); getch(); return(1); } -----------------------------------------------------------------------------------------------------------------
Present by DrAlpha
Powered By God Jesus and Holy spirit
36 Ex 71. #include<stdio.h> #include #include<string.h> int main() { char inp[128]; int i,eni; scanf("%[^\n]",&inp); for(i=strlen(inp)-1;i>=0;i--) { if((inp[i]>='a'&&inp[i]<='z')||(inp[i]>='A'&&inp[i]<='Z')) { eni=i; i=-1; } } printf("end char is %c",inp[eni]); getch(); return(1); } ----------------------------------------------------------------------------------------------------------------Ex 72. #include<stdio.h> #include int main() { int i,j,n; scanf("%d",&n); for(i=2;i<=n;i++) { for(j=2;j<=(i/2)+(i%2);j++) { if(i%j==0) j=i+2; } if(j!=i+3) printf("%5d",i); } getch(); return(1); } -----------------------------------------------------------------------------------------------------------------
Present by DrAlpha
Powered By God Jesus and Holy spirit
37 Ex 73. #include<stdio.h> #include #include<string.h> int main() { int i; char inp[128]; scanf("%[^\n]",&inp); for(i=strlen(inp)-1;i>=0;i--) { printf("%c",inp[i]); } getch(); return(1); } ----------------------------------------------------------------------------------------------------------------Ex 74. #include<stdio.h> #include int main() { int n,i,oup[128]; for(i=0;i<128;i++) oup[i]=0; scanf("%d",&n); i=0; while(n>=2) { oup[i]=n%2; i++;n/=2; } oup[i]=1; for(;i>=0;i--) { printf("%d",oup[i]); } getch(); return(1); } -----------------------------------------------------------------------------------------------------------------
Present by DrAlpha
Powered By God Jesus and Holy spirit
38 Ex 75. #include<stdio.h> #include #include<string.h> int main() { int i,j,k,n=1; char inp[128],temp; scanf("%[^\n]",inp); for(i=0;i<strlen(inp);i++) { if(inp[i]!=' ') { for(j=0;inp[i+j]!=' '&&i+j<strlen(inp);j++); if(n%2==1) { for(k=0;k<j/2+j%2;k++) { temp=inp[i+k]; inp[i+k]=inp[i+j-k-1]; inp[i+j-k-1]=temp; } } i+=j; n++; } } printf("%s",inp); getch(); return(1); } -----------------------------------------------------------------------------------------------------------------
Present by DrAlpha
Powered By God Jesus and Holy spirit
39 Ex 76. #include<stdio.h> #include int main() { int i,j,n[10]; for(i=0;i<10;i++) scanf("%d",&n[i]); for(i=0;i<=10;i++) { for(j=2;j<=(n[i]/2)+(n[i]%2);j++) { if(n[i]%j==0) j=n[i]+2; } if(j!=n[i]+3) printf("%5d",n[i]); } getch(); return(1); } ----------------------------------------------------------------------------------------------------------------Ex 77. #include<stdio.h> #include int main() { FILE *fo,*fp; char fad[2][30],temp; scanf("%s",&fad[0]); fo=fopen(fad[0],"rt"); scanf("%s",&fad[1]); fp=fopen(fad[1],"wt"); while(!feof(fo)) { fscanf(fo,"%c",&temp); fprintf(fp,"%c",temp); } fclose(fo); fclose(fp); getch(); return(1); } -----------------------------------------------------------------------------------------------------------------
Present by DrAlpha
Powered By God Jesus and Holy spirit
40 Ex 78. #include<stdio.h> #include #include<math.h> int main() { int num[10],i; float xbar=0,xsum=0; for(i=0;i<10;i++) { scanf("%d",&num[i]); xbar+=num[i]; } xbar/=10; for(i=0;i<10;i++) xsum+=(num[i]-xbar)*(num[i]-xbar); printf("%f",sqrt(xsum/9)); getch(); return(1); } ----------------------------------------------------------------------------------------------------------------Ex 79. #include<stdio.h> #include #include<string.h> int main() { int i,j; char inp[25]; scanf("%[^\n]",&inp); for(i=0;i<strlen(inp);i++) { for(j=0;j<strlen(inp)-i;j++) printf("%c",inp[j]); printf("\n"); } getch(); return(1); } -----------------------------------------------------------------------------------------------------------------
Present by DrAlpha
Powered By God Jesus and Holy spirit
41 Ex 80. #include<stdio.h> #include int main() { FILE *fp; char temp[128]; fp=fopen("d:\\temp\\data.txt","wt"); do { scanf("%s",&temp); fprintf(fp,"%s\n",temp); }while(strcmp(temp,".")); fclose(fp); getch(); return(1); } -----------------------------------------------------------------------------------------------------------------
To The End Of The Earth Present by DrAlpha
Powered By God Jesus and Holy spirit