当前位置:网站首页>C language learning log 10.11

C language learning log 10.11

2022-06-13 04:57:00 Today is also a day without baldness

Today is mainly about writing questions

Topic 1 .

Different countries in the world have different habits of writing dates . For example, Americans are used to writing “ month - Japan - year ”, And the Chinese are used to writing “ year - month - Japan ”. Now please write a program , Automatically change the date in American format into the date used by China .

Input format :

Type in a line and press “mm-dd-yyyy” To the moon 、 Japan 、 year . The date given in the title guarantee is 1900 The legal date from New Year's day to the present .

Output format :

In a row, press “yyyy-mm-dd” The format gives the year 、 month 、 Japan .

sample input :

03-15-2017

No blank lines at the end

sample output :

2017-03-15

No blank lines at the end

#include<stdio.h>
int main(void)
{
	int a,b,c,d;
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	b=-b;
	c=-c;
	if(a/10>0&&b/10>0)
{
	printf("%d-%d-%d",c,a,b);
}else if(a/10<=0&&b/10>0){
	printf("%d-0%d-%d",c,a,b);
}else if(a/10<=0&&b/10<=0){
	printf("%d-0%d-0%d",c,a,b);
}else if(a/10>0&&b/10<=0){
	printf("%d-%d-0%d",c,a,b);
}

}

Topic two .

Know a student's math 、 The grades of English and computer courses are 87 branch 、72 Points and 93 branch , Beg the student 3 The GPA of the course ( The result is output as an integer ).

Input format :

No input for this question

No blank lines at the end

Output format :

Output the results in the following format :

math = 87, eng = 72, comp = 93, average =  Calculated GPA 

No blank lines at the end

#include<stdio.h>
int main(void)
{
	const int math=87;
	const int eng=72;
	const int comp=93;
	int average;
	average=(math+eng+comp)/3;
	printf("math = %d, eng = %d, comp = %d, average = %d",math,eng,comp,average);
}

Question three .

For the two integers entered , Output the sum difference product quotient as required .

Input format :

Enter two numbers in one line that do not exceed 100 Non-negative integer a and b, The middle is separated by a space , And guarantee b Not for 0.

Output format :

There are four lines in total , The format is :

[a] + [b] = [a+b]
[a] - [b] = [a-b]
[a] * [b] = [a*b]
[a] / [b] = [a/b]

among , Bracketed content ( Such as [a][b][a+b] etc. ) Represents the value of the corresponding integer or operation result , When outputting, use the actual value instead of .

also : If a It can be b to be divisible by , that a/b The output should be in integer format , otherwise a/b The output is in a format with two decimal places .

Tips : Notice the spaces in the expression .

sample input 1:

6 3

No blank lines at the end

sample output 1:

6 + 3 = 9
6 - 3 = 3
6 * 3 = 18
6 / 3 = 2

No blank lines at the end

sample input 2:

8 6

sample output 2:

8 + 6 = 14
8 - 6 = 2
8 * 6 = 48
8 / 6 = 1.33
#include<stdio.h>
int main(void){
	int a,b,c,d,e;
	double f;
	scanf("%d %d",&a,&b);
	c=a+b;
	d=a-b;
	e=a*b;
	if((0<=a&&a<=100)&&(0<b&&b<=100)){
		printf("%d + %d = %d\n",a,b,c);
    	printf("%d - %d = %d\n",a,b,d);
    	printf("%d * %d = %d\n",a,b,e);
	}
    if(a%b==0){
		printf("%d / %d = %d\n",a,b,(int)a/b);
	}else{
		f=a/(b*1.0);
		printf("%d / %d = %.2f\n",a,b,f);
	}
	
}

 

原网站

版权声明
本文为[Today is also a day without baldness]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202280517426156.html