ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

C语言课程训练系统题-重庆邮电大学

2020-12-26 16:02:15  阅读:614  来源: 互联网

标签:main scanf 邮电大学 C语言 课程 printf input include c2


C语言课程训练系统题-基础习题

1.爱因斯坦

#include <stdio.h>
main()
{
	int  x,find=1;
	x=0;
    do{
        x++;
       if(x%2==1&&x%3==2&&x%5==4&&x%6==5&&x%7==0)find=0; 
    }while (find);  
    printf("x=%d\n",x);
}

在这里插入图片描述

2.输出两数最大值

#include<stdio.h>
main()
{
	int a,b,max;
	printf("Input a, b:");
	scanf("%d,%d",&a,&b);
	if (a>b) max = a;
	if (a<=b) max = b;
	printf("max = %d\n",max);
}

在这里插入图片描述

3.输出两数商

#include <stdio.h>
main()
{
    int a,b;
	double c;
	printf("Input two integers:");
    scanf("%d%d",&a,&b);
    c = a/b;
    printf("The quotient of a and b is :%.f",c);
}

在这里插入图片描述

4.12a4.2

#include <stdio.h>
main()
{
    int i;
    char ch;
    float f;
    printf("Please input:\n");
    scanf("%d%c%f",&i,&ch,&f);
    printf("The input integer is : %-3d\nThe input character is : %c\n",i,ch);
    printf("The input float is : %f",f);
}

在这里插入图片描述

5判断3个数是否相等

#include <stdio.h>
 main()
{
    int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
    if (a==b&&a==c)
        printf("The three number is equal!!!");
    else
        printf("The three number isn't equal!!!");
}

在这里插入图片描述

6输入一个数,逆序输出这个数

#include<stdio.h>
main()
{
	int x,a,b,c,d,y;
	printf("Input x:");
	scanf("%d",&x);
	if(x<0)
		d=(-x);
	else
		d=x;
	a=d/100;
	b=(d-a*100)/10;
	c=d%10;
	y=a+b*10+c*100;
	printf("y = %d\n",y);
}

在这里插入图片描述

7求三角形面积

#include<stdio.h>
#include<math.h>
main()
{
	float a,b,c,s,area;
	printf("Enter 3 floats");
	scanf("%f,%f,%f",&a,&b,&c);
	s=(a+b+c)/2;
	area=(float)sqrt(s*(s-a)*(s-b)*(s-c));
	printf("area=%.2f\n",area);
}

在这里插入图片描述

8四则运算

#include<stdio.h>
#include<math.h>
main()
{
	float a,b;
	char op;
	printf("Please enter the expression:\n");
	scanf("%f %c%f",&a,&op,&b);
	switch(op)
	{
	case'+':printf("%f + %f = %f \n",a,b,a+b);break;
	case'-':printf("%f - %f = %f \n",a,b,a-b);break;
	case'*':printf("%f * %f = %f \n",a,b,a*b);break;
	case'^':printf("%f ^ %f = %f \n",a,b,pow(a,b));break;
	case'/':if(b==0)
					printf("Division by zero!\n");
		else
			printf("%f / %f = %f \n",a,b,a/b);break;
	default:printf("Invalid operator! \n");
	}
}

在这里插入图片描述

9求2/1,3/2,5/3,8/5,13/8,21/13,…前20项之和

#include <stdio.h>
main()
{
    double i, s1 = 2, s2 = 1;
    float x, sum = 0;
	for (i = 1; i <= 20; i++)
    {
        sum +=( s1 / s2);
        x = s1;
        s1 += s2;
        s2 = x;
    }
    printf("sum = %f\n", sum);
}

在这里插入图片描述

10小写转大写

#include<stdio.h>
main()
{

	char c1,c2;
	c1=getchar();
	c2=c1-32;
	printf("%c,%d\n",c2,c2);
}

在这里插入图片描述

11大写转小写

#include<stdio.h>
main()
{
	char c1,c2;printf("Press a key and then press Enter:");
	c1=getchar();
	c2=c1+32;
	printf("%c\n",c2);
}

在这里插入图片描述

12输入两数求商

#include <stdio.h>
main()
{
    int a,b,c;
	printf("Enter two numbers");
	scanf("%d%d",&a,&b);
	if(b==0)
		printf("cannot divide by zero.\n");
	else
		c=a/b;
		printf("%d",c);
}

在这里插入图片描述

13计算心跳次数

#include<stdio.h>
#include<math.h>
main()
{
	int n,c;
	printf("Please input your age: ");
	scanf("%d",&n);
	c=n*365*24*60*75;
	printf("The heart beats in your life: %d",c);
}

在这里插入图片描述

14输出指定文字

#include<stdio.h>
main()
{
	printf("*****************************\n");
	printf("* C programming            *\n");
	printf("* Hello world!          *\n");
	printf("*****************************\n");
}

15温度转换

#include<stdio.h>
#include<math.h>
main()
{
	double t,T;
	printf("Please input fahr: ");
	scanf("%lf",&t);
	T=5.0*(t-32.0)/9.0;
	printf("The cels is: %.2f",T);
}

#include<stdio.h>
#include<math.h>
main()
{
	double t,T;
	printf("Please input cels: ");
	scanf("%lf",&t);
	T=t*9.0/5.0+32.0;
	printf("The fahr is: %.2f",T);
}

在这里插入图片描述

16体重指数

#include<stdio.h>
#include<math.h>
main()
{
	int w,h,weight;
	double height,t;
	printf("Input weight, height:\n");
	scanf("%d,%d",&w,&h);
	weight=w*2;
	height=h/100.00;
	t=w/(height*height);
	printf("weight=%d\n",weight);
	printf("height=%.2f\n",height);
	printf("t=%.2f\n",t);
}

在这里插入图片描述

17大象喝水

#include<stdio.h>
#include<math.h>
main()
{
	int h,r,n;
	float PAI=3.14159;
	scanf("%d,%d",&h,&r);
	n=20000/(h*r*r*PAI);
	printf("please input the height and the radius:\n%d",n+1);
}

在这里插入图片描述

18输出大写字母,所占内存大小

#include<stdio.h>
main()
{
	char c1,c2;
	printf("please input a lowercase:\n");
	c1=getchar();
	c2=c1-32;
	printf("%c %d %d\n",c2,c2,sizeof(c2));
}

在这里插入图片描述

19改错12a4.

#include <stdio.h>
main()
{
    int i;
    char ch;
    float f;
    printf("Please input:\n");
    scanf("%d%c%f",&i,&ch,&f);
    printf("The input integer is : %d \nThe input character is : %c\n", i, ch);
    printf("The input float is : %f", f);
}

在这里插入图片描述

20输出N个阶乘

#include<stdio.h>
#include<math.h>	
main()
{
	int i,n;
	long p=1;
	printf("Please enter n:");
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		p=p*i;
		printf("%d! = %ld\n",i,p);
	}
}

在这里插入图片描述
注:其余39道基础题在我资源文档中。

标签:main,scanf,邮电大学,C语言,课程,printf,input,include,c2
来源: https://blog.csdn.net/pitepa/article/details/111743776

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有