打印出在范围0-99之间缺失的元素

打印出在范围0-99之间缺失的元素

它将显示用户输入的给定集中缺失的值

Given : array = {88, 105, 3, 2, 200, 0, 10};Output : 1 4-9 11-87 89-99

登录后复制

算法

STARTSTEP 1-> Take an array with elements, bool flag[MAX] to Fale, int i, j, n to size of arrayStep 2-> Loop For from I to 0 and i=0      Set flag[array[i]]=true   End IFStep 3 -> End For LoopStep 4 -> Loop For from i to 0 and i End For LoopSTOP

登录后复制

示例

#include #define MAX 100int main(int argc, char const *argv[]) {   int array[] = {88, 105, 3, 2, 200, 0, 10};   bool flag[MAX] = { false }; //Initializing all the values of flag as false   int i, j, n;   n = sizeof(array)/sizeof(array[0]);   for (i = 0; i =0) {         flag[array[i]] = true; //Making the value of the elements present in an array as true, So missing will remain false      }   }   for (i = 0; i 

", i);         else //For printing the missing range            printf("%d-%d

", i, j-1);         i = j; //Initializing the range's last value to start from that number      }   }   return 0;}

登录后复制

输出

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

14-911-8789-99

登录后复制

以上就是打印出在范围0-99之间缺失的元素的详细内容,更多请关注【创想鸟】其它相关文章!

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

发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2583503.html

(0)
上一篇 2025年3月6日 14:35:15
下一篇 2025年3月6日 14:35:22

AD推荐 黄金广告位招租... 更多推荐

相关推荐

发表回复

登录后才能评论