pages

Sunday, 28 March 2021

c-program to find all the factors of n natural number in c-language.

c-program to  find all the factor of  n natural number 

The numbers that are completely divisible by the given value (it means the remainder should be 0) called factors of a given number in c. lets us see how to write a program in c-program

In this program ,we will calculate the factor of  a number by taking value by the user and display the factor of the number .

Alogrithm

1. input number from the user . store it in variable 'n'.

2. run a loop form 1 to n , increment 1 in each iteration. for(i=1;i<=-n;i++);

3. for each iteration ,it check the condition i,e if(n%i==0)  then i is  a factor of n.



#include<stdio.h>
#include<conio.h>
void main()
{
    int i,n;
    printf("enter the number");
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        if(n%i==0)
        printf("%d ",i);
    }
    getch();
}

output:- n=36
  
  1,2,3,4,6,9.12,18,36


For more c-programming example:-

.c-program to calculate the sum of the two numbers












Program to check weather a number is odd or even in c-language.

 c- program to check weather a number is odd or even 

   In this program , we will now taking input form the user and check weather the number is even or odd in c-programming.

If the number is  divisible by 2 is called even number and if the number is not divisible by 2 is called odd number . In the If condition ,if (n%2==0) then condition is  ture so print the even number otherwise condition is false than print odd  .

#incude<stdio.h>
#include<conio.h>
main()
{
    int x;
    printf("enter a number");
    scanf("%d",&x);
    if(x%2==0)
        printf("%d is even number",x);
    else
        printf("%d is odd number",x);
    getch();
}

output:- enter a number x=24 
               even number 


For more c-programming example:-

.c-program to calculate the sum of the two numbers

.