挑选几个喜欢的程序以备日后回顾
#include
int main(void){
int i=0;
float max=0,number=0;
for(;i<6;i++){
printf("enter a numebr :");
scanf("%f",&number);
if(number>max){
max=number;
}
}
printf("the largest number entered is %.2f" ,max);
return 0;
}
#include
int main(void){
int m=0,n=0,num=0,temp=0;
printf("enter two integers : ");
scanf("%d %d",&m,&n);
if(m==0 || n==0){
printf("please enter valid integer");
return 0;
}
if(m<n){
temp=n;
n=m;
m=temp;
}
if(m%n==0){
printf("greatest common divisor :%d", n);
return 0;
}
while(m%n!=0){
num=m%n;
m=n;
}
printf("greatest common divisor : %d",num);
return 0;
}
#include
int main (void)
{
int m=0,n=0,num=0;
printf("enter two integers: ");
scanf("%d %d",&m,&n);
while(n!=0){
num=n;
n=m%n;
m=num;
}
printf("Greatest common divisor: %d", m);
return 0;
}
#include
int main(void){
int m=0,n=0,temp=0;
int numerator=0,denominator=0;
printf ("enter a fraction : ");
scanf ("%d/%d",&m,&n);
if(n==0){
printf("illegal fraction");
return 0;
}
numerator=m;
denominator=n;
while(n!=0){
temp=n;
n=m%n;
m=temp;
}
numerator=numerator/m;
denominator=denominator/m;
printf("in lowest terms : %d/%d",numerator,denominator);
return 0;
}
#include
int main(void){
int number=0,i=0;
printf("please enter an integer as you like");
scanf("%d",&number);
do {
number=number/10;
i++;
}while(number!=0);
printf("this is a %d digit number",i);
return 0;
}
#include
int main(void){
int n=0,i=0;
printf("enter a number n");
scanf("%d" ,&n);
printf("look at this \n");
for(i=2;i<=n;i=i+2){
printf("%d\n" ,i*i);
}
return 0;
}
#include
int main(void){
int day=0,week=0,i=0,day_start=0,days=0;
printf("enter number of days in month : ");
scanf("%d",&days);
printf("enter starting days of the week \
like this (1=Mon,7=Sun)");
scanf("%d",&day_start);
printf("\t一\t二\t三\t四\t五\t六\t日\n");
for(i=1;i<day_start;i++){
printf("\t");
}
for(day=1,week=day_start-1;day<=days;day++,week++){
if(week%7==0){
printf("\n");
}
printf("\t%2d",day);
}
return 0;
}
#include
int main(void){
int yy=99,mm=99,dd=99,yy_old=99,mm_old=99,dd_old=99,\
yy_new=99,mm_new=99,dd_new=99;
printf("if you want to exit please enter 0/0/0\n");
do{
printf("enter a data :");
scanf("%d/%d/%d",&yy,&mm,&dd);
yy_old=yy;
mm_old=mm;
dd_old=dd;
if(yy_old==0 && mm_old==0 && dd_old==0){
printf("the earliest date is %2d/%2d/%2d"\
,yy_new,mm_new,dd_new);
return 0;
}
if(yy<yy_new){
yy_new=yy;
mm_new=mm;
dd_new=dd;
}
if(yy==yy_new){
if(mm<mm_new){
yy_new=yy;
mm_new=mm;
dd_new=dd;
}
if(mm==mm_new){
if(dd<dd_new){
yy_new=yy;
mm_new=mm;
dd_new=dd;
}
}
}
}while(1);
return 0;
}