Showing posts with label Series of Simple Program. Show all posts
Showing posts with label Series of Simple Program. Show all posts

Monday, July 1, 2019

Program to verify a given number is ODD or EVEN using C Program

Program to validate a given number.  In case the number is divisible by 2 without any remainders then the number is EVEN number.  Else the number is ODD number.

#include <stdio.h>
int main()
{
    int realnumber;
    printf("Enter a real numer: ");
    scanf("%d", &realnumber);
   
    // Below if condition return TRUE in case the number is perfectly divisible by 2
    // Else it return FALSE
    if(realnumber % 2 == 0)
        printf("%d is even.", realnumber);
    else
        printf("%d is odd.", realnumber);
    return 0;
}

Output:

Enter a real numer: 10                                                                                                       
10 is even. 

Enter a real numer: 5                                                                                                       
5 is odd. 





Factorial program using C Language

Factorial is a mathematical way of multiplying the numbers.

4! => 4 x 3 x 2 x 1 => 24
10 ! => 10 x 9 x 8 x 7 x 6 x 5 x 4 x 3 x 2 x 1 => 3628800


#include<stdio.h>
int main() 

int i,factorial=1,input; 
printf("Enter a number to Find Factorial?"); 
scanf("%d",&input); 
        for(i=1; i<=input; i++){ 
factorial=factorial*i; 


printf("Factorial of %d is: %d",input,factorial); 
return 0;
}

Output:

Enter a number to Find Factorial?10                                                                                         
Factorial of 10 is: 3628800

Enter a number to Find Factorial?5                                                                                         
Factorial of 5 is: 120

Program to swap two numbers without using third variable using C

Program to swap two numbers without using third variable:

#include <stdio.h>
int main()   
{   
    int number1=15, number2=25;     
    printf("Intially number1=%d number2=%d",number1,number2);     
    number1=number1+number2;//number1=40 (15+25)   
    number2=number1-number2;//number2=15 (40-25)   
    number1=number1-number2;//number1=25 (40-15)   
    printf("\nAfter swap number1=%d number2=%d",number1,number2);   
    return 0; 
}

Output:
Intially number1=15 number2=25                                                                                               
After swap number1=25 number2=15






Hello World in C

Program:
#include <stdio.h>

int main()
{
    printf("Hello World");

    return 0;
}

Output:
Hello World

Popular Posts