Skip to main content

Posts

Showing posts from 2021

Overview of C - Notes

 Overview of C - Notes   Importance of C Programming:   C is a robust language and has a rich set of built in functions, data types and operators which can be used to write any complex programs. Program written in C are efficient and fast due to availability of several data types and operators. C has the capability of an assembly language with the feature of high level language, so it is well suited for writing in both system software and application software. C is highly portable language, code written in one machine can be moved to other which is very important and powerful feature. C also supports low level features like bit level programming. C has high level constructs and it is more user friendly as its syntaxes approaches to English like language. History of C Language:                 In 1972, Dennis Ritchie developed a programming language at the AT&T Bell Laboratories in USA, called C Language. It was developed to be used in UNIX operating system. Dennis Ritchie

C program to reverse a number entered by the user

 C program to reverse a number entered by the user     In this example, we will display the reverse of a number entered by the user. Here, in the output we have entered a number 472 whose reverse will be displayed in the screen. C PROGRAM TO REVERSE A NUMBER ENTERED BY THE USER: #include <stdio.h> #include <conio.h> void  main() {      int  x,y=0,r;     printf( "Enter a number : " );     scanf( "%d" ,&x);      while (x!=0)     {         r=x%10;         y=y*10+r;         x=x/10;     }     printf( "Reverse is : %d" ,y);     getch(); } OUTPUT TO REVERSE A NUMBER ENTERED BY THE USER:      Enter a number: 472      Reverse is : 274 NOTE:   You Can Comment Your Code if you have solved differently and we will pin it in the comment section.  Let's Learn together.  MOTTO:                           You Learn, I Learn together We Learn.  

C program to read m x n matrix and calculate the Row sum and Column sum of the matrix.

 C program to read m x n matrix and calculate the Row sum and Column sum of the matrix.     In this example, we read a m x n matrix whose value would be entered by the user then the sum of row and column is calculated. Here in the example we have taken a matrix of order 3 x 2 whose row sum and column sum is displayed in the output screen. PROGRAM TO READ m x n MATRIX AND CALCULATE THE ROW SUM AND COLUMN SUM OF THE MATRIX: #include <stdio.h> #include <conio.h> void  main() {      int  i,j,m[100][100],row,column,rsum,csum=0;     printf( "Enter the row size of the matrix :" );     scanf( "%d" ,&row);     printf( "Enter the column size of the matrix :" );     scanf( "%d" ,&column);     printf( "Enter the Matrix : " );      for (i=0;i<row;i++)     {          for (j=0;j<column;j++)         {             scanf( "%d" ,&m[i][j]);         }     }      for (i=0;i<row;i++)     {         rsum=0;         

C Program to check if a given square matrix is symmetric or not using function

 C Program to check if a given square matrix is symmetric or not using function.     In this example, we will check if a given square matrix entered by the user is symmetric or not. Here in the output we have taken a square matrix of 3x3. PROGRAM TO CHECK IF A GIVEN SQUARE MATRIX IS SYMMETRIC OR NOT USING FUNCTION #include <stdio.h> #include <conio.h> void  symmetric( int , int , int  [50][50]); void  main() {      int  row,column,i,j,a[50][50];     printf( "Enter the size of the matrices: " );     scanf( "%d" ,&row);     column=row;     printf( "Enter the matrix : " );      for (i=0;i<row;i++)     {          for (j=0;j<column;j++)         {             scanf( "%d" ,&a[i][j]);         }     }     symmetric(row,column,a);     getch(); } void  symmetric( int   r , int   c , int   f [50][50]) {      int  flag=1,i,j,t[50][50];      for (j=0;j< c ;j++)     {          for (i=0;i< r ;i++)         {             t[i][j]=

C program to display the upper triangle and lower triangle of the given square Matrix using function

 C program to display the upper triangle and lower triangle of the given square Matrix using function     In this example, we will display the upper triangle and lower triangle of a given square matrix using function. Here in the output section we have taken a 3x3 matrix whose values are entered as shown in the output. After entering the elements of the square matrix it will display the upper triangle and lower triangle of the matrix entered. PROGRAM TO DISPLAY THE UPPER TRIANGLE AND LOWER TRIANGLE OF THE GIVEN SQUARE MATRIX USING FUNCTION #include <stdio.h> #include <conio.h> void  uppert( int , int , int  [100][100]); void  lowert( int , int , int  [100][100]); void  main() {      int  i,j,c,d,a[100][100];     printf( "Enter the size of the given square matrix : " );     scanf( "%d" ,&c);     d=c;     printf( "Enter the Matrix : " );      for (i=1;i<=c;i++)     {          for (j=1;j<=d;j++)         {              scanf( "%d&qu

C program to convert a decimal number into binary number using function.

 C program to convert a decimal number into binary number using function.     In this example, we  convert the decimal number entered by the user into binary form. Here, in the out put we have taken a decimal number 20 whose binary  is printed as 10100. You can take other numbers such as 15, 13 78, etc... PROGRAM TO CONVERT A DECIMAL NUMBER INTO BINARY NUMBER USING FUNCTION. #include   <stdio.h> #include <conio.h> int  binary( int   b ); void  main() {      int  b;     printf( "\nEnter the Number You want to convert : " );     scanf( "%d" , &b);     binary(b);     getch(); } int  binary( int   b ) {      int  a[10], i, j;      for  (i = 0;  b  > 0; i++)     {         a[i] =  b  % 2;          b  =  b  / 2;     }     printf( "\n Binary Number of a Given Number =  " );      for  (j = i - 1; j >= 0; j--)     {         printf( "%d" , a[j]);     }     printf( "\n" );      return  0; } OUTPUT  TO CONVERT A DECIMAL NUMBER

C Program to print the PASCAL Triangle up to the Nth row where n is a value inputted by the user

 C Program to print the PASCAL Triangle up to the Nth row where n is a value inputted by the user.  .    In this example, we will print a Pascal's triangle upto to the value of the Nth row entered by the user. In the output section we have taken the value of n as 6 and the pascal's triangle is shown in the output. No, it is not that you have to take the value of n as 6, you can enter any value according to your choice. And the required pascal's tringle will be available on the screen.   What is Pascal's Triangle? Pascal's Triangle is a triangular arrangement of the binaomaial coefficients of the expansion (x+y) n  for positive integral values of n. PROGRAM  TO PRINT THE PASCAL TRIANGLE UP TO THE N-TH ROW WHERE N IS A VALUE INPUTTED BY THE USER: #include <stdio.h> #include <conio.h> void  main() {      int  n,coef=1,space,i,j;     printf( "Enter the value of n:" );             scanf( "%d" ,&n);      for (i=0;i<n;i++)     {     

C Program to print the first N even numbers in reverse order.

 C Program to print the first N even numbers in reverse order.      In this example, we will print the first N even numbers in reverse order. Here N is the total number of even numbers you want to print. PROGRAM TO PRINT THE FIRST N EVEN NUMBERS IN REVERSE ORDER: #include <stdio.h> #include <conio.h> int   main () {      int   even , n , i ;      printf ( "Enter the value of N : " );      scanf ( " %d " ,& n );      printf ( "Printing first  %d  even numbers in reverse order : " , n );      for ( i = n * 2 ; i > 2 ; i --)     {          if ( i % 2 == 0 )         {              printf ( " %d \t " , i );         }     }      return   0 ; } OUTPUT TO PRINT THE FIRST N EVEN NATURAL NUMBERS IN REVERSE ORDER: Enter the value of N : 10 Printing first 10 even numbers in reverse order : 20    18      16      14      12      10      8       6       4     NOTE:   You Can Comment Your Code if you have solved differently and we will pin i

C program to Print the Digits of a Number in Words

 C program to Print the Digits of a Number in Words.      In this example, we will print the digits of a number in words.  For example, if a number 841 is entered through the keyboard  then the program must print “Eight Four One". For solving this first we have to reverse the number than by using switch statement we willl print the digits of the number in words.    PROGRAM TO PRINT THE DIGITS OF A NUMBER IN WORDS #include <stdio.h> #include <conio.h> void   main () {      int   n , num = 0 ;      printf ( "Enter the Number : " );      scanf ( " %d " ,& n );      while ( n != 0 )     {          num =( num * 10 )+( n % 10 );          n /= 10 ;     }      printf ( "Printing the digits of a number in words is : " );      while ( num != 0 )     {          switch ( num % 10 )         {          case   0 :              printf ( "Zero " );              break ;          case   1 :              printf ( "One " );            

C Program to find out the roots of a Quadratic Equation and also test for Real and Complex roots

 C Program to find out the roots of a Quadratic Equation  and also test for Real and Complex roots.       In this example, we will calculate the roots of the quadratic equation by testing for real and complex roots. We can test real and complex roots by checking these conditions : If b 2  −4 ac  < 0, then there are no real roots. If b 2  −4 ac  = 0, then both the roots are equal. If b 2  −4 ac  > 0, then roots are real and distinct.   PROGRAM TO FIND OUT THE ROOTS OF A QUADRATIC EQUATION. #include <stdio.h> #include <conio.h> #include <math.h> int   main () {      int   a , b , c , d ;      float   x , y ;      printf ( "Enter coefficient of x^2,x and constant : " );      scanf ( " %d   %d   %d " ,& a ,& b ,& c );      d = b * b - 4 * a * c ;      if ( d < 0 )     {          printf ( "Roots are Complex and Imaginary." );     }      if ( d == 0 )     {          printf ( "Both roots are equal" );        

C Program to find Mean and Standard deviation(SD) for a set of n numbers using array.

 C Program to find Mean and Standard deviation(SD) for a set of n numbers using array.     In this example, we will calculate the mean and standard deviation for a set of n numbers entered by the user using array.    PROGRAM TO FIND THE MEAN AND STANDARD DEVIATION(SD) FOR A SET OF N NUMBERS USING ARRAY. #include <stdio.h> #include <math.h> #include <conio.h> void   main () {      int   n , i ;      float   x [ 50 ], mean , sd , sum ;      printf ( "How many numbers you want to enter : " );      scanf ( " %d " ,& n );      printf ( "Enter the numbers " );      for ( i = 0 ; i < n ; i ++)      {          scanf ( " %f " ,& x [ i ]);     }      for ( i = 0 ; i < n ; i ++)     {          sum += x [ i ];     }      mean = sum / n ;      sum = 0 ;      for ( i = 0 ; i < n ; i ++)     {          sum = sum +( x [ i ]- mean )*( x [ i ]- mean );     }      sd = sqrt ( sum / n );      printf ( "Mean = %6.3f \n "

C Program to Calculate the Factorial of a number using Function

  C Program to Calculate the Factorial of a number using Function.     In this example, we will calculate the factorial of a number using function. Here we have used functions with Arguments and return value to perform this operation. We have declared a user-defined function fact which is called in the main function when printing the result. What is a Factorial of  a Number?      The factorial of a number is the product of all positive integers less than, equal to n. Factorial is denoted by the symbol '!'. Formula of factorial is n!=n x (n-1)! For example: 6!= 6 x 5 x 4 x 3 x 2 x1    = 720 PROGRAM TO CALCULATE THE FACTORIAL OF A NUMBER USING FUNCTION #include <stdio.h> #include <conio.h> int   fact ( int ); void   main () {      int   n ;      printf ( "Enter the number : " );      scanf ( " %d " ,& n );      printf ( "Factorial of  %d  is :  %d " , n , fact ( n ));      getch (); } int   fact ( int   b ) {      int   i , f =

C Program to input and display details of students using structure

 C Program to input and display details of students using structure.       In this example, we will enter the details of students like roll number, name and total marks using structure and will be displayed. The total number of student should be entered according to the requirements of the user(maximum value is 50). We can increase the maximum number by changing the statement struct student[50];  to struct student[100];     Here in the output we have entered details of four student and displayed them accordingly. PROGRAM #include <stdio.h> #include <conio.h> struct   student {      int   roll ;      char   name [ 20 ];      int   total ; }; void   main () {      int   i , n ;      struct   student   std [ 50 ];      printf ( "Enter the number of students :" );      scanf ( " %d " ,& n );      printf ( " \n Enter the Students Details. \n " );      for ( i = 0 ; i < n ; i ++)     {          printf ( "Enter Roll Number : " );