Sunday, October 16, 2011

Problem Number 3 (Iterative Statements)

Write a program that asks the user to enter a number n and display the first even numbers. Example: if n=5, the first 5 even numbers are 2, 4, 6, 8 and 10.

     #include<stdio.h>
     #include<conio.h>
     #define p printf
     #define s scanf


     int main()
     {
         int a, b;
   
         p("Enter a number: ");
         s("%d",&\b);
   
              for ( a = 0; a <= b*2; a+=2 )
                  s("%d\n",a);
            
         getch ();
         return 0;
     }

No comments:

Post a Comment