【C语言】找出1000以内可以被3整除的数
分别用while,do-while,for语句实现
方法一:while
#include<stdio.h> int main() { int m; m = 1; while (m<=1000) { if (m % 3 == 0) printf("%5d", m); m = m + 1; } }
方法二:do-whlie
#include<stdio.h> int main() { int m; m = 1; do { if (m % 3 == 0) printf("%5d", m); m = m + 1; } while (m <= 1000); }
方法三:for
#include<stdio.h> int main() { int m; for (m = 1; m <= 1000; m = m + 1) if (m % 3 == 0) printf("%5d", m); }
本文来自博客园,作者:木子欢儿,转载请注明原文链接:https://www.cnblogs.com/HGNET/p/11834199.html