首页 > 其他 > 详细

实验三

时间:2019-11-19 12:47:55      阅读:87      评论: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(max==min) {
		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 main(){
	int a,b=0,c;
	for(a=101;a<=200;a++){
		for(c=2;c<=sqrt(a);c++){
			if(a%c==0)
			break;
		}
		if(c>sqrt(a)){
			printf("%4d",a);
			b++;
			if(b%5==0)
			printf("\n");
		}
	}
	printf("101~200之间共有%d个素数\n",b);
	return 0;
}

	

  技术分享图片

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

  技术分享图片

#include <stdio.h>
int main(){
	int n,i;
	float a,m,s,b;
	m=0;s=0;
	printf("Enter n and a:\n",n,a);
	scanf("%d%f",&n,&a);
	for(i=1;i<=n;i++){
		m=a+m*10;
		b=1/m;
		s=s+b;
	}
	printf("%f\n",s);
	return 0;
}

  技术分享图片

对于数据类型的定义不清晰,在写程序时容易弄错,导致运行结果奇怪。

实验三

原文:https://www.cnblogs.com/cyh010430/p/11888524.html

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