我是靠谱客的博主 平淡灰狼,这篇文章主要介绍[Loops]D. Liang 4.11 Finding numbers divisible by 5 or 6, but not both.c,现在分享给大家,希望可以做个参考。

Description
Write a program that reads two integer a and b(a<b), and displays all the numbers from a to b, ten numbers per line, which are divisible by 5 or 6, but not both.
Input
Two integer a and b (20<=a<b<500).
Output
You should specify the width of each number’s print field to 5, and justify the output to the left.
The numbers in one line are separated by a space and there is no space at the end of the line.
Sample Input
100 162
Sample Output
100 102 105 108 110 114 115 125 126 130
132 135 138 140 144 145 155 156 160 162

General error :
(1) output format is not required ;
(2) output spaces are not valid.
在这里插入图片描述在这里插入图片描述code show as below:

//  Date:2020/3/13
//  Author:xiezhg5 
#include<stdio.h>
int main(void) 
{
	int i,j=0;                      //i是控制变量,j是计数变量 
	int start,end;
	scanf("%d %d",&start,&end);     //start表起始数字,end表终止数字 
	for(i=start;i<=end;i++)         //遍历start到end的所有数字 
	{
		if((i%5==0||i%6==0)&&(i%30!=0)) //能被5或6整除但不能被5和6同时整除 
		{
		printf("%-5d ",i);         //每个数字占5个宽度,左对齐 
		j++;
	    }
	    //每输出十个有效数字就换行输出
		//防止出现未找到数字也换行的情况 
		if((j%10==0)&&(i%5==0||i%6==0)&&(i%30!=0))
		printf("n");
	}
	return 0;
}

最后

以上就是平淡灰狼最近收集整理的关于[Loops]D. Liang 4.11 Finding numbers divisible by 5 or 6, but not both.c的全部内容,更多相关[Loops]D.内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(97)

评论列表共有 0 条评论

立即
投稿
返回
顶部