实验任务一

#include <stdio.h>
#include <math.h>
int main(){
float a, b, c, x1, x2;
float delta, real, imag;
printf("Enter a, b, c: ");
while(scanf("%f%f%f", &a, &b, &c) != EOF) {
if(a == 0) printf("not quadratic equation.\n\n");
else {
delta = b*b - 4*a*c;
if(delta >= 0) {
x1 = (-b + sqrt(delta)) / (2*a);
x2 = (-b - sqrt(delta)) / (2*a);
printf("x1 = %.2f, x2 = %.2f\n\n", x1, x2);
}
else {
real = -b/(2*a);
imag = sqrt(-delta) / (2*a);
printf("x1 = %.2f + %.2fi, x2 = %.2f - %.2fi\n\n", real, imag, real, imag);
}
}
printf("Enter a, b, c: ");
}
return 0;
}

实验任务二

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define N 5
int main (){
int x,n;
srand(time(0));
n=0;
do {
n++;x= rand()%10;
printf("%3d",x);
}while(n<N);
printf("\n");
return 0;
}

实验任务三

#include <stdio.h>
int main (){
int x=101;
int n=200;
int num=0;
for (;x<=200;x++){
int t,flag;
flag=1;
for (t=2;t<x;t++)
{
if (x%t==0)
{flag=0;
}
}
if (flag){
printf(" %d",x);
num++;
if (num%5==0) printf("\n");
}
}
printf("\n101~200之间共有%d个素数",num);
return 0;
}

实验任务四

#include <stdio.h>
int main(){
long s;
printf("Enter a number: ");
while (scanf("%ld",&s)!=EOF){
long sum,t;
sum=0;
int a,b;
b=0;
t=10;
long j=10;
if (s<1000000000){
while (s/t!=0){
a=(s%t-b)/(t/10);
b=b+a*(t/10);
if(a%2!=0){
sum=sum+a*(j/10);
j=j*10;
}
t=t*10;
}
a=(s%t-b)/(t/10);
b=b+a*(t/10);
if(a%2!=0){
sum=sum+a*(j/10);
}
}else{
int x;
for (x=1;x<=9;x++){
a=(s%t-b)/(t/10);
b=b+a*(t/10);
if(a%2!=0){
sum=sum+a*(j/10);
j=j*10;
}
t=t*10;
}
a=s/1000000000;
if(a%2!=0){
sum=sum+a*(j/10);
}
} printf("new number is: %ld\n\n",sum);
printf("Enter a number: ");
}
return 0;
}

实验任务五

#include <stdio.h>
int main(){
int n;
printf ("Enter n(1~10):");
while (scanf ("%d",&n)!=EOF){
int t,f,T;
f=1;
T=1;
double s=0.0;
for (t=1;t<=n;t++){
T=t*T;
s=s+f*(1.0/T);
f=f*(-1);
}
printf("n = %d, s = %f\n\n",n,s);
printf ("Enter n(1~10):");
}
}

实验任务六

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
int main (){
printf("猜猜2020年12月哪一天会是你的luck day\n\n");
int n= rand()%31+1;
int t=1;
printf ("开始喽,你有三次机会,猜吧(1~31):");
int a;
for (t=1;t<=3;t++){
scanf("%d",&a);
if(a<n){
printf("小伙子真着急,你猜的日期早了,luck day还妹到呢\n\n");
}
if (a>n){
printf("你猜的日期晚啦,luck已经莫得了\n\n");
}
if (a==n){
printf("这也能猜中??这么好的luck还需要luck day干嘛,速速去买彩票\n\n");
break;
}
}
if(a!=n){
printf("次数用光啦。。。偷偷告诉你:");
Sleep(1000);
printf("12月");
for (t=1;t<=3;t++){
Sleep(500);
printf("。");
}
Sleep(1000);
printf("每天都是luck day!!!");
}
}

随机推荐

  1. NameServer 与zk

    1.nameServer 之间互不通信,故不存在强一致性,即不同的producer看到的视图可能时不一样的,(如何保证最终一致的?) 2.nameServer维护的boker信息 发生变化时,不会像z ...

  2. Flv.js记录(vue)

    下载 npm install flv.js 插入 import flvjs from 'flv.js'   第一种报错:Failed to read the 'buffered' property f ...

  3. Python中使用f字符串进行字符串格式化的方法

    在<第3.10节 Python强大的字符串格式化新功能:使用format字符串格式化>介绍了使用format进行字符串格式化的方法,在Python 3.6中,如果格式化字符串中的关键字参数 ...

  4. buu学习记录(上)

    前言:菜鸡误入buu,差点被打吐.不过学到了好多东西. 题目名称: (1)随便注 (2)高明的黑客 (3)CheckIn (4)Hack World (5)SSRF Me (6)piapiapia ( ...

  5. 3、tensorflow变量运算,数学运算

    import tensorflow as tf import numpy as np a = tf.range(1,7) a = tf.reshape(a,[2,3]) b = tf.constant ...

  6. Raft概述

    Raft 1. 概述 Raft是一种一致性(共识)算法,相比Paxos,Raft更容易理解和实现,它将分布式一致性问题分解成多个子问题,Leader选举(Leader election).日志复制(L ...

  7. 【题解】「UVA681」Convex Hull Finding

    更改了一下程序的错误. Translation 找出凸包,然后逆时针输出每个点,测试数据中没有相邻的边是共线的.多测. Solution 首先推销一下作者的笔记 由此进入>>> ( ...

  8. linux的Umask 为022 和027 都是什么意思?

    用全部权限777去减这个数值 一.022表示默认创建新文件权限为755 也就是 rxwr-xr-x(所有者全部权限,属组读写,其它人读写)  二.027表示默认创建新文件权限为750 也就是rxwr- ...

  9. 基于WSL2 的 Docker Desktop 启动时 Failed to set version to docker-desktop: exit code: -1的解决方法

    在Windows 10 的 2004 版本  中, 启用 使用Docker Desktop 时 发现  根本无法启动, 偶尔 或者频繁的出错: System.InvalidOperationExcep ...

  10. Spring自带的定时任务框架Schedule的优缺点及使用

    spring自带的定时任务框架的有点:简单,拆箱即用 spring自带的定时任务框架的缺点: 不支持集群:为避免重复执行的问题 不支持生命周期统一管理:不重启服务情况下关闭,启动任务 不支持分片任务: ...