本文主要是介绍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的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!