Write a program that prints the numbers from 1 to 100,but for multiples of three print “Fizz” inste

2024-06-09 09:32

本文主要是介绍Write a program that prints the numbers from 1 to 100,but for multiples of three print “Fizz” inste,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1、问题

/*

Write a program that prints the numbers from 1 to 100,but for  multiples of three print “Fizz” instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print ”FizzBuzz“;

*/


2、算法

void foo()
{
        int m = 100 ;

        for(int i = 0; i <= m; i++)
        {
                if (i%(3*5) == 0)
                {
                        printf("FizzBuzz") ;
                }else if(i%3 == 0)
                {
                        printf("Fizz") ;
                }else if (i%5 == 0)
                {
                        printf("Buzz") ;
                }else
                {
                        printf("%d", i) ;
                }
        }
}

这篇关于Write a program that prints the numbers from 1 to 100,but for multiples of three print “Fizz” inste的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1044804

相关文章

初学WebGL,使用Three.js开发第一个3d场景示例

使用Three.js 开发3d场景   在图书馆偶然撞见《Three.js开发指南》一书,便试着捣鼓一翻,现将第一个示例的部分代码、注解和相关方法的API记录在此。因为此书发行时是Three.js r69版本,所以当前部分代码有所修改,且所有方法和参数以官方最新版本Three.js r90为准。 <!doctype html><html lang="en"><head><meta char

github 报错 git fatal: unable to write new index file

错误一:git fatal: unable to write new index file主要原因就是服务器磁盘空间不够导致的,增加服务器空间就OK了在百度上面搜索没得到什么有效信息,在gooogle上搜索得到很多有效信息 Finding large directories with something like the following helped clean up some log fi

Program-of-Thoughts(PoT):结合Python工具和CoT提升大语言模型数学推理能力

Program of Thoughts Prompting:Disentangling Computation from Reasoning for Numerical Reasoning Tasks github:https://github.com/wenhuchen/Program-of-Thoughts 一、动机 数学运算和金融方面都涉及算术推理。先前方法采用监督训练的形式,但这种方

求13x+12y=100;x+45=90的解,找到一个满足的解就行(break跳出循环)

#include<stdio.h>#include<stdlib.h>//break语句不能用在循环语句和switch语句之外的语句int main(){//x>0,y>0 ,求:x,y 且是整数 //13x+12y=100:即13i+12j=100,即12j=100-13ifor(int i=0;i<100;i++){printf("%d\n",i);if((100-13*i)%12==

调用FileOutputStream中的三种write方式

package fileoutputstream;import java.io.FileOutputStream;import java.io.IOException;//import java.io.OutputStream;public class FileOutputStreamDemo2 {public static void main(String[] args) throws I

oracle创建一个带参数的存储过程:为指定的员工,涨100块钱的工资;并且打印涨前和涨后的薪水

--创建一个带参数的存储过程--为指定的员工,涨100块钱的工资;并且打印涨前和涨后的薪水/*beginraisesalary(6755);raisesalary(4456);commit();//这里提交,所以说我们一般不会在存储过程或者存储函数中写提交,end;/*/--host cls--先创建表emp和插入数据,显示表的结构用desc 表名--create table empcr

Failed to load the JNI shared library D:\Program Files\Java\jdk1.5.0_08\bin\..\jre\bin\client\jvm.d

原因是 (外形类型向日葵) eclips要求jdk最低的版本为1.7以上

第十章 Three.js物理引擎与碰撞检测(一)

10.1 物理引擎基础 物理引擎用于模拟物体的物理行为,如重力、碰撞、摩擦力等。在 Three.js 中,我们可以使用外部物理引擎库来增强我们的 3D 场景的物理效果。常用的物理引擎有 Cannon.js、Ammo.js 和 Oimo.js。本章我们将重点介绍 Cannon.js,并展示如何将其集成到 Three.js 项目中。 10.2 使用 Cannon.js 集成物理效果 Cannon

Python-算法编程100例-前缀和双指针(入门级)-最长的指定瑕疵度的元音子串

题目描述: 元音字符为“aeiouAEIOU” 给定一个字符串,求字符串中满足指定瑕疵度的最长元音子串的长度。元音子串为字符串中开头和结尾都是元音字符的字符串,瑕疵度为子串中非元音字符的个数。 题目分析: 1、直接使用双指针,难度稍微有些大,边界不好处理。 2、使用前缀和+双指针,题目难度简化。 瑕疵度k=0原始字符串asdbuiodevauufgh元音字符到起始位置的瑕疵度00003

document.write()方法总结

document.write()方法总结 大家好,我是免费搭建查券返利机器人省钱赚佣金就用微赚淘客系统3.0的小编,也是冬天不穿秋裤,天冷也要风度的程序猿!document.write()方法是JavaScript中用于向HTML文档写入内容的方法之一。它允许我们在HTML文档加载过程中动态生成内容,包括文本、HTML标记和JavaScript代码等。 用法 document.write()