Tuesday, July 16, 2019

(TCSNINJA)Write a program to print the following the series(1 odd,2 even,3 odd,4 even....

/* write a program to print the following the series(1 odd,2 even,3 odd,4 even....)
i/p:4
o/p:1 2 4 5 7 9 10 12 14 16 */
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int n,i,lst=1,j,k,ecnt,ocnt;
clrscr();
scanf("%d",&n);
for(i=1;i<=n;i++)
   {
   if(i%2!=0)
      {
      ocnt=1;
for(ocnt=1;ocnt<=i;)
{
if(lst%2!=0)
printf(" %d",lst,ocnt++);
lst++;
}
printf("\n");

       }
    else
       {
      ecnt=1;
for(ecnt=1;ecnt<=i;)
{
if(lst%2==0)
printf(" %d",lst,ecnt++);
lst++;
}

printf("\n");

       }
    }
    getch();
  }

No comments:

Post a Comment