Skip to main content

Posts

Showing posts from January, 2019

write a c program to find positive or negative number.

In this example, you will learn to check whether a number (entered by the user) is negative or positive. Example : Check if a Number is Positive or Negative Using Nested if...else #include <stdio.h> int main () { double number ; printf ( "Enter a number: " ); scanf ( "%lf" , & number ); // true if number is less than 0 if ( number < 0.0 ) printf ( "You entered a negative number." ); // true if number is greater than 0 else if ( number > 0.0 ) printf ( "You entered a positive number." ); // if both test expression is evaluated to false else printf ( "You entered 0." ); return 0 ; } Example 2: Check if a Number is Positive or Negative Using if...else #include <stdio.h> int main () { double number ; printf ( "Enter a number: " ); scanf ( "%lf" , & number ); if ...

C Program to Display Factors of a Number

Example to find all factors of an integer (entered by the user) using for loop and if statement. To understand this example, you should have the knowledge of following  C programming    topics: # if -else ststement,for loop. this code id given blow #include<stdio.h> int main() { int num i; printf("Enter the number: "); scanf("%d",& num); for(i=1;i<num;++i) {     if(num%i==0) {         printf("\n%d",i);     } } return 0; } code block pic  results passive  number =120 Factors of 120 are: 1 2 3 4 5 6 8 10 12 15 20 24 30 40 60