C Program to print N Even numbers

Get input n and print n even numbers.

Sample Input 1:

7

Sample Output 1:

2 4 6 8 10 12 14

Program or Solution

#include<stdio.h>
int main()
{
int n,i,j;
printf("Enter a number:");
scanf("%d",&n);
printf("First %d even numbers are:\n",n);
for(j=1,i=0;j<=n;i=i+2,j++)
{
printf("%d ",i);
}
return 0;
}

Program Explanation

Instruction(s) inside the for block{} are executed repeatedly till the second expression (j<=n) is true.

Here i and j are initialized to 0 and 1 respecively.

i is incremented by 2 and j is incremented by 1.

for each iteration, instructions inside the for block are executed unless j becomes greater than n.

so value of i (0 2 4 6 8 10) (n even numbers) in each iteration will be printed using printf statement.
{"ft_lang_label":"__label__en","ft_lang_prob":0.75349534,"math_prob":0.9871176,"size":2331,"snap":"2022-05-2022-21","text_gpt3_token_len":582,"char_repetition_ratio":0.2677267,"word_repetition_ratio":0.24009325,"special_character_ratio":0.24667525,"punctuation_ratio":0.06140351,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.95648783,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-01-19T10:57:55Z\",\"WARC-Record-ID\":\"<urn:uuid:4534ef17-5d17-47fd-a238-5dd4eae564d0>\",\"Content-Length\":\"27209\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:8f6f66e8-f9c1-46b5-bf6d-51b1047b0b9a>\",\"WARC-Concurrent-To\":\"<urn:uuid:1918af2f-fb45-4015-9850-297187c41b17>\",\"WARC-IP-Address\":\"143.244.172.97\",\"WARC-Target-URI\":\"https://www.decodeschool.com/C-Programming/Looping/C-Program-to-print-N-Even-numbers\",\"WARC-Payload-Digest\":\"sha1:VLLHDDA3C6FKQ5WR7Y6T4O3RSB5UKAUT\",\"WARC-Block-Digest\":\"sha1:25BHMBO7B3BDTKOYSZZAA44QGBDLP254\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-05/CC-MAIN-2022-05_segments_1642320301309.22_warc_CC-MAIN-20220119094810-20220119124810-00017.warc.gz\"}"}