R4R
Right Place For Right Person TM
 
R4R C C ExamplesPrint all even numbers from 1 to 100
previous

Home

Next

Learn C with example

Print all even numbers from 1 to 100

In this program we are going to explain how you can print all even numbers from 1 to 100.

Here we are including two header files stdio.h and conio.h .To include these files we are using #include<stdio.h> and # include<conio.h> .Here we are using one predefined function .That is main() method. The return type of this function is void .That mean this method does not return any value.This method is necessary  to execute any C program. Nearly all languages must have a main() method which execute first by complier.

In this we are using three more methods .These are clrscr(), printf("") and getch().The clrscr() method is used to clear the screen ,the printf ("") is used to print messages or values on screen e.g. in this example printf("Print all even numbers from 1 to 100\n"); is used to print Print all even numbers from 1 to 100 on screen. In the printf() method we are also using \n for new line. This mean the next value will print at new line.The getch() method is used to get character from keyboard.

In this we are using for loop to iterate from 1 to 100 and if is used to check the condition(values from 1 to 100 is divisible by two or not).

Here in example we are declaring int i as integer type. Then we call clrscr() function to clear the screen. Then print the messages and using for loop iterate from 1 to 100 .In for loop we also checking the divisibility by two by checking modulo is equals to Zero or not. As we know when any number is divisible by two then its remainders Zero .And modular operator is used to check remainder. So we are checking the remainder in if (i%2==0).If it is Zero it mean number  is drivable by 2(So print the number )otherwise the number is not divisible by 2 .


/*Print all even numbers from 1 to 100 */
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
clrscr();
printf("Print  all even numbers from 1 to 100\n");
printf("Even Numbers are:\n");
for(i=1;i<=100;i++)
{
 if(i%2==0)
 printf("%d ",i);
}
getch();
}

Output Of Example

Print all even numbers from 1 to 100
Even Numbers are:
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56
58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100
previous

Home

Next


Tolal:0 Click:
Show All Comments

Post Your Comments

Your Name:

Your Email ID :
Comments :
URL
  =* Enter SUM

New Updates

10:New Updates
Tutorials,examples and Interview Questions with answers
Posted By: Shashi     Posted Date:02.10.14

9:C# Tutorials,C# examples and C# Interview Questions with answers
R4R provide C# Tutorials,C# examples and C# Interview Questions with answers. Through R4R you can develop a small application and small programs.We cover C# Tutorials,C# examples and C# Interview Questions and answers for freshers as well experienced programmer.
Posted By: Shashi     Posted Date:11.17.13

8:Java/J2EE(Servlet,JSP,JNDI,Struts,Spring,Hibernate,EJB,JSF,JMS,Web-Services)
In this section R4R covers Java/J2EE(Servlet,JSP, JNDI, Struts, Spring, Hibernate, EJB,JSF,JMS,Web-Services) Tutorials with Examples.R4R provide Java/J2EE (Servlet,JSP, JNDI,Struts, Spring, Hibernate, EJB, JSF, JMS, Web-Services) Interview Questions with answers study materials for freshers and experienced.
Posted By: Shashi     Posted Date:11.13.13

7:CoreJava Tutorials , CoreJava Examples and CoreJava Interview Questions with answers
In this section R4R covers CoreJava Tutorials with CoreJava Examples. R4R covers CoreJava programming concept in easy way. R4R provide CoreJava Interview Questions with answers study materials for freshers and experienced.
Posted By: Shashi     Posted Date:11.04.13

6:Microsoft.net Technology ASP.NET,c# ,ADO.NET,WCF,WPF,Silverlight ,VB.net
R4R provides Microsoft Technologies(like ASP.NET,c# ,ADO.NET,WCF,WPF, Silverlight and VB.ne)Tutorials with Examples,programming concept and Interview Questions with answers study materials for freshers and experienced.
Posted By: Shashi     Posted Date:11.04.13

5:J2me Tutorials concept with Examples with Netbean IDE and J2ME Application Examples.
R4R cover basic J2me Tutorials concept with Examples and provide a way to develop J2me programming concept in easy way. R4R provide J2me Interview Questions with answers.R4R provide J2me Languages study materials with examples uing Netbean IDE and J2ME Application Examples.
Posted By: Shashi     Posted Date:10.30.13

4:J2me Tutorials concept with Examples ith netbean IDE and J2ME Application Examples.
R4R cover basic J2me Tutorials concept with Examples and provide a way to develop J2me programming concept in easy way. R4R provide J2me Interview Questions with answers.R4R provide J2me Languages study materials with examples uing Netbean IDE and J2ME Application Examples.
Posted By: Shashi     Posted Date:10.30.13

3:Java ebooks , Java tutorials , Java examples , Java interview questions and answers
R4R provides study materials for Java/j2EE technologies. R4R covers core java, advanced java, servlet, JSP, Struts, Spring, Hibernate, EJB, JSF, J2ME, ANT, JUnit and Some APIS .R4R also provides ebooks,tutorials,examples, interview questions and answers.
Posted By: Shashi     Posted Date:10.30.13

2:Learn basic C++ Tutorials with Examples , C++ Interview Questions with answers
R4R is a free E-learning website.You can learn basic C++ Tutorials with Examples , C++ Interview Questions with answers and also some hot topics.
Posted By: Shashi     Posted Date:10.30.13

1:C Tutorials with Example C subjective and objective interview questions and answers
R4R provide C Tutorials with Example and also provides C subjective and objective interview questions and answers.You can learn C in easy way.We cover basics of C here and give some examples.
Posted By: Shashi     Posted Date:10.30.13

Topics

R4R
R4R
R4R
R4R
R4R
R4R
R4R
R4R