首页 > 其他 > 详细

实验三

时间:2019-11-16 19:43:14      阅读:66      评论:0      收藏: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<=4) {
        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>
int main()
{
    long int x,y,t,i;
    i = 1;
    y = 0;
    printf("Enter a number: ");
    scanf("%ld",&x);
    while(x != 0)
    {
        t = x % 10;
        x = x / 10;
        if (t % 2 !=0)
        {
            y = y + t * i;
            i = i * 10;
        }
    }

    printf("new number is: %ld", y);

    return 0;
}

技术分享图片

#include<stdio.h>
#include<math.h>
int isprime(int n);
int main()
{
    int i,j;
    j=0;
    for(i=101;i<=200;i++)
    {
        if(isprime(i))
          printf("%4d",i);
        if(isprime(i))  
          j=j+1;  
        if(i%30==0)
          printf("\n");
    }
    printf("\n101~200之间共有素数个数:%d",j);
    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(){
    int n,a,b;
    float s,m,t;
    s=0;
    m=0;
    t=1;
    b=1;
    printf("Enter n and a:\n");
    scanf("%d%d",&n,&a);
    while(t<=n)
    {
        m=m+b*a;
        s=s+t/m;
        b=10*b;
        t++;
    }
    printf("s=%f\n",s);
    return 0;
}

技术分享图片

实验三

原文:https://www.cnblogs.com/nanamocha/p/11872905.html

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