C语言程序设计,实验报告程序

1.

判断输入字符种类
#include 
#include 

int main()
{
    char c;
    printf("plz enter character:\n ");
    c=getchar();
    if(c<32){
    printf("\n the charater is a control charater");
    }else if(c>='0'&&c<='9'){
    printf("\n the charater is a digit");
    }else if(c>='A'&&c<='Z'){
    printf("\n the charater is a capital letter");
    }else if(c>='a'&&c<='z'){
    printf("\n the charater is a lower letter");
    }else {
    printf("the charater is other charater");
    }

}


2.
输入三个数,从小到大排序
#include 
#include 

int main()
{
float a,b,c,d;
printf("\n plz enter three number:");
scanf("\n%f %f %f",&a,&b,&c);
if(a>b){
d=a; a=b; b=d;
}
if(a>c){
d=a; a=c; c=d;
}
if(b>c){
d=b; b=c; c=d;
}
printf("\n %5.1f,%5.1f,%5.1f\n",a,b,c);
    return 0;
}


3.
判断一年是否是闰年
#include 
#include 

int main()
{
   int year,leap;
   printf("\n enter your year:");
   scanf("\n%d",&year);
   if((year%4==0&&year%100!=0)||(year%400==0)){
   leap=1;
   }else{
   leap=0;
   }
   if(leap)
   {
   printf("\n%d is a leap year",year);
   }else{
   printf("\n%d is not a leap year",year);
   }


    return 0;
}


4.
输入两个数,判断是否相等
#include 
#include 

int main()
{

  int a,b;
  printf("\n plz enter two numbles");
  scanf("\n%d %d",&a,&b);
  if(a==b){
  printf("\n a=b");
  }else{
  printf("\n a!=b");
  }
}


5.
二元一次方程求根
#include 
#include 
#include

int main()
{
   float a,b,c,disc,x1,x2,p,q;
   printf("plz enter a b c");
   scanf("%f %f %f",&a,&b,&c);
   disc=b*b-4*a*c;

   if(disc>0){
   p=-b/(2*a);q=sqrt(disc)/(2*a);
   x1=p+q;
   x2=p-q;
   printf("\n\nx1=%5.2f\nx2=%5.2f\n",x1,x2);
   }
   else{
   printf("\n\nmei you shigen\n\n");
   }
}


6.
字符大小写转换
#include 
#include 

int main()
{
char ch;
printf("plz enter a charater\n");
scanf("%c",&ch);
ch=(ch>='A'&&ch<='Z')?(ch+32):(ch-32);
printf("%c",ch);

    return 0;
}


7.
根据输入的字符输出相应的语句(switch-case练习!)
#include 
#include 

int main()
{int c;
printf("plz enter charater:\n");
c=getchar();
switch(c){
case 'm':
printf("good morning!\n");
break;
case 'n':
printf("good night\n");
break;
case 'o':
printf("other\n");
break;
default:
printf("???\n");
break;
}
    return 0;
}

8.
要求按照考试成绩的等级输出百分制分数段,A等为85分以上,B等为70~84分,C等为60~69分 ,D等为 60分以下 。成绩的等级由键盘输入
#include 
int main()
{ char grade;
   scanf("%c",&grade);
   printf("Your score:");
   switch(grade)
  { case 'A': printf("85~100\n");break;
     case 'B': printf("70~84\n");break;
     case 'C': printf("60~69\n");break;
     case 'D': printf("<60\n");break;    
	  default:  printf("enter data error!\n");
   }
   return 0;
 }

9.
编程实现:输入一个整数,判断它能否被3、5、7整除,并输出以下信息之一: 
能同时被3、5、7整除; 
能被其中两数(要指出哪两个)整除;
能被其中一个数(要指出哪一个)个整除;
不能被3、5、7任一个整除。

#include 
#include 

int main()
{
int a;
printf("plz input a number:\n");
scanf("%d",&a);
if(a%3==0&&a%5==0&&a%7==0){
printf("%d neng bei 3,5,7zhengchu!\n",a);
}
else if(a%3==0&&a%5==0){
printf("%d nengbei 3,5 zhengchu\n",a);
}
else if(a%3==0&&a%7==0){
printf("%d nengbei 3,7 zhengchu\n",a);
}
else if(a%7==0&&a%5==0){
printf("%d nengbei 7,5 zhengchu\n",a);
}
else if(a%3==0){
printf("%d nengbei 3, zhengchu\n",a);
}
else if(a%5==0){
printf("%d nengbei 5, zhengchu\n",a);
}
else if(a%7==0){
printf("%d nengbei 7, zhengchu\n",a);
}

    return 0;
}


你可能感兴趣的:(学习)