Write a C program to print series of reverse number upto 1 using functions
#include<stdio.h>
#include<conio.h>
void printn(int n)
{ printf(“%d\n”,n);
if(n!=1)
{
printn(n-1);
}
}
void main()
{ int n;
clrscr();
printf(“Enter value of n:”);
scanf(“%d”,&n);
printn(n);
getch();
}
This program can also be done with the use of loop.
The code is given below using loop:
#include<stdio.h>
#include<conio.h>
void printn(int n);
void main()
{ int n;
clrscr();
printf(“Enter value of n:”);
scanf(“%d”,&n);
printn(n);
getch();
}
void printn(int n)
{ int i;
for(i=n;i>=1;i–)
{ printf(“%d”,i);
}
}
Output