Odd numbers Program in C/C++

Source code in C and C++ language to generate odd numbers. The programming logic is very simple, define and initialize the variable in this case variable name is “num”. To generate the even numbers start the loop from 1, increment num by 2 and terminate the loop on condition num < = 100.

C Source Code

   1:  #include <stdio.h>
   2:  #include <conio.h>
   3:  void main ()
   4:  {
   5:  clrscr();
   6:  int num=0;
   7:  for (num=1;num<=100;num=num+2)
   8:  {
   9:  printf("%d,", num);
  10:  }
  11:  getch ();
  12:  }

 

C++ Source Code

   1:  #include <iostream.h>
   2:  #include <conio.h>
   3:  void main ()
   4:  {
   5:  clrscr();
   6:  int num=0;
   7:  for (num=1;num<=100;num=num+2)
   8:  {
   9:  cout<<num<<",";
  10:  }
  11:  getch ();
  12:  }

 

Output

image

Be Sociable, Share!

One response to Odd numbers Program in C/C++

Leave a Reply