c program print all natural numbers in reverse (from n to 1) using while loop
Answers
Answered by
5
Solution:
The given códe is written in C.
#include <stdio.h>
int main(){
int n;
printf("Enter n - ");
scanf("%d",&n);
while(n>0)
printf("%d ",n--);
return 0;
}
Logic:
- Accept the value of n from the user.
- Loop while n>0 -
- Display the value of n.
- Decrement the value of n.
See the attachment for output.
Attachments:
Similar questions
Social Sciences,
18 days ago
Math,
18 days ago
English,
18 days ago
History,
1 month ago
Math,
8 months ago
Chemistry,
8 months ago
Psychology,
8 months ago