while循环练习题(C语言一个while循环的选择题)

本文目录
- C语言一个while循环的选择题
- C语言,利用getchar(),while循环读取字符数,总字数,行数的一道练习题,求解
- C语言 while循环小练习
- while 循环语句练习 程序功能:运行程序后,从键盘输入数字 1/2/3 后,可显示抽奖得到的奖品(1:恭喜你得
- C# While循环作业
- 关于do while循环的题目
- 关于C++的dowhile循环题目
- 用while循环打出100-10000之间各位数之和为7的数
- while循环求一个整数是几就有几个零
- 请各位大神用Cfree的while循环帮忙做下4、5、6练习
C语言一个while循环的选择题
第一次循环:执行a《b,它的值等于1,1《c,执行while里面的语句,那么c=1
第二次:执行a《b,它的值是0,0《c,执行while里面的语句,那么c=0
第三次:执行a《b,它的值是1,1》c,不执行while
故a=1,b=2,c=0
C语言,利用getchar(),while循环读取字符数,总字数,行数的一道练习题,求解
#include 《stdio.h》
#include 《stdlib.h》
int main(void){
int ch=0,characters=0,words=0,newlines=0;
char str={0};
while(4!=(ch=getchar())){//我的环境中ctrl d对应-1
if(’\n’==ch){
newlines++;
if(str!=’ ’){
words++;
}
}
if(str!=’ ’&&’ ’==ch){
words++;
}
str=ch;
characters++;
}
if(str!=’\n’){
words++;
}
printf("characters=%d,words=%d,newlines=%d\n",characters,words,newlines+1);
return 0;
}
C语言 while循环小练习
#include 《stdio.h》
#pragma warning(disable:4996)//VS关闭scanf()报错
int main(void)
{
int i,num;
printf("请输入一个数:\n");
scanf("%d", &num);
i = num / 4;
while (i--)
{
if ((num % 4) == 0 && i == 0)
{
printf("four");
}
else
{
printf("four-");
}
}
if((num % 4) != 0)
printf("%d\n", (num % 4));
return 0;
}
不知道为什么代码直接复制进来是没有格式的
while 循环语句练习 程序功能:运行程序后,从键盘输入数字 1/2/3 后,可显示抽奖得到的奖品(1:恭喜你得
#include 《stdio.h》
int main()
{
int i;
do
{
printf("please give me one number:");
scanf_s("%d",&i);
if (i==1)
{
printf("恭喜你得大奖,一辆汽车!\n");
}
if (i==2)
{
printf("不错呀,你得到一台笔记本电脑\n");
}
if (i==3)
{
printf("没有白来,你得到一台冰箱\n");
}
if (i》3 || i《 0)
{
printf("很遗憾,您没有中奖!\n");
}
}
while(i);
printf("欢迎再来^_^\n");
return 0;
}
C# While循环作业
//int a = 0;
////while (true)
////{
//// Console.WriteLine("我陷入死循环");
//// a++;
//// if (a 》 10)
//// {
//// break;//中断,跳出循环!
//// }
////}
//while (a 《= 10)
//{
// Console.WriteLine("a:{0}", a);
// a++;
//}
int a = 10;
int b = 0;
//int c = a % b;
Console.Write("请您输入一个数字,我们为您求得0至您输入的数字之间的偶数:");
int d = Convert.ToInt32(Console.ReadLine());
int e = d;
while (d 》= 0)
{
int c = (d + 1) % 2;
if (c != 0 && d != 0)
{
Console.WriteLine("\n0-{0}之间的偶数:{1}", e, d);
b += d;
}
d--;
}
Console.WriteLine("\n0-{0}之间的偶数和:{1}", e, b);
//Console.Write("\n请您输入两个数字,我们为您求得它们之间的奇数");
//Console.Write("\n请您输入第一个数字:");
//int f = Convert.ToInt32(Console.ReadLine());
//Console.Write("\n请您输入第二个数字:");
//int e = Convert.ToInt32(Console.ReadLine());
//if (e 》= f)
//{
// while (e 》= f)
// {
// int c = e % 2;
// if (c != 0 && e != 0)
// {
// Console.WriteLine("{0}-{1}之间的奇数:{2}", f, e, e);
// }
// e--;
// }
//}
//if (f 》= e)
//{
// while (f 》= e)
// {
// int c = f % 2;
// if (c != 0 && f != 0)
// {
// Console.WriteLine("{0}-{1}之间的奇数:{2}",f, e, f);
// }
// f--;
// }
//}
//Console.WriteLine("请您注册您一个用户名:");
//string userInfoId = "";
//userInfoId = Console.ReadLine();
//Console.WriteLine("请您注册您一个密码:");
//string userPassword = Console.ReadLine();
//int a = 3;
//while (a 》 0) {
// Console.WriteLine("请您输入您的用户名:");
// string accountNumber =Console.ReadLine();
// Console.WriteLine("请您输入您的密码:");
// string password = Console.ReadLine();
// if(accountNumber==userInfoId&& password == userPassword)
// {
// Console.WriteLine("恭喜您输入正确");
// a = 0;
// }
// else
// {
// a--;
// Console.WriteLine("抱歉,您输入出错了,还有{0}次输入机会!",a);
// }
//}
Console.ReadKey();
关于do while循环的题目
先判断a是否大于10,再判断b是否小于10,无论结果是什么,b=b+1
第一个循环:
a=100, b=4
a/=b后,a=25,b=4
判断条件成立
b+1=5;
第二个循环
a=25, b=5
a/=b后,a=5,b=5
判断条件不成立
跳出循环
b+1=6;
这时打印结果是a=5,b=6;
关于C++的dowhile循环题目
第一次循环
x=3-2=1
输出1
然后while里面是先--x,x变成0,然后!x是1,所以执行第二次循环
x=0-2 = -2
输出-2
然后先--x,x变成-3,!x就是0,退出循环
用while循环打出100-10000之间各位数之和为7的数
#include《stdio.h》
void main()
{
int i;
i=100;
while(i《=10000)
{
if(i《=1000)
{
if((i/100+i/10%10+i%100)==7)
printf("%d,",i);
}
else
{
if((i/1000+i/100%10+i/10%100+i%1000)==7)
printf("%d,",i);
}
i++;
}
}
while循环求一个整数是几就有几个零
如何使用while循环计算一个整数的位数
做个 java 小练习,使用while循环来实现如下功能:
计算出任意一个小于10位的整数的个数.
如输入100,则输出:它是个3位数!
实现代码如下
public static void count(int n) {
/**
* 计算一个整数(小于10位)的位数
* 如:输入999,则输出 "它是个3位数"
*
* @param n:小于10位的整数
*
*/
if(n 》= 0 && n 《= 999999999) {
int countN = 0;
while(n != 0) {
countN++;
n /= 10;
}
System.out.println("它是个" + countN + "位数!");
}else {
System.out.println("The number is too large! ");
}
}
这里主要是练习一下 while 循环的使用,实现一个简单的小功能。
java循环习题,求整数位数
案例1、整数位数
功能描述:任意输入一个整数(小于10位),求它的位数
方法一
System.out.println("任意输入一个整数(小于10位):");
Scanner sc = new Scanner(System.in);
long s = sc.nextLong();
String str = String.valueOf(s);
if(str.length() 》= 10){
System.out.println("您输入的整数超过的10位!");
}else{
System.out.println("您输入的整数是"+str.length()+"位。");
}
方法二
System.out.println("任意输入一个整数(小于10位):");
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
int count = 0;
//计算位数
do{
num /= 10;
count++;
}while(num 》 0);
System.out.println("该数字是"+count+"位。");
请各位大神用Cfree的while循环帮忙做下4、5、6练习
第4题
#include 《stdio.h》
#include 《math.h》
int main(void)
{
double ns,zsr;
ns=log10(13/3)/log10(1.1);
printf(" 需要 %.2f 年能成为百万富翁\n",ns);
return 0;
}
第5题
#include 《stdio.h》
int main(void)
{
int i,bjs,bws,sws,gws;
printf(" 从 100 到 999 之间的水仙花数:");
for(i=100;i《1000;i++)
{
bws=i/100;
sws=(i-bws*100)/10;
gws=i-bws*100-sws*10;
if(i==bws*bws*bws+sws*sws*sws+gws*gws*gws)
printf(" %d",i);
}
return 0;
}
第6题有问题,因为 1-1/2+1/3-1/4+1/5-...... 的累积项都大于0.5,所以永远都不会小于0.01。

更多文章:
androidapp源码免费下载(如何实现APK的反编译得到APK的源码)
2026年9月22日 18:00
service pack 3(操作系统版本升级(SP) Service Pack 3当中的“Service Pack 3”是什么意思)
2026年9月22日 10:20
html代码怎么写大佬教程(html网页的题来个大佬,写代码,题目在图上)
2026年9月22日 10:10
结构体内又一个struct(c++ 在结构体中再嵌入一个结构体如何调用)
2026年9月22日 09:40
cocos creator中文(cocoscreator和cocoscreator3d的区别)
2026年9月22日 02:30






