#include <stdio.h>//task1.2 int main() { printf(" O O\n"); printf("<H> <H>\n"); printf("I I I I\n"); return 0; }
#include <stdio.h>//task1 int main() { printf(" O \n"); printf("<H>\n"); printf("I I\n"); return 0; }
#include <stdio.h>//task1.1 int main() { printf(" O \n"); printf("<H>\n"); printf("I I\n"); printf(" O \n"); printf("<H>\n"); printf("I I\n"); return 0; }
#include<stdio.h>//task2 int main() { int n,sum; scanf("%d", &n); sum = n/2*(n+1); printf("sum = %d\n",sum); return 0; }
讨论:写法3无法实现,因为将n/2视为整数,输入51/2=25
#include<stdio.h>//task3 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); return 0; }
讨论:实现a与b数值互换
#include<stdio.h>//task4 int main() { int x,t,m; x=123; 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); return 0; }
讨论:实现x倒序
#include <stdio.h>//task5 int main() { float a,b,c; scanf("%f%f%f",&a,&b,&c); if (a+b>c and a+c>b and b+c>a) printf("能构成三角形\n"); else printf("不能构成三角形\n"); return 0; }
#include<stdio.h>//task6 int main() { int year; year=1000000000; year=year/60/60/24/365; printf("10亿秒约等于%d年\n",year); return 0; }#include<stdio.h> //task7
#include<stdlib.h>
#include<time.h>
int main()
{
int n;
srand((unsigned)time(NULL));
n=rand() % 41 + 60;
printf("n=%d\n",n);
return 0;
}
#include<stdio.h> //task8 int main() { char ans1,ans2; printf("每次课前认真预习、课后及时复习了吗?(输入y或Y表示有,输入n或N表示木有)"); ans1=getchar(); getchar(); printf("\n动手敲代码时间了没?(输入y或Y表示敲了,输入n或N表示木有敲)") ; ans2=getchar(); if(ans1==ans2 and ans2=='y' or ans1==ans2 and ans2=='Y') printf("\n罗马不是一天建成的,继续保持哦:)\n"); else printf("\n罗马不是一天毁灭的,我们来建设吧\n"); return 0; }
标签:10,include,return,int,实验,printf,main From: https://www.cnblogs.com/wu-wu-/p/17172402.html