概述
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. Liang 4.11 Finding numbers divisible by 5 or 6, but not both.c所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复