> How do I write this program in C?

How do I write this program in C?

Posted at: 2014-12-18 
I have to print all the even numbers less than a given number like this.

Say if the given number is: 9

the output would look like

2

2=4

2=4=6

2=4=6=8

Use a for loop from 1 to the given number.

Use the mod operator with 2. If it gives a result of 0, the number is even. If it gives a 1 it is odd.

The mod operator gives the remainder when doing integer division.

5 % 2 = 1

4 % 2 = 0

so your pseudo code might look like this

ask user for input

begin loop from one to input

if the loop_number mod 2 equals 0 then

print and " = " and the loop_number

no mod needed just step by 2

look up the ?: operator. made it easy....

#include

int main(void){

int n,p,j;

n=8;

for(p=2;p<=n;p+=2)

for(j=2;j<=p;j+=2)

printf("%d%c",j,j==p?'\n':'=');

return 0;

}

I have to print all the even numbers less than a given number like this.

Say if the given number is: 9

the output would look like

2

2=4

2=4=6

2=4=6=8