《C语言趣味程序百例》由会员分享,可在线阅读,更多相关《C语言趣味程序百例(14页珍藏版)》请在金锄头文库上搜索。
1、C 语言趣味程序百例语言趣味程序百例(1):绘制余弦曲线绘制余弦曲线public class test1public static void main(String args)double y; double x, m; for (y=1;y-1;y-=0.1) m= Math.acos(y) * 10; for (x = 1; x =-10;y-)m=2*Math.sqrt(100-y*y);for(x=1;x max) max=x;if(x99;i-) if (555555%i=0) System.out.println(“最大约数=“+i); return; C 语言趣味程序百例语言趣味
2、程序百例(12):抓交通肇事犯抓交通肇事犯public class test12public static void main(String args)int k;for(int i=1;i= 1 System.out.println(“a=“+a); System.out.println(“b=“+b); System.out.println(“c=“+c); System.out.println(“d=“+d); System.out.println(“e=“+e); System.out.println(“f=“+f); C 语言趣味程序百例语言趣味程序百例(10):数制转换数制转换im
3、port java.io.*; public class test10 public static void main(String args) throws IOException BufferedReader br = new BufferedReader(new InputStreamReader(System.in); System.out.println(“input int:“); String s=br.readLine(); int val=Integer.parseInt(s); System.out.println(getBits(val); public static S
4、tring getBits(int value) int displayMask=131; StringBuffer buf=new StringBuffer(35); for(int c=1;c=32;c+) buf.append(value value=1; if(c%8=0) buf.append( ); return buf.toString(); C 语言趣味程序百例语言趣味程序百例(9):杨辉三角形杨辉三角形public class test9public static void main(String args)int n=Integer.parseInt(args0);Syst
5、em.out.println(“N=“+n);for(int i=0;i=n;i+)for(int j=0;j 12-i;j+) System.out.printf(“ “);for(int j=1;j i+2;j+) System.out.printf(“%6d“,c(i,j);System.out.println();public static int c(int x,int y)int z;if(y=1)|(y=x+1) return 1;z=c(x-1,y-1)+c(x-1,y);return z;C 语言趣味程序百例语言趣味程序百例(79):随机数求圆周率随机数求圆周率public class test79public static void main(String args) double all=10000000; double l=1000000; double pai=0; double in=0; double x=0,y=0; for (int i=0;iall;i+) x=(Math.random()*l); y=(Math.random()*l); if(x*x+y*yl*l) in+; pai=(in/all*4); System.out.println(“Times/All=“+in+“/“+all+“ “+“=“+pai);