[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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值