{"id":950,"date":"2021-11-10T09:43:22","date_gmt":"2021-11-10T09:43:22","guid":{"rendered":"https:\/\/ethosspace.com\/programmers\/?p=950"},"modified":"2021-11-11T08:41:52","modified_gmt":"2021-11-11T08:41:52","slug":"how-to-generate-the-series-1-3-6-11-18-29-42-up-to-n-number-in-c-program","status":"publish","type":"post","link":"https:\/\/ethosspace.com\/programmers\/how-to-generate-the-series-1-3-6-11-18-29-42-up-to-n-number-in-c-program\/","title":{"rendered":"How to generate the series 1, 3, 6, 11, 18, 29, 42? up to N number in C Program"},"content":{"rendered":"\n<p>To generate series 1, 3, 6, 11, 18, 29, 42? in C Language it is important to understand the logic behind it. If we observe the difference between each number is like 2,3,7,11. So these are prime numbers. To generate such a series it is important that the difference between numbers should be an incremental prime number. So below program will generate a series up to user input by having prime number difference.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-c\" data-lang=\"C\"><code>\/\/ Online C Program to generate Series up to Number\n\/\/ 1, 3, 6, 11, 18, 29, 42?\n#include &lt;stdio.h&gt;\nint main() {\n    \/\/variable declaration\n    int i,j,num,primeFlag,seriesNum,Scount;\n    printf(&quot;\\n how many numbers you need in this Series 1, 3, 6, 11, 18, 29, 42? to Print\\n&quot;);\n    scanf(&quot;%d&quot;,&num);\n    \/\/for loop to print numbers\n    seriesNum =1; \/\/This variable to store number from series.\n    Scount=1; \/\/variable to check count of numbers in series.\n    printf(&quot;\\t%d&quot;,seriesNum);\n    do\n    {\n        primeFlag=0; \/\/flag to check if number is prime or not.\n        i= i+1;\n        \/\/loop to find prime number and add it to previous\n        for(j=1;j&lt;=i;j++)\n        {\n            if((i%j)==0)\n            {\n                primeFlag++;\n            }\n            else\n            {\n               \/\/continue\n            }\n        }\n        if (primeFlag == 2)\n        {\n\/\/here if number is divisible by 1 and self number then only primeFlag will become 2\n            seriesNum = seriesNum + i;\n            printf(&quot; %d,&quot;,seriesNum);\n            Scount = Scount + 1;\n        }\n    }while (Scount &lt; num);\n    return 0;\n}<\/code><\/pre><\/div>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>how many numbers you need in this Series 1, 3, 6, 11, 18, 29, 42? to Print\n22\n1 3, 6, 11, 18, 29, 42, 59, 78, 101, 130, 161, 198, 239, 282, 329, 382, 441, 502, 569, 640, 713,<\/code><\/pre><\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>To generate series 1, 3, 6, 11, 18, 29, 42? in C Language it is important to understand the logic behind it. If we observe the difference between each number is like 2,3,7,11. So these are prime numbers. To generate such a series it is important that the difference between numbers should be an incremental [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","footnotes":""},"categories":[6],"tags":[],"class_list":["post-950","post","type-post","status-publish","format-standard","hentry","category-c-language"],"aioseo_notices":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"sparkling-featured":false,"sparkling-featured-fullwidth":false,"tab-small":false},"uagb_author_info":{"display_name":"program45_-rt8nb","author_link":"https:\/\/ethosspace.com\/programmers\/author\/program45_-rt8nb\/"},"uagb_comment_info":6,"uagb_excerpt":"To generate series 1, 3, 6, 11, 18, 29, 42? in C Language it is important to understand the logic behind it. If we observe the difference between each number is like 2,3,7,11. So these are prime numbers. To generate such a series it is important that the difference between numbers should be an incremental&hellip;","_links":{"self":[{"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/posts\/950","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/comments?post=950"}],"version-history":[{"count":1,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/posts\/950\/revisions"}],"predecessor-version":[{"id":951,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/posts\/950\/revisions\/951"}],"wp:attachment":[{"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/media?parent=950"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/categories?post=950"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/tags?post=950"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}