首页 > 其他 > 详细

实验三

时间:2019-11-20 10:49:30      阅读:79      评论:0      收藏:0      [点我收藏+]
#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.\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 = %f, x2 = %f\n", x1, x2);
            }
            else {
                real = -b/(2*a);
                imag = sqrt(-delta) / (2*a);
                printf("x1 = %f + %fi, x2 = %f - %fi\n", real, imag, real, imag);
            }
        }
        
        printf("Enter a, b, c:\n");
    }
    system("pause");
    return 0;
} 

技术分享图片

#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.\n", ans);
        else if(ans > guessNumber) 
            printf("%d higher then the number.\n", ans); 
    }while(ans != guessNumber);
    
    printf("Congratulations. you hit it~\n");    
    
    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(max<=number)
            max = number;
        else if(min>=number)
            min = number;
    }
    
    printf("最大数为: %d\n", max);
    printf("最小数为: %d\n", min);
    
    system("pause");
    
    return 0;
} 

技术分享图片

#include<stdio.h>
#include<math.h>
int isprime(int n);
int main()
{
    int i,x;
    x=0;
    for(i=101;i<=200;i++)
    {
        if(isprime(i)){
        
        printf("%4d",i);
        x++;}
    }
    printf("\n101~200内共有%ld个素数\n",x);
    return 0;
 } 
 int isprime(int n){
     int k;
     for(k=2;k<=sqrt(n);k++)
    if(n%k==0)
            return 0;
     return 1;
}

技术分享图片

#include<stdio.h>
int main(){
    long int n;
    int a=0,b,c=1;
     printf("Enter a number:\n");
      scanf("%ld",&n);
       while (n!=0){
           b=n%10;
           n=n/10;
            if(b%2==1){
        a=a+b*c;
        c=c*10;
    }
       }
    printf("Enter a new number:%d\n",a);
    return 0;
    
    
}

技术分享图片

最后一个编程题太难了...

实验三

原文:https://www.cnblogs.com/xiaolinsocute/p/11894858.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!