码迷,mamicode.com
首页 > 其他好文 > 详细

实验3

时间:2019-11-18 23:26:23      阅读:110      评论:0      收藏:0      [点我收藏+]

标签:最小数   amp   int   clu   img   ESS   ret   srand   while   

#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;
int ans;

srand((time(0)));
guessNumber = 1 + rand()%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 than the number.\n", ans);
}while(ans!=guessNumber);

printf("Congratulations. you hit it~\n");

system("pause");

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<=4) {
n++;
printf("输入第%d个数: ", n);
scanf("%d", &number);

if(number>=max)
max = number;
else if(number<=min)
min = number;
}
printf("最大数为: %d\n", max);
printf("最小数为: %d\n", min);

system("pause");

return 0;
}

技术图片

 

 

#include <stdio.h>
int main()
{
long s;
int m,i;
int q=10000000;
scanf("%ld",&s);

for(i=1;i<=8;i++)
{
m=s/q;
if(m%2!=0)
printf("%d",m);
s=s-m*q;
q=q/10;
}
return 0;
}

技术图片

 

 

#include<stdio.h>
#include<math.h>
int sushu(int a);
int main()
{int a,n=0;
for(a=101;a<=200;a++)
{
if (sushu(a))
{
printf("%d,",a);
n++;
}
}
printf("\n有%d个素数",n);

return a;
}
int sushu(int a)
{int i;
for(i=2;i<a;i++)
if(a%i==0)
return(0);

return(1);
}

技术图片

 

实验3

标签:最小数   amp   int   clu   img   ESS   ret   srand   while   

原文地址:https://www.cnblogs.com/uziuzi/p/11886362.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!