C程序设计-清览题库

简介: C程序设计-清览题库 | yujing.fit

清览题库


官方地址


题号:20241

#include <stdio.h>
  
  int main()
{
  double areaT(double r,double h);//对areaT函数进行声明 
  double r,h,v;
  printf("请输入半径和高:"); 
  scanf("%lf%lf",&r,&h);//输入double类型数据,必须使用%lf,不可以%f 
  v=areaT(r,h);
  printf("r=%f\n",r);
  printf("h=%f\n",h);
  printf("v=%.2f\n",v);//输出结果保留两位小数 
  return 0;
}
 double areaT(double r,double h)
{
  double z;
  z=h*3.14*r*r/3;
  return(z);//返回结果语法 
}  

20242

#include <stdio.h> 
int main()
{
  double areaT(double a,double b,double h);
  double a,b,h,s;
  scanf("%lf%lf%lf",&a,&b,&h);//带上取地址符&!!!!!!
  s=areaT(a,b,h);//后面有分号
  printf("%.2f",s);
  return 0;
}
double areaT(double a,double b,double h)
{
  double z;
  z=(a+b)*h/2;
  return(z);
}

20251----待修改

#include <stdio.h>
int main()
{
  int arr[3],i,j;
  for(i=0;i<=2;i++)
   scanf("%d",&arr[i]);
  for(i=0;i<2;i++)
  {
    for(j=0;j<2-i;j++){
     if(arr[i]>arr[i+1])
    {
      int t;
      t=arr[i+1];
      arr[i+1]=arr[i];
      arr[i]=t;
    } 
    }
    
  }
  for(i=0;i<=2;i++)
   printf("%d\t",arr[i]);
  return 0;
}

答案

#include <stdio.h>
int main()
{
  void  swap( int *p1, int *p2 );
  int n1, n2, n3;
  int *p1, *p2, *p3;
  scanf( "%d %d %d", &n1, &n2, &n3 );
  p1  = &n1;
  p2  = &n2;
  p3  = &n3;
  if ( n1 > n2 )
    swap( p1, p2 );
  if ( n1 > n3 )
    swap( p1, p3 );
  if ( n2 > n3 )
    swap( p2, p3 );
  printf( "%d %d %d\n", n1, n2, n3 );
  return(0);
}
void swap( int *p1, int *p2 )
{
  int p;
  p = *p1;
  *p1 = *p2;
  *p2 = p;
}

20229

#include <stdio.h>
int main()
{
  double sum(double a,double b);
  double a,b,s;
  scanf("%lf%lf",&a,&b);
  s=sum(a,b);
  printf("%.2f",s);
  return 0;
  
 } 
 double sum(double a,double b)
 {
  double z;
  z=a+b;
  return(z);
 } 

20133

#include <stdio.h>
int main()
{
  int x;
  for(x=0;x<3000;x++)
  if(x%5==1&&x%6==5&&x%7==4&&x%11==10){
    printf("%d",x);
  }
  return 0;
}

20275

#include <stdio.h>
int main()
{
    void nav(int *q1,int *q2);
    int a,b,*p1,*p2;
    printf("请输入a和b:");
    scanf("%d%d",&a,&b);
    p1=&a;
    p2=&b;
    nav(p1,p2);
    printf("max=%d,min=%d",*p1,*p2);
    return 0;
}
void nav(int *q1,int *q2)
{
    if(*q1<*q2)
    {
        int temp;
        temp=*q1;
        *q1=*q2;
        *q2=temp;
    }
}

20276

方法一

#include <stdio.h>
int a, b, c;
int main()
{
    void nav(int q1, int q2, int q3);
    scanf("%d%d%d", &a, &b, &c);
    nav(a, b, c);
    printf("%d %d %d", a, b, c);
    return 0;
}
void nav(int q1, int q2, int q3)
{
    void rev(int x, int y);
    if (q1 < q2)
    {
        int temp;
        temp = a;
        a = b;
        b = temp;
    }
    if (q1 < q3)
    {
        int temp;
        temp = a;
        a = c;
        c = temp;
    }
    if (q2 < q3)
    {
        int temp;
        temp = c;
        c = b;
        b = temp;
    }
}

方法二

#include <stdio.h>
int main()
{
    void exchange(int *q1,int *q2,int *q3);
    int a,b,c,*p1,*p2,*p3;
    printf("请输入a,b,c的值:");
    scanf("%d%d%d",&a,&b,&c);
    p1=&a;
    p2=&b;
    p3=&c;
    exchange(p1,p2,p3);
    printf("由小到大的排序为%d,%d,%d",a,b,c);
    printf("%d,%d,%d",*p1,*p2,*p3);//指针指向并没有改变,改变的为a,b,c的值
    return 0;
}
void exchange(int *q1,int *q2,int *q3)//排序
{
    void swap(int *j1,int *j2);
    if (*q1>*q2)//不可使用if……else if……else if……只执行一个语句
    {
        /* code */
        swap(q1,q2);
    }
    if (*q1>*q3)
    {
        /* code */
        swap(q1,q3);
    }
    if (*q2>*q3)
    {
        /* code */
        swap(q2,q3);
    }
}
void swap(int *j1,int *j2)//交换值
{
    int temp;
    temp=*j1;
    *j1=*j2;
    *j2=temp;
}

20277

#include <stdio.h>
int main()
{
    void exchange(int *p, int *q);
    int a[10], n = 10, *p;
    for (int i = 0; i < 10; i++)
    {
        /* code */
        scanf("%d", &a[i]);
    }
    p = a;
    for (int i = 0; i < n / 2; i++)
    {
        exchange((p+i), (p+9-i));
    }
    for (int i = 0; i < 10; i++)
    {
        printf("%d ", a[i]);
    }
    return 0;
}
void exchange(int *p, int *q) //排序
{  
        /* code */
        int temp;
        temp = *p;
        *p=*q;
        *q=temp;
}

20308

#include <stdio.h>
//声明一个名字为Student的数据类型
// your code
#define M 5
int main()
{
    //your code begin
    struct Student
    {
        int num;
        char *name;
        float score;
    } stu[M] = {{10101, "Zhang", 78}, {10103, "Wang", 98.5}, {10106, "Li", 86}, {10108, "Ling", 73.5}, {10110, "Fun", 100}};
    for (int j = 0; j < M; j++)
    {
        for (int i = 0; i < M - j; i++)
        {
            if (stu[i].score < stu[i + 1].score)
            {
                int num1;
                char *name1;
                float score1;
                num1 = stu[i].num;
                stu[i].num = stu[i + 1].num;
                stu[i + 1].num = num1;
                name1 = stu[i].name;
                stu[i].name = stu[i + 1].name;
                stu[i + 1].name = name1;
                score1 = stu[i].score;
                stu[i].score = stu[i + 1].score;
                stu[i + 1].score = score1;
            }
        }
    }
    for (int i = 0; i < M; i++)
    {
        /* code */
        printf("%d %s %.2f\n", stu[i].num, stu[i].name, stu[i].score);
    }
    //your code end
    return 0;
}
#include <stdio.h>
//声明一个名字为Student的数据类型
// your code
#define M 5
int main()
{
    //your code begin
    struct Student
    {
        int num;
        char *name;
        float score;
    } stu[M] = {{10101, "Zhang", 78}, {10103, "Wang", 98.5}, {10106, "Li", 86}, {10108, "Ling", 73.5}, {10110, "Fun", 100}};
    for (int j = 0; j < M; j++)
    {
        for (int i = 0; i < M - j; i++)
        {
            if (stu[i].score < stu[i + 1].score)
            {
                struct Student temp;
                temp=stu[i];
                stu[i]=stu[i+1];
                stu[i+1]=temp;
            }
        }
    }
    for (int i = 0; i < M; i++)
    {
        /* code */
        printf("%d %s %.2f\n", stu[i].num, stu[i].name, stu[i].score);
    }
    //your code end
    return 0;
}

20309

#include <stdio.h>
int main()
{
    struct student
    {
        int num;
        char* name;
        char sex;
        int age;
    }stu[]={{10101,"Li Lin",'M',18},{10102,"Zhang Fun",'M',19},{10104,"Wang Min",'F',20}};
    printf("No.Name sex age ");
    for (int i = 0; i < 3; i++)
    {
        printf("%d %s %c %d",stu[i].num,stu[i].name,stu[i].sex,stu[i].age);
    }  
}
#include <stdio.h>
struct student {
  int num;
  char name[20];
  char sex;
  int age;
};
struct student stu[3]= {{10101,"Li Lin",'M',18},{10102,"Zhang Fun",'M',19},{10104,"Wang Min",'F',20}};
int main() {
  struct student *p;
  printf("No. Name sex age\n");
  for (p=stu; p<stu+3;p++)
    printf("%d %s %c %d\n",p->num, p->name, p->sex, p->age);
  return 0;
}

问题


无法输出

#include <stdio.h>
struct student {
  int num;
  char* name;
  char sex;
  char* address;
}stu;
int main() {
    printf("xuehao1:");
    scanf("%d%s%c%s",&stu.num,&stu.name,&stu.sex,&stu.address);
    printf("%d %s %c %s",stu.num,stu.name,stu.sex,stu.address);
  return 0;
}

能正确输出,两次回车键

#include <stdio.h>
struct student {
  int num;
  char name[20];
    char sex;
}stu;
int main() {
    printf("开始输入:");
    scanf("%d",&stu.num);
    gets(stu.name);
    stu.sex=getchar();
    printf("输出%d %s %c",stu.num,stu.name,stu.sex);
  return 0;
}
相关文章
|
3天前
计算机基础100题含答案
计算机基础100题含答案
|
10月前
|
芯片
大学计算机基础-题库刷题-精选(二)
大学计算机基础-题库刷题-精选(二)
53 0
|
10月前
|
存储 编解码 关系型数据库
大学计算机基础-题库刷题-精选(一)
大学计算机基础-题库刷题-精选(一)
157 0
高等数学常见面试问题总结,含答案
高等数学常见面试问题总结,含答案
|
8月前
|
算法
离散数学常见面试问题总结,含答案
离散数学常见面试问题总结,含答案
|
10月前
|
缓存 网络协议 网络架构
大学计算机基础-题库刷题-精选(三)
大学计算机基础-题库刷题-精选(三)
108 0
|
10月前
大学计算机基础-题库刷题-精选(四)
大学计算机基础-题库刷题-精选(四)
63 0
|
存储 编解码 安全
题库——“计算机基础”
题库——“计算机基础”
|
机器学习/深度学习 人工智能 移动开发
c语言期末突击讲义+笔记
一、 固定格式 例 1: #include<stdio.h> int main() { return 0; }
194 0
|
C语言 数据安全/隐私保护
西安石油大学C语言期末真题实战
前3题就是一些基础定义,在此不多赘述 要注意不同的数据类型的字节数不同 a<<2 b>>1(b>>1;就是说b自身右位移一位(参考位运算) “>>”位移运算,就是把b转换为二进制数,整体向右移一位,高位补零,最低位消失,通常右移一位就等价于b除以2再赋给b) 连接两个字符串用的函数是Strcat
106 0