#include<stdio.h>
#include<math.h>
int main()
{int m,i,k,h=0,leap=1;for(m=101;m<=200;m++){k=sqrt(m+1);for(i=2;i<=k;i++)if(m%i==0){leap=0;break;}if(leap){printf("%-4d",m);h++;if(h%10==0)printf("\n");}leap=1;}printf("\nThe total is %d",h);return 0;
}
#include<stdio.h>
int main()
{int n,i;printf("\nplease input a number:\n");scanf("%d",&n);printf("%d=",n);for(i=2;i<=n;i++)while(n!=i){if(n%i==0){printf("%d*",i);n=n/i;}elsebreak;}printf("%d",n);return 0;
}
#include<stdio.h>
int main()
{int score;char grade;printf("please input a score\n");scanf("%d",&score);grade=score>=90?'A':(score>=60?'B':'C');printf("%d belongs to %c",score,grade);return 0;
}
#include<stdio.h>
int main()
{int a,n,count=1;long int sn=0,tn=0;printf("please input a and n\n");scanf("%d %d",&a,&n);printf("a=%d,n=%d\n",a,n);while(count<=n){tn=tn+a;sn=sn+tn;a=a*10;++count;}printf("a+aa+...=%ld\n",sn);return 0;
}
#include<stdio.h>
int main()
{static int k[10];int i,j,n,s;for(j=2;j<1000;j++){n=-1;s=j;for(i=1;i<j;i++){if((j%i)==0){n++;s=s-i;k[n]=i;}}if(s==0){printf("%d is a wanshu",j);for(i=0;i<n;i++)printf("%d,",k[i]);printf("%d\n",k[n]);}}return 0;
}
#include<stdio.h>
int main()
{float sn=100.0,hn=sn/2;int n;for(n=2;n<=10;n++){sn=sn+2*hn;/*第n次落地時共經過的米數*/hn=hn/2; /*第n次反跳高度*/}printf("the total of road is %f\n",sn);printf("the tenth is %f meter\n",hn);return 0;
}
#include<stdio.h>
int main()
{int day,x1,x2;day=9;x2=1;while(day>0){x1=(x2+1)*2;/*第一天的桃子數是第2天桃子數加1后的2倍*/x2=x1;day--;}printf("the total is %d\n",x1);return 0;
}
#include<stdio.h>
int main()
{char i,j,k;/*i是a的對手,j是b的對手,k是c的對手*/for(i='x';i<='z';i++)for(j='x';j<='z';j++){if(i!=j)for(k='x';k<='z';k++){if(i!=k&&j!=k){if(i!='x'&&k!='x'&&k!='z')printf("order is a--%c\tb--%c\tc--%c\n",i,j,k);}}}return 0;
}
#include<stdio.h>
int main()
{int n,t,number=20;float a=2,b=1,s=0;for(n=1;n<=number;n++){s=s+a/b;t=a;a=a+b;b=t;/*這部分是程序的關鍵,請讀者猜猜t的作用*/}printf("sum is %9.6f\n",s);return 0;
}
#include<stdio.h>
int main()
{long a,b,c,d,e,x;scanf("%ld",&x);a=x/10000;/*分解出萬位*/b=x%10000/1000;/*分解出千位*/c=x%1000/100;/*分解出百位*/d=x%100/10;/*分解出十位*/e=x%10;/*分解出個位*/if (a!=0) printf("there are 5, %ld %ld %ld %ld %ld\n",e,d,c,b,a);else if (b!=0) printf("there are 4, %ld %ld %ld %ld\n",e,d,c,b);else if (c!=0) printf(" there are 3,%ld %ld %ld\n",e,d,c);else if (d!=0) printf("there are 2, %ld %ld\n",e,d);else if (e!=0) printf(" there are 1,%ld\n",e);return 0;
}
#include<stdio.h>
int main()
{long ge,shi,qian,wan,x;scanf("%ld",&x);wan=x/10000;qian=x%10000/1000;shi=x%100/10;ge=x%10;if(ge==wan&&shi==qian)/*個位等于萬位并且十位等于千位*/printf("this number is a huiwen\n");elseprintf("this number is not a huiwen\n");return 0;
}
#include<stdio.h>
int main()
{char letter;printf("please input the first letter of someday\n");while((letter=getchar())!='Y')/*當所按字母為Y時才結束*/{switch (letter){case 'S':printf("please input second letter\n");if((letter=getchar())=='a')printf("saturday\n");else if ((letter=getchar())=='u')printf("sunday\n");elseprintf("data error\n");break;case 'F':printf("friday\n");break;case 'M':printf("monday\n");break;case 'T':printf("please input second letter\n");if((letter=getchar())=='u')printf("tuesday\n");else if ((letter=getchar())=='h')printf("thursday\n");elseprintf("data error\n");break;case 'W':printf("wednesday\n");break;default: printf("data error\n");}}return 0;
}
============================================================== 【程序32】 題目:Press any key to change color, do you want to try it. Please hurry up! 1.程序分析: 2.程序源代碼: 代碼如下:
#include "conio.h"
#include "stdio.h"
void main(void)
{int color;for (color = 0; color < 8; color++){textbackground(color);/*設置文本的背景顏色*/cprintf("This is color %d\r\n", color);cprintf("Press any key to continue\r\n");getch();/*輸入字符看不見*/}
}
#include "stdio.h"
#include "conio.h"
main()
{int i,num;num=2;for(i=0;i<3;i++){printf("\40: The num equal %d \n",num);num++;{auto int num=1;printf("\40: The internal block num equal %d \n",num);num++;}}getch();
}
#include "stdio.h"
#include "conio.h"
main()
{int i,num;num=2;for(i=0;i<3;i++){printf("\40: The num equal %d \n",num);num++;{static int num=1;printf("\40:The internal block num equal %d\n",num);num++;}}getch();
}
#include "stdio.h"
#include "conio.h"
int a,b,c;
void add()
{int a;a=3;c=a+b;
}
void main()
{a=b=4;add();printf("The value of c is equal to %d\n",c);getch();
}
#include "stdio.h"
#include "conio.h"
#define TRUE 1
#define FALSE 0
#define SQ(x) (x)*(x)
void main()
{int num;int again=1;printf("\40: Program will stop if input value less than 50.\n");while(again){printf("\40:Please input number==>");scanf("%d",&num);printf("\40:The square for this number is %d \n",SQ(num));if(num>=50)again=TRUE;elseagain=FALSE;}getch();
}
#define LAG >
#define SMA <
#define EQ ==
#include "stdio.h"
#include "conio.h"
void main()
{int i=10;int j=20;if(i LAG j)printf("\40: %d larger than %d \n",i,j);else if(i EQ j)printf("\40: %d equal to %d \n",i,j);else if(i SMA j)printf("\40:%d smaller than %d \n",i,j);elseprintf("\40: No such value.\n");getch();}
#include "stdio.h"#include "conio.h"#define MAX#define MAXIMUM(x,y) (x>y)?x:y#define MINIMUM(x,y) (x>y)?y:xvoid main(){int a=10,b=20;#ifdef MAXprintf("\40: The larger one is %d\n",MAXIMUM(a,b));#elseprintf("\40: The lower one is %d\n",MINIMUM(a,b));#endif#ifndef MINprintf("\40: The lower one is %d\n",MINIMUM(a,b));#elseprintf("\40: The larger one is %d\n",MAXIMUM(a,b));#endif#undef MAX#ifdef MAXprintf("\40: The larger one is %d\n",MAXIMUM(a,b));#elseprintf("\40: The lower one is %d\n",MINIMUM(a,b));#endif#define MIN#ifndef MINprintf("\40: The lower one is %d\n",MINIMUM(a,b));#elseprintf("\40: The larger one is %d\n",MAXIMUM(a,b));#endifgetch();}