打印系列的前N个项(0.25、0.5、0.75,…)的分数表示形式

打印系列的前n个项(0.25、0.5、0.75,...)的分数表示形式

输入N,它等于要打印系列的最大数

Input : N=5Output : 0 ¼ ½ ¾ 1

算法

STARTStep 1 -> declare start variables as int num , den, i, nStep 2 -> input number in nStep 3 -> Loop For from i to 0 and i End For LoopSTOP

示例

#include int main(int argc, char const *argv[]) {   int num, den;   int i, n;   printf("Enter series limit

"); scanf("%d", &n); //Till where the series will be starting from zero for (i = 0; i < n; i++) { if (i%2==0) { //Checking the numerator is odd or even if(i%4==0) { //If the numerator divisible by 4 divide it num = i/4; den = 0; } else {//if not divisible by 4 its even number divisible by 2 num = i/2; den = 2; } } else { //Assigning numerator and denominator value if the number is odd num = i; den = 4; } if (den != 0) { //if denominator is not zero then print in fraaction form printf("%d/%d

",num, den); } else //else print in a normal number form printf("%d

", num); } return 0;}

输出

如果我们运行上述程序,它将生成以下输出

Enter series limit501/41/23/41

以上就是打印系列的前N个项(0.25、0.5、0.75,…)的分数表示形式的详细内容,更多请关注创想鸟其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1445406.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2025年12月17日 22:29:52
下一篇 2025年12月17日 22:30:00

相关推荐

发表回复

登录后才能评论
关注微信