Friday, May 31, 2019

Write a C Program to Check Positive or Negative Number

Write a C Program to Check  Positive or Negative Number

Positive Number : If Number is Greater than 0
Negative Number :  If Number is less than 0


Program:

#include<stdio.h>
#include<conio.h>

int main()
{
 int num;
 printf("Enter any number: ");
 scanf("%d", &num);
 if (num > 0)
 {
  printf("%d is a Positive number \n", num);
 }
  else if (num < 0)
  {
   printf("%d is a Negative number \n", num);
  }
  else
  {
   printf("0 is Neither Positive nor Negative");
  }
  getch();
}

Output:

Enter any number: -6
-6 is a Negative number

C Program to Print Table

Write a C Program to Print Table ?

Program:

#include<stdio.h>
#include<conio.h>

int main()
{
int i,no,table=1;

printf("Enter any number : ");
scanf("%d",&no);
printf("Table of  %d \n",no);
for(i=1;i<=10;i++)
{
table=no*i;
printf("%d",table);
printf("\n");
}
getch();
}
.....................................................................
Output:

Enter any number : 2
Table of  2
2
4
6
8
10
12
14
16
18
20

Tuesday, May 28, 2019

To Print Alphabet Triangle

Write a C Program to print Alphabet Triangle

Program:
 
  #include<stdio.h>   
    #include<stdlib.h> 
    int main(){ 
      int ch=65;   
        int i,j,k,m;   
      system("cls"); 
        for(i=1;i<=5;i++)   
        {   
            for(j=5;j>=i;j--)   
                printf(" ");   
            for(k=1;k<=i;k++)   
                printf("%c",ch++);   
                ch--;   
            for(m=1;m<i;m++)   
                printf("%c",--ch);   
            printf("\n");   
            ch=65;   
        }   
    return 0; 
    } 

Output:

    A
    ABA
   ABCBA
  ABCDCBA
 ABCDEDCBA

--------------------------------
Process exited after 0.7288 seconds with return value 0
Press any key to continue . . .

To Print Number Triangle

Write a C Program to Print Number Triangle

Program:
 
 #include<stdio.h>  
 #include<stdlib.h> 
    int main()
    { 
      int i,j,k,l,n;   
    system("cls"); 
    printf("Enter the range=");   
    scanf("%d",&n);   
    for(i=1;i<=n;i++)   
    {   
    for(j=1;j<=n-i;j++)   
    {   
    printf(" ");   
    }   
    for(k=1;k<=i;k++)   
    {   
    printf("%d",k);   
    }   
    for(l=i-1;l>=1;l--)   
    {   
    printf("%d",l);   
    }   
    printf("\n");   
    }   
    return 0; 
    } 

Output:

Enter the range=
6
     1
    121
   12321
  1234321
 123454321
12345654321

--------------------------------
Process exited after 7.007 seconds with return value 0
Press any key to continue . . .

C Program to Print Diamond Pattern

Write a C Program to Print Diamond Pattern

Program:

#include <stdio.h>
#include <conio.h>
void main()
{
    int i, j, k, space=10;
    
    for (i=0;i<=5;i++)
    {
        for (k=0;k<space;k++)
        {
        printf(" ");
        }
        for (j=0;j<2*i-1;j++)
        {
        printf("*");
        }

        space--;
        printf("\n");
    }
    getch();
}

Output:

Enter number of rows
10
         *
        ***
       *****
      *******
     *********
    ***********
   *************
  ***************
 *****************
*******************
 *****************
  ***************
   *************
    ***********
     *********
      *******
       *****
        ***
         *

--------------------------------
Process exited after 4.725 seconds with return value 0
Press any key to continue . . .

Floyd's Triangle

Write a  Program to Create Floyd's Triangle

Program:-

#include <stdio.h>

int main()
{
    int n, i,  c, a = 1;
   
    printf("Enter the number of rows of Floyd's triangle to print\n");
    scanf("%d", &n);
   
    for (i = 1; i <= n; i++)
    {
        for (c = 1; c <= i; c++)
        {       
            printf("%d ",a);
            a++;
        }
        printf("\n");
    }
   
    return 0;
}
-------------------------------------------------------------------------------
Output:

Enter the number of rows of Floyd's triangle to print
6
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
16 17 18 19 20 21

--------------------------------
Process exited after 8.383 seconds with return value 0
Press any key to continue . . .

C Program to Print Pascal Triangle

Write a C Program to Print Pascal Triangle

Program:

#include<stdio.h>

long factorial(int);

int main()
{
    int i, n, c;
   
    printf("Display Row  in pascal triangle?\n");
   
    scanf("%d",&n);
   
    for ( i = 0 ; i < n ; i++ )
    {
        for ( c = 0 ; c <= ( n - i - 2 ) ; c++ )
        printf(" ");
        for( c = 0 ; c <= i ; c++ )
            printf("%ld ",factorial(i)/(factorial(c)*factorial(i-c)));
            printf("\n");
    }
    return 0;
}

long factorial(int n)
{
    int c;   
    long result = 1;
   
    for( c = 1 ; c <= n ; c++ )
    result = result*c;
    return ( result );
}
........................................................................................................

Output:

Display Row  in pascal triangle?
10
         1
        1 1
       1 2 1
      1 3 3 1
     1 4 6 4 1
    1 5 10 10 5 1
   1 6 15 20 15 6 1
  1 7 21 35 35 21 7 1
 1 8 28 56 70 56 28 8 1
1 9 36 84 126 126 84 36 9 1

--------------------------------
Process exited after 3.11 seconds with return value 0
Press any key to continue . . .


Write a C Program to generate Fibonacci Triangle

Write a C Program to generate Fibonacci Triangle

Program:
 
  #include<stdio.h>  
    #include<stdlib.h>
    int main(){
       int a=0,b=1,i,c,n,j;  
    system("cls");
        printf("Enter the limit:");  
        scanf("%d",&n);  
        for(i=1;i<=n;i++)  
        {  
            a=0;  
            b=1;  
            printf("%d\t",b);  
            for(j=1;j<i;j++)  
            {  
                c=a+b;  
                printf("%d\t",c);  
                a=b;  
                b=c;  
      
            }  
            printf("\n");  
        }  
    return 0;
    }
...............................................................................................................
Output:

Enter the limit:6
1
1       1
1       1       2
1       1       2       3
1       1       2       3       5
1       1       2       3       5       8

--------------------------------
Process exited after 6.162 seconds with return value 0
Press any key to continue . . .





Monday, May 27, 2019

To Calculate the Power of a Number

Write a C Program to Calculate the Power of a Number using While Loop

Program:

#include <stdio.h>
int main()
{
    int base, exponent;

    long long result = 1;

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

    printf("Enter an exponent: ");
    scanf("%d", &exponent);

    while (exponent != 0)
    {
        result *= base;
        --exponent;
    }

    printf("Answer = %lld", result);

    return 0;
}

Output:

Enter a base number: 2
Enter an exponent: 4
Answer = 16
--------------------------------
Process exited after 11.73 seconds with return value 0
Press any key to continue . . .

Program to Print ASCII Value

Write a C Program to find ASCII Value of a Character

Program:

#include <stdio.h>
int main()
{
    char c;
    printf("Enter a character: ");
    scanf("%c", &c); 
    printf("ASCII value of %c = %d", c, c);
    return 0;
}

 d : the integer value of a character
 c :  the actual character

Output:

Enter a character: G
ASCII value of G = 71
--------------------------------
Process exited after 4.356 seconds with return value 0
Press any key to continue . . .

Program to Check Vowel or consonant

Write a C Program to Check Vowel or consonant

Program: -

#include <stdio.h>
int main()
{
    char c;
    int isLowercaseVowel, isUppercaseVowel;

    printf("Enter an alphabet: ");
    scanf("%c",&c);

    // evaluates to 1 (true) if c is a lowercase vowel
    isLowercaseVowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');

    // evaluates to 1 (true) if c is an uppercase vowel
    isUppercaseVowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');

    // evaluates to 1 (true) if either isLowercaseVowel or isUppercaseVowel is true
    if (isLowercaseVowel || isUppercaseVowel)
        printf("%c is a vowel.", c);
    else
        printf("%c is a consonant.", c);
    return 0;
}
----------------------------------------------------------------------------------------

Output:

Enter an alphabet: a
a is a vowel.
--------------------------------
Process exited after 3.779 seconds with return value 0
Press any key to continue . . .

A Character is an Alphabet or not

C Program to Check Whether a Character is an Alphabet or not

Program:

#include <stdio.h>
int main()
{
    char c;
    printf("Enter a character: ");
    scanf("%c",&c);

    if( (c>='a' && c<='z') || (c>='A' && c<='Z'))
        printf("%c is an alphabet.",c);
    else
        printf("%c is not an alphabet.",c);

    return 0;

}
---------------------------------------------------------------------------
Output:

Enter a character: g
g is an alphabet.
--------------------------------
Process exited after 3.156 seconds with return value 0
Press any key to continue . . .

C Program to Check Leap Year

Write a C Program to Check Leap Year ?


Program:

#include <stdio.h>

int main()
{
    int year;

    printf("Enter a year: ");
    scanf("%d",&year);

    if(year%4 == 0)
    {
        if( year%100 == 0)
        {
            // When the year is divisible by 400,  year is a leap year
            if ( year%400 == 0)
                printf("%d is a leap year.", year);
            else
                printf("%d is not a leap year.", year);
        }
        else
            printf("%d is a leap year.", year );
    }
    else
        printf("%d is not a leap year.", year);
   
    return 0;
}

Output:

Enter a year: 1992
1992 is a leap year.
--------------------------------
Process exited after 5.863 seconds with return value 0
Press any key to continue . . .

Display Armstrong Number Between Two Intervals

Write C Program to Display Armstrong Number Between Two Intervals

Program:

#include <stdio.h>
#include <math.h>

int main()
{
    int low, high, i, temp1, temp2, remainder, n = 0, result = 0;

    printf("Enter two numbers(intervals): ");
    scanf("%d %d", &low, &high);
    printf("Armstrong numbers between %d an %d are: ", low, high);

    for(i = low + 1; i < high; ++i)
    {
        temp2 = i;
        temp1 = i;

        // number of digits calculation
        while (temp1 != 0)
        {
            temp1 /= 10;
            ++n;
        }
        while (temp2 != 0)
        {
            remainder = temp2 % 10;
            result += pow(remainder, n);
            temp2 /= 10;
        }

        if (result == i) {
            printf("%d ", i);
        }

        n = 0;
        result = 0;

    }
    return 0;
}
-----------------------------------------------------------------------------------------

Output:

Enter two numbers(intervals): 999
9999
Armstrong numbers between 999 an 9999 are: 1634 8208 9474
--------------------------------
Process exited after 8.244 seconds with return value 0
Press any key to continue . . .


Write a C Program to Count Number of Digits in an Integer

Write a C Program to Count Number of Digits in an Integer

Program:

#include <stdio.h>
int main()
{
    long long n;
    int count = 0;

    printf("Enter an integer: ");
    scanf("%lld", &n);

    while(n != 0)
    {
        // n = n/10
        n /= 10;
        ++count;
    }

    printf("Number of digits: %d", count);
}
---------------------------------------------------------------------------
Output

Enter an integer: 56789
Number of digits: 5
--------------------------------
Process exited after 5.369 seconds with return value 0
Press any key to continue . . .

Saturday, May 25, 2019

NIT, Calicut Recruitment of Ad-hoc Faculty 2019

NATIONAL INSTITUTE OF TECHNOLOGY CALI CUT Ad-hoc/Temporary Faculty Recruitment June-July, 2019 .NIT, Calicut are invited for the post of Adhoc Faculty in Architecture& Planning,
Biotechnology, Civil Engineering, Chemical Engineering, Computer Science & Engineering,
Electrical Engineering, Electronics & Communication Engineering, Mechanical Engineering,
Material Science & Engineering, Mathematics, Physics, Chemistry, Economics, Management,
English, German, and French on temporary basis with a consolidated remuneration (Rs. 50,000
per month for Ph.D./Rs. 40,000 per month for M.Tech./M.Arch./M.Planning).

The appointment will be for a period of one semester beginning in July 2019.

HOW TO APPLY:

Applications  scanned copy of UG, PG and Ph.D. degree
mark lists/ certificates should reach by e-mail to the Head of the Departments/Schools.

Important Date: -

Last Date for online Application Form :  06-06-2019

Selected candidates will be informed by e-mail/mobile and they are expected to join
immediately, preferably by 22ndJuly 2019.



Click here to Download  : Notification of  Ad-hoc/Temporary Faculty Recruitment

Click here to Download :  Information Brochure
Click here to Download : Application form





Official Website : National Institute of Technology Calicut (NITC)




NABARD Recruitment for the Post of Manager in Grade 'B' (RDBS) - 2019

National Bank for Agriculture & Rural Development (NABARD) Recruitment to the post of Manager in Grade `B' (RDBS)-2019

NABARD Recruitment  for the post of Manager in Grade ‘B’ in the Rural
Development Banking Service (RDBS) in National Bank for Agriculture
and Rural Development (NABARD).
Candidates can Apply Only ON-LINE on NABARD  through Bank’s website www.nabard.org.
No other mode of submission of application will be accepted by NABARD.
between 10 May 2019 and 26 May 2019.

1. NUMBER OF VACANCIES :

No. Post Number of Vacancies

Manager (RDBS)        UR    SC   ST     OBC  EWS  PWBD    Total
 General                       4        1      --         3     --        --             8

SELECTION PROCEDURE:

The selection will be in three Phases as  below:

1. Phase I  –  Preliminary Examination (Online Exam)
2. Phase II  – Main Examination will be online and will be a mix of MCQ
                     and descriptive   pattern.
3. Phase III – Interview

Important Dates:

Phase I (Preliminary) – Online Examination  16 June 2019
On-line Registration of Application Date       10/05/2019
Closure of Registraion of Application Date    26/05/2019
Closure for Editing Application Details          26/05/2019
Last date for Printing your Application          10/06/2019
Online Fee Payment                                        10/05/2019 to 26/05/2019

Click Here to Apply Online : The Post of Officers in Grade 'B' (RDBS)

Click here to Download Syllabus : The post of Manager in Grade `B' (RDBS)

Click here to View Notification : Recruitment to the post of Manager in Grade `B' (RDBS)



Official Site Link:- National Bank for Agriculture & Rural Development (NABARD)

Thursday, May 23, 2019

To convert Binary to Decimal

Write a C Program to Convert Binary to Decimal Number System

Program:-

#include <stdio.h>
#include <math.h>
int binaryToDecimal(long binarynum)
{
    int decimalnum = 0, temp = 0, remainder;
    while (binarynum!=0)
    {
        remainder = binarynum % 10;
        binarynum = binarynum / 10;
        decimalnum = decimalnum + remainder*pow(2,temp);
        temp++;
    }
    return decimalnum;
}

int main()
{
    long binarynum;
    printf("Enter a Binary Number: ");
    scanf("%ld", &binarynum);

    printf("Equivalent decimal number is: %d", binaryToDecimal(binarynum));
    return 0;
}

Output:-

Enter a Binary Number: 110011
Equivalent decimal number is: 51
--------------------------------
Process exited after 20.4 seconds with return value 0
Press any key to continue . . .


C Program to convert Binary to Octal

Write a C Program to Convert Binary to Octal Number System:

Program:-

#include <stdio.h>
#include <math.h>

int binaryToOctal(long binarynum)
{
    int octalnum = 0, decimalnum = 0, i = 0;

  
    while(binarynum != 0)
    {
        decimalnum = decimalnum + (binarynum%10) * pow(2,i);
        i++;
        binarynum = binarynum / 10;
    }

    //i is re-initialized
    i = 1;

  
    while (decimalnum != 0)
    {
        octalnum = octalnum + (decimalnum % 8) * i;
        decimalnum = decimalnum / 8;
        i = i * 10;
    }

    return octalnum;
}
int main()
{
    long binarynum;

    printf("Enter a binary number: ");
    scanf("%ld", &binarynum);

    printf("Equivalent octal value: %d", binaryToOctal(binarynum));

    return 0;
}
------------------------------------------------------------------------------------------

Output:

Enter a binary number: 111001
Equivalent octal value: 71
--------------------------------
Process exited after 35.61 seconds with return value 0
Press any key to continue . . .

Bubble Sorting in c

Program:
#include<stdio.h>

int main(){

   int count, temp, i, j, number[30];

   printf("How many numbers are u going to enter: ");
   scanf("%d",&count);

   printf("Enter %d numbers: ",count);

   for(i=0;i<count;i++)
   scanf("%d",&number[i]);

   /* This is the main logic of bubble sort algorithm
    */
   for(i=count-2;i>=0;i--){
      for(j=0;j<=i;j++){
        if(number[j]>number[j+1]){
           temp=number[j];
           number[j]=number[j+1];
           number[j+1]=temp;
        }
      }
   }

   printf("Sorted elements: ");
   for(i=0;i<count;i++)
      printf(" %d",number[i]);

   return 0;
}

Output:-

How many numbers are u going to enter: 5
Enter 5 numbers: 42
22
12
65
30
Sorted elements:  12 22 30 42 65
--------------------------------
Process exited after 25.23 seconds with return value 0
Press any key to continue . . .

V B S Purvanchal University, Jaunpur PG Result Session 2018-19 Declared

Veer Bahadur Singh Purvanchal University, Jaunpur Post Graduate Result of

Regular/Private Students (Session 2018-2019) -

Click Here to View PG Result:-

M.A. First Year
M.A. Final Year


M.Com. First Year
M.Com. Final Year

M.Sc. First Year
M.Sc. Final Year

M.Sc. (Agriculture) First Year
M.Sc. (Agriculture) Final Year



Site Link:- Veer Bahadur Singh Purvanchal University, Jaunpur

V B S Purvanchal University, Jaunpur UG Result 2018-19 Declared

Tuesday, May 21, 2019

To Calculate Area and Circumference of Circle

Write a C  Program to calculate Area and Circumference of Circle

Formula used:-
Area = 3.14 * radius * radius
Circumference = 2 * 3.14 * radius


Program:

#include <stdio.h>
int main()
{
   int circle_radius;
   float PI_VALUE=3.14, circle_area, circle_circumf;

   //Ask user to enter the radius of circle
   printf("\nEnter radius of circle: ");
   //Storing the user input into variable circle_radius
   scanf("%d",&circle_radius);

   //Calculate and display Area
   circle_area = PI_VALUE * circle_radius * circle_radius;
   printf("\nArea of circle is: %f",circle_area);

   //Caluclate and display Circumference
   circle_circumf = 2 * PI_VALUE * circle_radius;
   printf("\nCircumference of circle is: %f",circle_circumf);

   return(0);
}

Output:-
Enter radius of circle: 2

Area of circle is: 12.560000
Circumference of circle is: 12.560000
--------------------------------
Process exited after 6.685 seconds with return value 0
Press any key to continue . . .

Program to calculate Area

Write a C program to find area of equilateral triangle

Formula used in the program: 
Area = sqrt(3)/4 * side * side

program:

#include<stdio.h>
#include<math.h>
int main()
{
   int triangle_side;
   float triangle_area, temp_variable;
   printf("\nEnter the Side of the triangle:");
   scanf("%d",&triangle_side);

   temp_variable = sqrt(3) / 4 ;
   triangle_area = temp_variable * triangle_side * triangle_side ;
   printf("\nArea of Equilateral Triangle is: %f",triangle_area);
   return(0);
}

Output:-


Enter the Side of the triangle
2
Area of Equilateral Triangle is: 1.732051

Sunday, May 19, 2019

Write a C program to remove spaces, blanks from a string

Write a C program to remove spaces, blanks from a string

Program:-

    #include <stdio.h>
    
    int main()
    {
       char text[1000], blank[1000];
       int c = 0, d = 0;
    
       printf("Enter some text\n");
       gets(text);
    
       while (text[c] != '\0') {
          if (text[c] == ' ') {
             int temp = c + 1;
             if (text[temp] != '\0') {
                while (text[temp] == ' ' && text[temp] != '\0') {
                   if (text[temp] == ' ') {
                      c++;
                   } 
                   temp++;
                }
             }
          }
          blank[d] = text[c];
          c++;
          d++;
       }
    
       blank[d] = '\0';
    
       printf("Text after removing blanks\n%s\n", blank);
    
       return 0;
    }

Output :- 




Diamond pattern in C language

To Print Diamond pattern in C language


Program:-

#include <stdio.h>
    
    int main()
    {
      int n, c, k, space = 1;
    
      printf("Enter number of rows\n");
      scanf("%d", &n);
    
      space = n - 1;
    
      for (k = 1; k <= n; k++)
      {
        for (c = 1; c <= space; c++)
          printf(" ");
    
        space--;
    
        for (c = 1; c <= 2*k-1; c++)
          printf("*");
    
        printf("\n");
      }
    
      space = 1;
    
      for (k = 1; k <= n - 1; k++)
      {
        for (c = 1; c <= space; c++)
          printf(" ");
    
        space++;
    
        for (c = 1 ; c <= 2*(n-k)-1; c++)
          printf("*");
    
        printf("\n");
      }
    
      return 0;
    }


Output:

C program to get IP address

Write a C program to get IP address

Program:


    #include<stdlib.h>
   
    int main()
    {
       system("C:\\Windows\\System32\\ipconfig");
     
       return 0;
    }


Saturday, May 18, 2019

Binary Search in C

Program:-

    #include <stdio.h>
    
    int main()
    {
       int c, first, last, middle, n, search, array[100];
    
       printf("Enter number of elements\n");
       scanf("%d",&n);
    
       printf("Enter %d integers\n", n);
    
       for (c = 0; c < n; c++)
          scanf("%d",&array[c]);
    
       printf("Enter value to find\n");
       scanf("%d", &search);
    
       first = 0;
       last = n - 1;
       middle = (first+last)/2;
    
       while (first <= last) {
          if (array[middle] < search)
             first = middle + 1;   
          else if (array[middle] == search) {
             printf("%d found at location %d.\n", search, middle+1);
             break;
          }
          else
             last = middle - 1;
    
          middle = (first + last)/2;
       }
       if (first > last)
          printf("Not found! %d isn't present in the list.\n", search);
    
   return 0; 
    }
------------------------------------------------------------------------------------

Output:-
Enter number of elements
6
Enter 6 integers
-2
5
8
48
55
478
Enter value to find
55
55 found at location 5




Linear search for multiple occurrences

Program:

    #include <stdio.h>
    
    int main()
    {
       int array[100], search, c, n, count = 0;
      
       printf("Enter number of elements in array\n");
       scanf("%d", &n);
      
       printf("Enter %d numbers\n", n);
      
       for (c = 0; c < n; c++)
          scanf("%d", &array[c]);
        
       printf("Enter a number to search\n");
       scanf("%d", &search);
      
       for (c = 0; c < n; c++) {
          if (array[c] == search) {
             printf("%d is present at location %d.\n", search, c+1);
             count++;
          }
       }
       if (count == 0)
          printf("%d isn't present in the array.\n", search);
       else
          printf("%d is present %d times in the array.\n", search, count);
        
getch();
    }

---------------------------------------------------------------------------------------

Output:-

Enter number of elements in array
8
Enter 8 numbers
1
4
3
4
5
6
4
4
Enter a number to search
4
4 is present at location 2.
4 is present at location  4.
4 is present at location  7.
4 is present at location 8.
4 is present 4 times in the array.
  

 

Write a C program for Linear Search Using Function

Write a C program for linear search using function:

Program:-
   
#include <stdio.h>
    
    long linear_search(long [], long, long);
    
    int main()
    {
       long array[100], search, c, n, position;
    
       printf("Input number of elements in array\n");
       scanf("%ld", &n);
    
       printf("Input %d numbers\n", n);
    
       for (c = 0; c < n; c++)
          scanf("%ld", &array[c]);
    
       printf("Input a number to search\n");
       scanf("%ld", &search);
    
       position = linear_search(array, n, search);
    
       if (position == -1)
          printf("%d isn't present in the array.\n", search);
       else
          printf("%d is present at location %d.\n", search, position+1);
    
       return 0;
    }
    
    long linear_search(long a[], long n, long find) {
       long c;
    
       for (c = 0 ;c < n ; c++ ) {
          if (a[c] == find)
             return c;
       }
    
       return -1;
    }

Linear search in C

Linear search C program

Program: -

    #include <stdio.h>
    
    int main()
    {
      int array[100], search, c, n;
    
      printf("Enter number of elements in array\n");
      scanf("%d", &n);
    
      printf("Enter %d integer(s)\n", n);
    
      for (c = 0; c < n; c++)
        scanf("%d", &array[c]);
    
      printf("Enter a number to search\n");
      scanf("%d", &search);
    
      for (c = 0; c < n; c++)
      {
        if (array[c] == search)    /* If required element is found */
        {
          printf("%d is present at location %d.\n", search, c+1);
          break;
        }
      }
      if (c == n)
        printf("%d isn't present in the array.\n", search);
    
  return 0;
    }
----------------------------------------------------------------------------------

Output :- 

Enter number of elements in array
4

Enter 4 numbers
2
3
4
5

 Enter a number to search
5
5 is present at location 4

Write a C program to find HCF and LCM

Write a C program to find HCF and LCM.

Program:

 #include <stdio.h>
    
    int main() {
      int a, b, x, y, t, gcd, lcm;
    
      printf("Enter two integers\n");
      scanf("%d%d", &x, &y);
    
      a = x;
      b = y;
    
      while (b != 0) {
        t = b;
        b = a % b;
        a = t;
      }
    
      gcd = a;
      lcm = (x*y)/gcd;
    
      printf("Greatest common divisor of %d and %d = %d\n", x, y, gcd);
      printf("Least common multiple of %d and %d = %d\n", x, y, lcm);
    
 return 0;
    }
-----------------------------------------------------------------------------------------
Output:

Enter two integers

9
24

Greatest common divisor of 9 and 24 = 3
Least common multiple of 9 and 24 =  27



Write a C program to find HCF and LCM Using Recursion

Write a C program to find HCF and LCM (Using Recursion)


Program:-

    #include <stdio.h>
    
    long gcd(long, long);
    
    int main() {
      long x, y, hcf, lcm;
    
      printf("Enter two integers\n");
      scanf("%ld%ld", &x, &y);
    
      hcf = gcd(x, y);
      lcm = (x*y)/hcf;
    
      printf("Greatest common divisor of %ld and %ld = %ld\n", x, y, hcf);
      printf("Least common multiple of %ld and %ld = %ld\n", x, y, lcm);
    
      return 0;
    }
    
    long gcd(long a, long b) {
      if (b == 0) {
        return a;
      }
      else {
        return gcd(b, a % b);
      }
    }

Write a C program to Find HCF and LCM (Using Function)

Write a C program to Find HCF and LCM (Using Function)

Program:
  
 #include <stdio.h>
    
    long gcd(long, long);
    
    int main() {
      long x, y, hcf, lcm;
    
      printf("Enter two integers\n");
      scanf("%ld%ld", &x, &y);
    
      hcf = gcd(x, y);
      lcm = (x*y)/hcf;
    
      printf("Greatest common divisor of %ld and %ld = %ld\n", x, y, hcf);
      printf("Least common multiple of %ld and %ld = %ld\n", x, y, lcm);
    
      return 0;
    }
    
    long gcd(long x, long y) {
      if (x == 0) {
        return y;
      }
    
      while (y != 0) {
        if (x > y) {
          x = x - y;
        }
        else {
          y = y - x;
        }
      }
    
      return x;
    }

Write a Factorial program in C using function

Write a Factorial program in C using function
Program:-

    #include <stdio.h>
    
    long factorial(int);
    
    int main()
    {
      int number;
      long fact = 1;
    
      printf("Enter a number to calculate its factorial\n");
      scanf("%d", &number);
    
      printf("%d! = %ld\n", number, factorial(number));
    
      return 0;
    }
    
    long factorial(int n)
    {
      int c;
      long result = 1;
    
      for (c = 1; c <= n; c++)
        result = result * c;
    
      return result;
    }

Write a Factorial program in C using recursion

Write a Factorial program in C using recursion:

Program:-

    #include<stdio.h>
    
    long factorial(int);
    
    int main()
    {
      int n;
      long f;
    
      printf("Enter an integer to find its factorial\n");
      scanf("%d", &n);
    
      if (n < 0)
        printf("Factorial of negative integers isn't defined.\n");
      else
      {
        f = factorial(n);
        printf("%d! = %ld\n", n, f);
      }
    
      return 0;
    }
    
    long factorial(int n)
    {
      if (n == 0)
        return 1;
      else
        return(n * factorial(n-1));
    }

Write a Factorial Program in C using a for loop

Write a Factorial program in C (using a for loop)

Program:-

    #include <stdio.h>
    
    int main()
    {
      int c, n, fact = 1;
    
      printf("Enter a number to calculate its factorial: \n");
      scanf("%d", &n);
    
      for (c = 1; c <= n; c++)
        fact = fact * c;
    
      printf("Factorial of %d = %d\n", n, fact);
    
     getch ();
    }
--------------------------------------------------------------------------------------------
Output:-

Enter a number to calculate its factorial:
5
Factorial of 5 = 120

Write a C Program to Find nCr and nPr:

Write a  C program to find ncr and npr

Program :-
    #include <stdio.h>
    
    long factorial(int);
    long find_ncr(int, int);
    long find_npr(int, int);
    
    int main()
    {
       int n, r;
       long ncr, npr;
    
       printf("Enter the value of n and r\n");
       scanf("%d%d",&n,&r);
      
       ncr = find_ncr(n, r);
       npr = find_npr(n, r);
      
       printf("%dC%d = %ld\n", n, r, ncr);
       printf("%dP%d = %ld\n", n, r, npr);
    
       return 0;
    }
    
    long find_ncr(int n, int r) {
       long result;
      
       result = factorial(n)/(factorial(r)*factorial(n-r));
      
       return result;
    }
    
    long find_npr(int n, int r) {
       long result;
      
       result = factorial(n)/factorial(n-r);
      
       return result;
    }
    
    long factorial(int n) {
       int c;
       long result = 1;
    
       for (c = 1; c <= n; c++)
          result = result*c;
    
       return result;
    }
---------------------------------------------------------------------------------------------------

Output:

Enter the value of n and r
5
2

5C2 = 10
5P2 = 20

Swap function in C language (using call by Reference)

Swap function in C language ( using call by reference.)

Program :-

    #include <stdio.h>
    
    void swap(int*, int*);

    int main()
    {
       int x, y;
    
       printf("Enter the value of x and y\n");
       scanf("%d%d",&x,&y);
    
       printf("Before Swapping\nx = %d\ny = %d\n", x, y);
    
       swap(&x, &y);
    
       printf("After Swapping\nx = %d\ny = %d\n", x, y);
    
       return 0;
    }
    //Swap function definition
    void swap(int *a, int *b)
    {
       int t;
    
       t  = *b;
       *b = *a;
       *a = t;
    }

Swap two numbers using pointers in C

Swap two numbers using pointers

Program :

    #include <stdio.h>
    
    int main()
    {
       int x, y, *a, *b, temp;
    
       printf("Enter the value of x and y\n");
       scanf("%d%d", &x, &y);
    
       printf("Before Swapping\nx = %d\ny = %d\n", x, y);
      
       a = &x;
       b = &y;
      
       temp = *b;
       *b   = *a;
       *a   = temp;
    
       printf("After Swapping\nx = %d\ny = %d\n", x, y);
      
return 0;
    }

C programming code to swap using bit-wise XOR

C programming code to swap using bit-wise XOR

Program:-

    #include <stdio.h>
    
    int main()
    {
      int x, y;
    
      scanf("%d%d", &x, &y);
    
      printf("x = %d\ny = %d\n", x, y);
    
      x = x ^ y;
      y = x ^ y;
      x = x ^ y;
    
    
      printf("x = %d\ny = %d\n", x, y);
    
return 0;
    }

Swapping of two numbers in C

Swapping of two numbers in C

Program :-

    #include <stdio.h>
    
    int main()
    {
      int x, y, t;
    
      printf("Enter two integers\n");
      scanf("%d%d", &x, &y);
    
      printf("Before Swapping\nFirst integer = %d\nSecond integer = %d\n", x, y);
    
      t = x;
      x = y;
      y = t;
    
      printf("After Swapping\nFirst integer = %d\nSecond integer = %d\n", x, y);
    
      return 0;
    }
----------------------------------------------------------------------------------------------------

Output :-

Enter two integers
76
46

Before Swapping
First integer = 76
Second integer = 46

After Swapping
First integer = 46
Second integer = 76

C program to addition, subtraction, multiplication and division

C program to  addition, subtraction, multiplication and division
program:-
    #include <stdio.h>
    
    int main()
    {
       int first, second, add, subtract, multiply;
       float divide;
    
       printf("Enter two integers\n");
       scanf("%d%d", &first, &second);
    
       add = first + second;
       subtract = first - second;
       multiply = first * second;
       divide = first / (float)second; 
    
       printf("Sum = %d\n", add);
       printf("Difference = %d\n", subtract);
       printf("Multiplication = %d\n", multiply);
       printf("Division = %.2f\n", divide);
    
 return 0;
    }

Output:
Enter two integers
5 3
Sum = 10
Difference = 2
Multiplication = 15
Division = 1.66

Write a C Program To Print Date

Write a C program to print current system date. By using get date function.

Program:-

    #include <stdio.h>
    #include <conio.h>
    #include <dos.h>
    
    int main()
    {
       struct date d;
    
       getdate(&d);
    
       printf("Current system date: %d/%d/%d", d.da_day, d.da_mon, d.da_year);
      return 0;

    }

This code works in Turbo C only because it supports dos.h header file.

Hello World C Program

  Program:-

  #include <stdio.h>
    
    int main()
    {
      printf("Hello world\n");
return 0;
    }

Output: -

Hello World
-----------------------------------------------------
"stdio.h" header file contains the declaration of printf function.
 printf:- Library Function used to display text on the screen
"\n" :- used to placed the cursor at the beginning next line

To Find Reverse of a Number

Write a C program to find reverse of a number:

 Program:- 

#include <stdio.h>
    int main()
    {
       int n, reverse = 0;
    
       printf("Enter a number to reverse\n");
       scanf("%d", &n);
       while (n != 0)
       {
          reverse = reverse * 10;
          reverse = reverse + n%10;
          n       = n/10;
       }
       printf("Reverse of entered number is = %d\n", reverse);
    return 0;
    } 

Output:-  Enter a number to reverse 

12345

Reverse of entered number is= 54321