C program to print following numbers series 1 2 3 6 9 18 27 54 81...

Ex: write a C program to print following series 1 2 3 6 9 18 27 54 81. How to write a C program to print following series 1 2 3 6 9 18 27 54 81.. C program to print following series 1 2 3 6 9 18 27 54 81..


Input from user:
Enter the number: 8

Expected output:
1 2 3 6 9 18 27 54 .....






Program:

#include<stdio.h>
void main()
{
int i,no,z=1,k;
printf("Enter the number:\n");
scanf("%d",&no);
for(i=1;i<=no;i++)
{
if(i<=3)
{
printf("%d ",i);
z=i;
}
   else if(z%2==1)
{
k=z;
z=z*2;
printf("%d ",z);
}
  else if(z%2==0)
{
z=z+k;
printf("%d ",z);
}
}
}

Above program shows the following output:

C program to print following numbers series 1 2 3 6 9 18 27 54 81...





No comments:

Post a Comment

If you have any doubts, please discuss here...👇