C program to check if the given number is a natural number | Coding safari

preview_player
Показать описание
Write a c program to check if the given number is a natural number | Coding safari

In this C programming tutorial, we present a simple program to check if a given number is a natural number. The user is prompted to enter a number, and the program determines if it is greater than zero. By utilizing conditional statements, it provides a clear output indicating whether the number is a natural number or not. Join us to understand the concept of natural numbers and enhance your coding skills with this easy-to-follow program.

Related Queries:-
conditional statements
natural number
if else programs
c language
c programming
programming in c
c programming language
c programming for beginners
learn c programming
c programming basics
programming in english
beginner-friendly programming
practice programs
c programming tutorial
step-by-step programming guide
hands-on coding
programming skills
code development
c programming full course
c programming language tutorial
fundamental concept
c programming hindi
c programming loops
clean code
c programming basics
c programming examples
coding education
c programming first program
c programming tutorial in hindi
visual studio code
c programming tutorial
c programs
c programming syntax
programming concepts
programming tutorials,

#cprogramming
#clanguage
#cprograms
#practiceprograms
#ctutorials
#visualstudiocode
#cprogrammingtutorials
#cprogrammingexamples
#basiccprogramming
#cprogrammingpractice
#cprogrammingexercises
#cprogrammingconcepts
#cprogramminginterviewquestions
#learncprogrammingfromscratch
#cprogrammingbasics
#cprogrammingforbeginners
#codingtutorials
Рекомендации по теме
Комментарии
Автор

This updated code handles the decimal edge case also! 🙌

#include <stdio.h>

int main() {
float number;

printf("Enter a number: ");
scanf("%f", &number);

// Check if the number is a natural number.
if (number > 0 && number == (int)number) { // checks if the number has no decimal
printf("%.2f is a natural number.\n", number);
} else {
printf("%.2f is not a natural number.\n", number);
}

return 0;
}

coding_safari
Автор

it is wrong because when we give 1.1 or any decimal as input it will give natural number as out put which is not an natural number( because of typescript)

Krishna-lnol
welcome to shbcf.ru