Skip to main content

Posts

C++ program to define a class circle to represent circles. Add a data member radius to store the radius of a circle. Write member functions area() and perimeter() to compute the area and perimeter of a circle.

  C++ program to define a class circle to represent circles. Add a data member radius to store the radius of a   circle. Write member functions area() and perimeter() to compute the area and perimeter of a circle.     To define a Circle class in C++, we start by declaring the class with the class keyword, followed by the name of the class. In this case, we'll call it Circle . We'll then define a private data member to store the radius of the circle. Here's the code to do that:    class Circle {      private:      double radius;    };          Next, we need to define public member functions that can set and get the value of the radius, as well as calculate the area and perimeter of the circle. Here's the full code for the Circle class: class Circle { private: double radius; public: void setRadius(double r) { radius = r; } double getRadius() { return radius; } double area() { return 3.14159 * r

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