1.实验任务1
task1_1.c
#include<stdio.h> #include<stdlib.h> int main() { printf(" 0 \n"); printf("<H>\n"); printf("I I\n"); printf(" 0 \n"); printf("<H>\n"); printf("I I\n"); system("pause"); return 0; }
task1_2.c
#include<stdio.h> #include<stdlib.h> int main() { printf(" 0 0 \n"); printf("<H> <H>\n"); printf("I I I I\n"); system("pause"); return 0; }
2.实验任务2
#include<stdio.h> #include<stdlib.h> int main() { int n,sum; scanf("%d",&n); sum = n*(n+1)/2; printf("sum = %d\n",sum); system("pause"); return 0; }
写法一和写法二能够实现题目要求,三和四先做了除法,对于int型的除法,写法三51/2省去了小数部分产生了误差,写法四(50+1)/2省去了小数部分产生了误差。
3.实验任务3
#include<stdio.h>; #include<stdlib.h>; int main() { int a,b,t; a = 3; b = 4; printf("a = %d,b = %d\n",a,b); t = a; a = b; b = t; printf("a = %d,b = %d\n",a,b); system("pause"); return 0; }
实现了a和b数值的交换
4.实验任务4
#include<stdio.h> #include<stdlib.h> int main() { int x,t,m; x = 456; printf("x = %d\n",x); t= 0; m = x % 10; t = t * 10 + m; x = x / 10; m = x % 10; t = t * 10 + m; x = x / 10; m = x % 10; t = t * 10 + m; x = x / 10; printf("t = %d\n",t); system("pause"); return 0; }
实现的功能是把各个位的数字顺序颠倒了
5.实验任务5
#include<stdio.h> #include<stdlib.h> int main() { float a,b,c; scanf("%f%f%f",&a,&b,&c); if(a+b>c&&abs(a-b)<c) printf("能构成三角形\n"); else printf("不能构成三角形\n"); system("pause"); return 0; }
6.实验任务6
#include<stdio.h> #include<stdlib.h> int main() { int year; year = 10*10*10*10*10*10*10*10*10/(60*60*24*365); printf("10亿秒约等于%d年\n",year); system("pause"); return 0; }
7.实验任务7
#include<stdio.h> #include<stdlib.h> int main() { int n; srand((unsigned)time(NULL)); n = rand() % 41+60; printf("n = %d\n",n); system("pause"); return 0; }
8.实验任务8
#include<stdio.h> #include<stdlib.h> int main() { char ans1,ans2; printf("每次课前认真预习、课后及时复习了没?(输入y或Y表示有,输入n或N表示没有):"); ans1 = getchar(); getchar(); printf("\n动手敲代码实践了没?(输入y或Y表示敲了,输入n或N表示木有敲):"); ans2 = getchar(); if(ans1== 'y'&&ans2=='y'||ans1=='Y'&&ans2=='Y') printf("\n罗马不是一天建成的,继续保持哦:)\n"); else printf("\n罗马不是一天毁灭的,我们来建设吧:)\n"); system("pause"); return 0; }
标签:10,main,int,pause,实验,printf,include From: https://www.cnblogs.com/cxj114-514/p/17173934.html