实验3

Posted zxjaq

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了实验3相关的知识,希望对你有一定的参考价值。

// 一元二次方程求解
// 重复执行, 直到按Ctrl+D或Ctrl+E结束
//  
#include <math.h>
#include <stdio.h>
#include <stdlib.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)) {
        if(a == 0) 
            printf("not quadratic equation.
");
        else {
            delta = b*b - 4*a*c;
        
            if(delta >= 0) {
                x1 = (-b + sqrt(delta)) / (2*a);
                x2 = (-b - sqrt(delta)) / (2*a);
                printf("x1 = %f, x2 = %f
", x1, x2);
            }
            else {
                real = -b/(2*a);
                imag = sqrt(-delta) / (2*a);
                printf("x1 = %f + %fi, x2 = %f - %fi
", real, imag, real, imag);
            }
        }
        
        printf("Enter a, b, c:
");
    }
    system("pause");
    return 0;
} 

技术图片

// 猜数游戏
// 程序运行时自动生成1~100之间的随机数,提示用户猜
// 如果用户猜的数等于随机数,提示用户猜对了,程序结束
// 否则,如果用户猜的数小于随机数,提示用户低了,用户继续猜
// 如果用户猜的数大于随机数,提示用户高了,用户继续猜 
// 程序循环运行直到用户猜对为止

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main() {
    int guessNumber; // 存放程序运行时生成的1~100之间的随机整数 
    int ans;     // 存放用户猜的数字 
    
    srand((time(0)));  // 以时间函数作为随机种子 
    guessNumber = 1 + rand()%100;  // 生成1~100之间的随机数 
    
    do {
        printf("your guess number is(1~100): ");
        scanf("%d", &ans);
        if(ans < guessNumber)
            printf("%d is lower than the number.
", ans);
        else if(ans > guessNumber) 
            printf("%d higher then the number.
", ans); 
    }while(ans != guessNumber);
    
    printf("Congratulations. you hit it~
");    
    
    system("pause"); // 在devc中运行时,这一行可以去掉
     
    return 0;
} 

技术图片

#include <stdio.h>
#include <stdlib.h>
int main() {
    int number, max, min, n;
    
    n=1;
    printf("输入第%d个数: ", n);
    scanf("%d", &number);
    max = number;
    min = number;
    
    while(n<5/*补足①*/) {
        n++;
        printf("输入第%d个数: ", n);
        scanf("%d", &number);    

        if(number>=max/*补足②*/)
            max = number;
        else if(number<=max/*补足③*/)
            min = number;
    }
    
    printf("最大数为: %d
", max);
    printf("最小数为: %d
", min);
    
    system("pause");
    
    return 0;
} 

技术图片

#include <stdio.h>
#include <stdlib.h> 
#include <math.h>

int main(){
    int n,i,m,k;
    for(n=101;n<=200;n++){
    m=sqrt((double)n);
    for(i=2;i<=m;i++)
    if(n%i==0)break;
    if(i>m&&n>100){
        k++;
        printf("%5d",n);
        if(k%5==0)
        printf("
 ");
    }
    }
    
    printf("一共有 %d 个数",k);
    
    return 0; 
    } 

技术图片

#include <stdio.h>
int main(){
 int n;
 printf("Enter a number
"); 
    while((n=getchar()))
{
 switch(n%2)
 {
  case 0:continue;
  case 1:putchar(n);break;
 }
}

    return 0;

}

技术图片

以上是关于实验3的主要内容,如果未能解决你的问题,请参考以下文章

20155201 李卓雯 《网络对抗技术》实验一 逆向及Bof基础

JSP 设计教师与学生不同登陆界面(带验证码)

[NTUSTISC pwn LAB 7]Return to libc实验(puts泄露libc中gadget片段定位)

缓冲区溢出漏洞实验

使用 React 实验性中继片段:缺少属性 '"$fragmentRefs"'

chapter1.高通量序列实验简介:设计与生物信息学分析