ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

实验三

2021-04-14 17:32:23  阅读:108  来源: 互联网

标签:%. int double delta 实验 printf include


#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define N 5

int main() {
    int x, n; 
    
    srand(time(0));  // 以当前系统时间作为随机种子 
    
    for(n=1; n<=N; n++) {
        x = rand() % 100;  // 生成一个0~99之间的随机整数
        printf("%3d", x);
    }
    
    printf("\n");
    
    return 0;
} 

#include <stdio.h> 
#include <stdlib.h> 
#include <time.h> 
#define N 1 
int main() 
{ 
    int x, n, a; 
    srand(time(0)); 
    printf("猜猜2021年5月的哪一天会是你的lucky day\n");
    printf("你有三次机会哦,快来试试欧气把。(1~31):");
    x = rand() % 30+1;
    for(n=1; n<=3;) 
    {   
        scanf("%d", &a);
        if (a == x)
        {
            printf("芜湖~猜对了!!\n");break;
        }
        else if (a > x)    
        {
            printf("你猜的幸运日晚了,lucky day悄悄溜到前面啦\n");
        }
        else
        {
            printf("你猜的幸运日早了,lucky day还没到呢\n");
        }
        n++;
        if (n > 3)break;
        printf("再猜~(1~31):");
    }
    if (n > 3)
    {
        printf("次数用完啦,偷偷告诉你幸运日其实是%d啦\n",x);
    }
    return 0;
}

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

#include <math.h>
#include <stdio.h>
void solve(double a, double b, double c);

int main() {
    double a, b, c;
    
    printf("Enter a, b, c: ");
    while(scanf("%lf%lf%lf", &a, &b, &c) != EOF) {
        solve(a, b, c); 
        printf("Enter a, b, c: ");
    }
    
    return 0;
}


void solve(double a, double b, double c) {
    double x1, x2;
    double delta, real, imag;
    
    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 = %.2f, x2 = %.2f\n", x1, x2);
        }
        else {
            real = -b/(2*a);
            imag = sqrt(-delta) / (2*a);
            printf("x1 = %.2f + %.2fi, x2 = %.2f - %.2fi\n", real, imag, real, imag);
        }
    }    
}

否。因为函数只能返回一个值。

#include <stdio.h>
double fun(int n);  // 函数声明 
 
int main() {
    int n;
    double s;
    
    printf("Enter n(1~10): ");
    while(scanf("%d", &n) != EOF) {
        s = fun(n);  // 函数调用 
        printf("n = %d, s= %f\n\n", n, s);
        printf("Enter n(1~10): ");
    }
    
    return 0;
}

// 函数定义 
double fun(int n) {
double s=1,x=1;
    int i;
    if(n==1)
    return 1;
    else{
    for(i=2;i<=n;i++){
        x=-x*1/i;
        s=s+x;
        }
    return s;
    }    
}

#include<stdio.h>
#include<stdlib.h>
int isPrime(int);
int main(){
    int i=0,x,s,sum=0;
    for(x=101;x<=200;x++){
        s=isPrime(x);
        if(s==0){
            printf(" %d",x);
            i++;
            x++;
            sum++;
            if(sum%5==0)
            {
                printf(" \n");
            }
        }
    }
    printf("\n101~200之间素数一共有%d个\n",i);
    system("pause");
    return 0;
}
int isPrime (int x)
{
    int n=0,i;
    for(i=2;i<x;i++){
        if(x%i==0)
            n++;
    }return n;
}

实验总结:上课的我:搞懂了,简简单单。做实验任务:我是笨蛋【扶额】。总是会有大大小小的错误,看见错误提示都要抓狂了。敲代码也没思路。乌乌。还是要更下心思啊。

标签:%.,int,double,delta,实验,printf,include
来源: https://www.cnblogs.com/dzyeah/p/14644568.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有