标签:guess bsp ret ons bre 控制 输出 sqrt higher
#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 then 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<5) {
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>
#include <math.h>
int main ()
{
int i,j,k,count=0;
int m=0;
for(i=101;i<=200;i++)
{
k=sqrt(i);
for (j=2;j<=k;j++)
if(i%j==0)
break;
if(j>k)
{
printf("%d\t",i);
m++;
if(m%5==0)
printf("\n");}
count++;
}
printf("\n");
printf("100~200之间共有%d\n个素数. ",count);
return 0;
}
#include<stdio.h>
int main()
{
long int s,p=1,t=0;
printf("输入一个整数:");
scanf("%ld",&s);
while(s)
{
if((s%10)%2!=0)
{
t=t+(s%10)*p;
p=p*10;
}
s=s/10;
}
printf("得到的数为:%ld\n",t);
return 0;
}
实验总结与体会
本次实验使我更加熟练掌握了握while语句、do...while语句、for语句用法以及在part 3中学会了控制每行数据个数换行输出。
实验3
标签:guess bsp ret ons bre 控制 输出 sqrt higher
原文地址:https://www.cnblogs.com/ws6666/p/11881181.html