Sunday, December 23, 2018

PROGRAM TO DISPLAY TRANSPOSE OF A MATRIX

/*PROGRAM TO DISPLAY TRANSPOSE OF A MATRIX*/

#include<stdio.h>
#include<conio.h>
void main()
{
   int m, n, c, d, matrix[10][10], transpose[10][10];
   clrscr();
   printf("Enter the number of rows and columns of matrix\n");
   scanf("%d%d", &m, &n);

   printf("Enter the elements of matrix\n");

   for (c = 0; c < m; c++)
      for(d = 0; d < n; d++)
         scanf("%d",&matrix[c][d]);

   for (c = 0; c < m; c++)
      for( d = 0 ; d < n ; d++ )
         transpose[d][c] = matrix[c][d];
   printf("Transpose of entered matrix :-\n");

   for (c = 0; c < n; c++) {
      for (d = 0; d < m; d++)
         printf("%d\t",transpose[c][d]);
      printf("\n");
   }

   getch();
}

OUTPUT:-
sk.

PROGRAM TO DISPLAY MULTIPLICATION OF TWO MATRIX

/*PROGRAM TO DISPLAY MULTIPLICATION OF TWO MATRIX*/

#include<stdio.h>
#include<conio.h>
void main()
{
  int m, n, p, q, c, d, k, sum = 0;
  int first[10][10], second[10][10], multiply[10][10];
  clrscr();
  printf("Enter the number of rows and columns of first matrix\n");
  scanf("%d%d", &m, &n);
  printf("Enter the elements of first matrix\n");

  for (c = 0; c < m; c++)
    for (d = 0; d < n; d++)
      scanf("%d", &first[c][d]);
   
  printf("Enter the number of rows and columns of second matrix\n");
  scanf("%d%d", &p, &q);

  if (n != p)
    printf("Matrices with entered orders can't be multiplied with each other.\n");
  else
  {
    printf("Enter the elements of second matrix\n");

    for (c = 0; c < p; c++)
      for (d = 0; d < q; d++)
        scanf("%d", &second[c][d]);

    for (c = 0; c < m; c++) {
      for (d = 0; d < q; d++) {
        for (k = 0; k < p; k++) {
          sum = sum + first[c][k]*second[k][d];
        }

        multiply[c][d] = sum;
        sum = 0;
      }
    }

    printf("Product of entered matrices:-\n");

    for (c = 0; c < m; c++) {
      for (d = 0; d < q; d++)
        printf("%d\t", multiply[c][d]);

      printf("\n");
    }
  }

  getch();
}


Output:-
sk.

PROGRAM TO DISPLAY ADDITION OF TWO MATRIX

/*PROGRAM TO DISPLAY ADDITION OF TWO MATRIX*/

#include <stdio.h>
#include<conio.h>
void main()
{
   int m, n, c, d, first[10][10], second[10][10], sum[10][10];
   clrscr();
   printf("Enter the number of rows and columns of matrix\n");
   scanf("%d%d", &m, &n);
   printf("Enter the elements of first matrix\n");

   for (c = 0; c < m; c++)
      for (d = 0; d < n; d++)
         scanf("%d", &first[c][d]);

   printf("Enter the elements of second matrix\n");
      for (c = 0; c < m; c++)
      for (d = 0 ; d < n; d++)
            scanf("%d", &second[c][d]);

   printf("Sum of entered matrices:-\n");

   for (c = 0; c < m; c++) {
      for (d = 0 ; d < n; d++) {
         sum[c][d] = first[c][d] + second[c][d];
         printf("%d\t", sum[c][d]);
      }
      printf("\n");
   }

   getch();
}

OUTPUT:-
sk.

PROGRAM TO DISPLAY LINEAR SEARCH

/*PROGRAM  TO  DISPLAY  LINEAR  SEARCH*/

#include<stdio.h>
#include<conio.h>
void main()
{
   int array[100], search, c, n;
   clrscr();
   printf("Enter the 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 the number to search\n");
   scanf("%d", &search);

   for (c = 0; c < n; c++)
       {
      if (array[c] == search)     /* if required element found */
      {
         printf("%d is present at location %d.\n", search, c+1);
         break;
      }
   }
   if (c == n)
      printf("%d is not present in array.\n", search);

   getch();
}

OUTPUT:-
sk.

PROGRAM TO MERGE AN ARRAY

/*PROGRAM  TO  MERGE  AN  ARRAY*/

#include<stdio.h>
#include<conio.h>
void merge(int [], int, int [], int, int []);

void main()
 {
  int a[100], b[100], m, n, c, sorted[200];
  clrscr();
  printf("Input number of elements in first array\n");
  scanf("%d", &m);

  printf("Input %d integers\n", m);
  for (c = 0; c < m; c++)
{
 scanf("%d", &a[c]);
  }

 printf("Input number of elements in second array\n");
 scanf("%d", &n);
 printf("Input %d integers\n", n);
for (c = 0; c < n; c++) {
scanf("%d", &b[c]);
  }

  merge(a, m, b, n, sorted);

  printf("Sorted array:\n");

  for (c = 0; c < m + n; c++)
{
    printf("%d\n", sorted[c]);
  }

  getch();
}

void merge(int a[], int m, int b[], int n, int sorted[])
{
  int i, j, k;

  j = k = 0;

  for (i = 0; i < m + n;)
 {
    if (j < m && k < n)
 {
      if (a[j] < b[k])
{
        sorted[i] = a[j];
        j++;
      }
      else {
        sorted[i] = b[k];
        k++;
      }
      i++;
    }
    else if (j == m)
 {
    for (; i < m + n;)
 {
        sorted[i] = b[k];
        k++;
        i++;
      }
    }
    else
{
      for (; i < m + n;)
{
        sorted[i] = a[j];
        j++;
        i++;
      }
    }
  }
}


Output:-
sk.

PROGRAM TO SWAP TWO NUMBERS

/*PROGRAM  TO  SWAP  TWO  NUMBERS*/

#include<stdio.h>
#include<conio.h>
void main()
{
 int x, y, temp;
 clrscr();
 printf("Enter the value of x and y\n");
 scanf("%d%d", &x, &y);

 printf("Before Swapping\nx = %d\ny = %d\n",x,y);
 temp = x;
  x    = y;
  y    = temp;
printf("After Swapping\nx = %d\ny = %d\n",x,y);
getch();
}


Output:-
sk.

PROGRAM TO SWAP TWO NUMBERS

/*PROGRAM  TO  SWAP  TWO  NUMBERS*/

#include<stdio.h>
#include<string.h>
#include<malloc.h>
#include<conio.h>
void main()
{
char first[100], second[100], *temp;
clrscr();
printf("Enter the first string\n");
gets(first);
printf("Enter the second string\n");
gets(second);
printf("\nBefore Swapping\n");
printf("First string: %s\n",first);
printf("Second string: %s\n\n",second);
temp = (char*)malloc(100);
strcpy(temp,first);
strcpy(first,second);
strcpy(second,temp);
printf("After Swapping\n");
printf("First string: %s\n",first);
printf("Second string: %s\n",second);
 getch();
}

OUTPUT:-
sk.

PROGRAM TO FIND STRING LENGTH

/*PROGRAM  TO  FIND  STRING  LENGTH*/

#include<stdio.h>
#include<string.h>
#include<conio.h>
void main()
{
char a[100];
int length;
clrscr();
printf("Enter a string to calculate it's length\n");
gets(a);
length = strlen(a);
printf("Length of entered string is = %d\n",length);
 getch();
}


Output:-
sk.

PROGRAM TO DISPLAY REVERSE OF A STRING

/*PROGRAM  TO  DISPLAY  REVERSE  OF  A  STRING*/

#include<stdio.h>
#include<conio.h>
void main()
{
 int n, reverse = 0;
 clrscr();
 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);
getch();
}

OUTPUT:-
sk.

PROGRAM TO DISPLAY PRIME NO FROM THE SERIES

/*PROGRAM  TO  DISPLAY  PRIME  NO  FROM  THE  SERIES*/

#include<stdio.h>
#include<conio.h>
void main()
{
int n, i = 3, count, c;
clrscr();
printf("Enter the number of prime numbers required\n");
scanf("%d",&n);
if ( n >= 1 )
{
 printf("First %d prime numbers are :\n",n);
 printf("2\n");
 }
 for ( count = 2 ; count <= n ;  )
 {
  for ( c = 2 ; c <= i - 1 ; c++ )
 {
 if ( i%c == 0 )
break;
 }
if ( c == i )
{
printf("%d\n",i);
 count++;
 }
 i++;
}
getch();
}

OUTPUT:-
sk.

PROGRAM TO CHECK NUMBER OF DAYS FROM A NUMBER

/*PROGRAM  TO  CHECK  NUMBER  OF  DAYS  FROM  A  NUMBER*/

#include<stdio.h>
#include<conio.h>
void main()
{
 int ndays, years, weeks, days;
 clrscr();
 printf("\nEnter the total days\n");
 scanf("%d",&ndays);
 years=(ndays/365);
 weeks=((ndays%365)/7);
 days=((ndays%365)%7);
 printf("%d = %d years, %d weeks, %d days\n",ndays, years, weeks, days);
 getch();
}

Output:-
sk.

PROGRAM TO DELETE AN ELEMENT FROM AN ARRAY

/*PROGRAM  TO  DELETE  AN  ELEMENT  FROM  AN  ARRAY*/

#include<stdio.h>
#include<conio.h>
void main()
{
 int array[100], position, c, n;
clrscr();
 printf("Enter number of elements in array\n");
scanf("%d", &n);
 printf("Enter %d elements\n", n);
 for ( c = 0 ; c < n ; c++ )
scanf("%d", &array[c]);
printf("Enter the location where you wish to delete element\n");
 scanf("%d", &position);
 if ( position >= n+1 )
 printf("Deletion not possible.\n");
 else
 {
 for ( c = position - 1 ; c < n - 1 ; c++ )
 array[c] = array[c+1];
 printf("Resultant array is\n");
 for( c = 0 ; c < n - 1 ; c++ )
 printf("%d\n", array[c]);
 }
 getch();
}

OUTPUT:-
sk.


PROGRAM TO INSERT AN ELEMENT IN A ARRAY

/*PROGRAM  TO  INSERT  AN  ELEMENT  IN  A  ARRAY*/

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

void main()
{
int array[100], position, c, n, value;
clrscr();
printf("Enter number of elements in array\n");
scanf("%d", &n);
printf("Enter %d elements\n", n);
for (c = 0; c < n; c++)
Scanf("%d", &array[c]);
 printf("Enter the location where you wish to insert an element\n");
scanf("%d", &position);
printf("Enter the value to insert\n");
scanf("%d", &value);
for (c = n - 1; c >= position - 1; c--)
 array[c+1] = array[c];
 array[position-1] = value;
 printf("Resultant array is\n");
 for (c = 0; c <= n; c++)
printf("%d\n", array[c]);
getch();
}

OUTPUT:-
sk.

PROGRAM TO DISPLAY MULTIPLICATION OF TABLE

/*PROGRAM  TO  DISPLAY  MULTIPLICATION  OF  TABLE*/

#include <stdio.h>
#include<conio.h>
void main()
{
int num, i = 1;
clrscr();
printf("Enter any Number:");
scanf("%d", &num);
printf("Multiplication table of %d: ", num);
while (i <= 10)
 {
printf("%d x %d = %d", num, i, num * i);
 i++;
}
getch();
}

Output:-
sk.

Saturday, December 22, 2018

PROGRAM TO CONVERT DECIMAL TO BINARY NUMBER

/*PROGRAM  TO  CONVERT  DECIMAL TO  BINARY  NUMBER*/

#include<stdio.h>
#include<conio.h>
void main()
{
int n, c, k;
clrscr();
printf("Enter an integer in decimal number system\n");
scanf("%d", &n);
printf("%d in binary number system is:\n", n);
for (c = 31; c >= 0; c--)
{
 k = n >> c;
 if (k & 1)
printf("1");
else
printf("0");
 }
printf("\n");
getch();

}

OUTPU:-
sk.

PROGRAM TO DISPLAY LEAP YEAR

/*PROGRAM  TO  DISPLAY  LEAP  YEAR*/

#include<stdio.h>
#include<conio.h>
int main()
{
 int year;
clrscr();
printf("Enter a year to check if it is a leap year\n");
scanf("%d", &year);
if ( year%400 == 0)
printf("%d is a leap year.\n", year);
else if ( year%100 == 0)
printf("%d is not a leap year.\n", year);
else if ( year%4 == 0 )
printf("%d is a leap year.\n", year);
else
printf("%d is not a leap year.\n", year); 
getch();
}

OUTPUT:-
sk.


PROGRAM TO DISPLAY WHETHER THE GIVEN CHARACTER IS VOWEL OR NOT

/*PROGRAM TO DISPLAY WHETHER THE GIVEN CHARACTER IS VOWEL OR NOT*/

#include <stdio.h>
#include<conio.h>
void main()
{
 char ch;
 clrscr();
 printf("Enter a character\n");
 Scanf("%c", &ch);

 if (ch == 'a' || ch == 'A' || ch == 'e' || ch == 'E' || ch == 'i' || ch == 'I' || ch =='o' || ch=='O' || ch ='u' || ch == 'U')
 printf("%c is a vowel.\n", ch);
 else
 printf("%c is not a vowel.\n", ch);
 getch();
}

OUTPUT:-
sk.

PROGRAM TO DISPLAY WHETHER THE NO IS EVEN OR ODD.

/*PROGRAM TO DISPLAY WHETHER THE NO IS EVEN OR ODD*/

#include <stdio.h>
#include<conio.h>
int main()
{
 int n;
 clrscr();
 printf("Enter an integer\n");
scanf("%d", &n);

 if (n%2 == 0)
 printf("Even\n");
else
 printf("Odd\n");

getch();
}

OUTPUT:-
sk.

PROGRAM TO ADD TWO Numbers

/*PROGRAM  TO  ADD  TWO  Numbers*/

#include<stdio.h>
#include<conio.h>
int main()
{
   int a, b, c;
   clrscr();
   printf("Enter two numbers to add\n");
   scanf("%d%d",&a,&b);

   c = a + b;

   printf("Sum of entered numbers = %d\n",c);

   getch();
}

OUTPU:-
sk.

Program to display “Welcome to C”

/*Program to display “Welcome to C”*/

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("\nWELCOME TO C\n");
getch();
}

OUTPUT:-
sk.



Sunday, December 16, 2018

Operators and Expressions

/*OPERATORS AND EXPRESSIONS*/
sk.
* OPERATORS:- An operator is the symbol that is struct the computer to perform a specific operation. The main use of operator is to manipulate the data and variable.
<TYPES OF OPERATOR>

  • ARITHMETIC OPERATOR
  • RELATIONAL OPERATOR
  • LOGICAL OPERATOR
  • ASSIGNMENT OPERATOR
  • INCREMENT OR DECREMENT OPERATOR
  • CONDITIONAL OPERATOR
  • BITWISE OPERATOR 
  • SPECIAL OPERATOR


A) ARITHMETIC OPERATORS:-ADDITION OPERATOR:- It is used to add two or more integers or float value.
SUBTRACTION OPERATOR:-It is used to calculate the difference of two integers or float value.
MULTIPLICATION OPERATOR:- It is used to calculate product of two value.
DIVISION OPERATOR:- It is use to divide two value.
MODULATION DIVISION OPERATOR:- It is used to calculate the reminder left after the integer of two numbers.

B) RELATIONAL OPERATORS:- These are used to compare two value. Comparison is very important in a program and it acts as a base for executing certain statements (i) the program.

  • RELATIONAL OPERATOR:-





CLASSIFICATION OF DATA TYPES.

/*CLASSIFICATION OF DATA TYPE.*/
sk.
*PRIMARY DATA TYPE:-

  •   Integer data types:- These are used to store numeric data items. They can store whole number as well as numbers with fractions. The data type of this categories are integer, short integer, long integer. In addition to these type unsigned int, unsigned short int, and unsigned long int are also lies in this category. Integer occupy one word in the numbering. The length of the word may vary and it is typically 16 or 32 bits.
  •  FLOATING POINT TYPE:- These are used to store number with fraction.
  •  CHARACTER DATA TYPE:- These are used to store character data items. The value to be stored in them are enclosed in single quotation mark ('') char and unsigned char are two character data type.
* SECONDARY/DERIVED DATA TYPE:- These are also called structure data type. The main difference between fundamental and derived data type is that a variables of derived data types can handle more than one value data type but in variable of fundamental data type it can handle only one value data type. They are also called secondary data type. Example:- array, string, union etc.
  • USER DEFINED DATA TYPE:- These are the data types that are defined by the user. The contain users specified values "enum". keyword is used to declare data types of this type.
  • POINTER DATA TYPE:- A pointer is a data type that handles the data as per as its memory address.
  • VOID DATA TYPES:- It represent null or empty. This is used when a particular function does not return any value.

Saturday, December 15, 2018

CLASSIFICATION OF CONSTANTS

/*CLASSIFICATION OF CONSTANTS*/
sk
* NUMERIC CONSTANT:- These are the constants that are formed by the combination of digits from 0to9. They may or may not have a decimal point in them. They may be preceded by +ve or -ve sign. Numeric constants are further of two types:-
a:- INTEGER CONSTANT
    b:-REAL CONSTANT 

A:- INTEGER CONSTANT:- Integer constants are the sequence of digits that are used in C program. Integer, octal integer and hexadecimal integer, are the three types of numeric constants.
Decimal integer may be preceded by +ve or -ve sign. you can use commas(,) etc.
Octal integer constants consist of sequence of digit from 0to7.
Hexadecimal integer are represented by the combination of 0to9 and character from AtoF.
B:-REAL CONSTANT:- It is used to represent the quantities that vary rapidly. Example:- distance, weight, height, and price.
It contains fractional part to accurately represent such quantities. Real constants are also called as float point cell.
 They are further of two types:-
   1) FRACTIONAL FORM
   2) EXPONENTIAL FORM


* CHARACTER CONSTANT:- These are used to express quantity like:- name, place, gender, etc. They can be a single character or a group of characters or backslash(\) character constant.
 :-SINGLE CHARACTER CONSTANT:- A single character constant contains a single character. They are enclosed in single quotation make ('E'). It can be either a single alphabet, digit, or single symbol out of 'C' character cell and it must be enclosed l in single inverted commas.
 :-STRING CHARACTER CONSTANT:- A group of character is called strings. These are enclosed with in double quotation make ("cat").
 :-BACKSLASH CHARACTER CONSTANT:- In C language code some special character constant that are called escape sequences. They are used with other function of C.
Example:- \n=next line, \b=back space, \t=horizontal tab, \v=vertical tab.


     

CONSTANTS, VARIABLES AND DATATYPES.

/*constant, variable and data types*/

sk

* CHARACTER SET:- The character from character cell are combined to form constant, variables and keywords. In is set of character supported by 'c' language. Character can be any alphabet, digit or special symbol.

  •  Alphabets:- A-Z or a-z.
  •  Digits:- 0-9.
 Special symbol:- +,-,&,*,/,%,etc.

* ALPHABETS:- 'C' character set supports A to Z and a to z. Not that 'k' is 'K' sensitive language in which a=!A. Total 26+26 alphabets can be used in 'C' program.
* DIGITS:- 'C' character set supports digit from 0to9. Any combination of digit from this range is valid in 'C' program.
* SPECIAL SYMBOLS:- In addition to alphabets and digiys 'C' support many special character of keywords. many of special characters have special meaning in 'C' language. Total number of special character is 30, in addition to this 'C' language supports while space in character set. When you put while space between two keywords, it will be transported to turbo 'C' compiler but if you use it with in a keywords it will generate a error. 
        example:- prin tf("");

* 'C' TOKENS:- In languages like english, individual words and punctuation and make are token. In 'C' language small individual unit are called 'C' tokens. There are six types of C tokens, all programs are made by using this.
sk

* keywords:- Every word in C program will be a keyword a identifier. Every language have set of characters, whose meaning is already defined and understand to the compiler. The number of this set are reserved words that can be used in a pre defined way are called keywords. The variable name defined in C program cannot be taken from set of keywords. C compiler has 40 keywords but we use 32 in C language and 8 of them are used in low language program. All keywords must be written in lower case:-

  • auto
  • break
  • case
  • char
  • const 
  • continue 
  • default
  • do 
    else  etc.....
* IDENTIFIERS:- Name given to variables, function, structure, and array, they are called so as they identify particular part of program. They are made of alphabets or digits (lower or upper case) with any combination of digit.
* CONSTANTS:- A constant refers to a value that do not change during execution of the program. It is similar to mathematical constant. like 'π' whose value is always assumed to be 22/7 or 3.14 whenever we need a quantity that should be static and a like throughout a program.(next blog)
* VARIABLES:- It ia a name given to a temporary memory location that has been used to store any value. It is clear from the name of that the value stored in a variable can be changed at any instant of the time during a program execution. It is needed when we want to store the input of user for calculation or you want to store a piece of output generated in the mid of calculation and to store the final output of the program.
*DATA TYPES:- Various quantities such as constant, variable etc, occur in C program must have a type associated with them. They can be one and only one type associated with an entity.
Data type are classified into primary (fundamental) data type and derived data type (secondary)and user defined data type.(next blog)


Algorithm

/*WHAT IS ALGORITHM?*/
sk.
An ALGORITHM is a detailed step-by-step instruction set or formula for solving a problem or completing a task. In computing, programmers write ALGORITHMS that instruct the computer how to perform a task.
 When a think of an ALGORITHM in the most general way (not just in regards to computing), ALGORITHMS are everywhere. A recipe for making food is an ALGORITHM, the method you use to solve addition or long division problems is an ALGORITHM, and the process of folding a shirt or a pair of pants is an ALGORITHM. Even your morning routine could be considered an ALGORITHM! In fact, here's what your childs morning might look like written out as an ALGORITHM...

History of C.

/*HISTORY OF C*/
sk

The C programming language was devised in the early 1970s by DENNIS M.RETCHIE an employee from BELL LABS (AT&T). In the 1960s RITCHIE worked with several other employees of BELL LABS (AT&T), on a project called MULTICS.



 * ALGOL(1960)
    International group
 * BCPL(1967)
    MARTIN RICHARDS.
 * B(1970)
    KEN THOMPSON
 * TRADITIONAL C(1972)
    DENNIS RITCHIE
 * K & RC (1978)
    BRAIN KERNIGHAN & DENNIS RITCHIE.
 * ANSI C(1989)
    ANSI Committee
 * ANSI/ISO C(1990)
    ISO Committee.
 * 'C' (C-95)(1995)
    Internet Through
 * (C99)(1999)
    LINKED
 * (C11) (2011)
    Last tearm in December 2011.

simple program in c.

/*Simple program in C.*/

ak.


 #include<stdio.h>       //standard input/output.
 #include<conio.h>     //console input/output
 void main()                 //member function
 {
   clrscr();                      //clear screen function
   printf("\nMy first C program.\n");
   printf("\nMy name is Shubham.\n");
   printf("\nMy roll number is 4464.\n");
   getch();                      //for screen hold
  }


 OUTPUT:-
    My first C program.
    My name is Shubham.
    My roll number is  4464.



(use in program)
*  #include<stdio.h> is header file
*  #include<conio.h> is header file
*  \n for next line.
*  void main() for empty return
*  clrscr()  for clear the back work.
*  printf()  for print the value
*  ""  use for string or statement.
*  getch() use for screen hold
*  {} use for starting and ending program.




Wikipedia

Search results

Search The program