编写程序。输出[1,1000]范围内能被3整除但不能被5整除的所有数据,并统计共有多少个这样的数据

如题所述

#include <stdio.h>

int main()

{

int i,count=0;

for (i = 1; i <= 100; i++) {

if (i % 3 == 0 && i % 5 != 0) {

printf("%d ",i);

count++;

if (count% 9== 0)printf("\n");

}

}

}

 扩展资料:

C语言书写规则:

1、一个说明或一个语句占一行。

2、用{} 括起来的部分,通常表示了程序的某一层次结构。{}一般与该结构语句的第一个字母对齐,并单独占一行。

3、低一层次的语句或说明可比高一层次的语句或说明缩进若干格后书写。以便看起来更加清晰,增加程序的可读性。在编程时应力求遵循这些规则,以养成良好的编程风格。

参考资料:

百度百科-c语言

温馨提示:答案为网友推荐,仅供参考
第1个回答  2019-05-28

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

namespace _1

{

public partial class Form1:Form

{

public Form1()

{

InitializeComponent();

}

private void Form1_Load(object sender,EventArgs e)

{

}

private void button1_Click(object sender,EventArgs e)

{

label1.Text="";

int number=0;

for(int x=1;x&lt;1000;x++)

{

if((x%3)==0&&(x%5)!=0)

{

label1.Text+=string.Format("{0,-3:D}",x)+"";

number++;

}

if(number%5==0){label1.Text+="\n";}

}

}

}

}

运行效果:

扩展资料:

system()函数

windows操作系统下system()函数详解(主要是在C语言中的应用)

功能:发出一个DOS命令

用法:int system(char*command);

system函数已经被收录在标准c库中,可以直接调用

程序例:

#include&lt;stdlib.h&gt;

#include&lt;stdio.h&gt;

int main(void)

{

printf("About to spawn and run a DOS command\n");

system("dir");

return 0;

}

又如:system("pause")可以实现冻结屏幕,便于观察程序的执行结果;system("CLS")可以实现清屏操作。而调用color函数可以改变控制台的前景色和背景,具体参数在下面说明。

例如,用system("color 0A");其中color后面的0是背景色代号,A是前景色代号。各颜色代码如下:

0=黑色1=蓝色2=绿色3=湖蓝色4=红色5=紫色6=黄色7=白色8=灰色9=淡蓝色A=淡绿色B=淡浅绿色C=淡红色D=淡紫色E=淡黄色F=亮白色

(注意:Microsoft Visual C++6.0支持system)

本回答被网友采纳
第2个回答  2018-11-29

本回答被提问者采纳
第3个回答  2018-11-29
package test;
public class MathController {

public static void main(String[] args) {
int count = 0;
for (int i = 1; i <= 1000; i++) {
if(i % 3 == 0 && i % 5 != 0) {
System.out.println(i);
count++;
}
}
System.out.println("满足条件的数量为:"+count);
}
}本回答被网友采纳
相似回答