Skip to main content

Posts

(1+2+3.....n) Sum of n natural numbers, (1^2 + 2^2+3^2 ...... n^2)Sum square of n natural numbers, Sum cube of n natural numbers program in C language .

   Natural numbers program in c language                  H ow to make  (1+2+3.....n) Sum of n natural numbers, (1^2 + 2^2+3^2 ...... n^2)Sum square of n natural numbers, Sum cube of n natural numbers program in C language. Then today we will know about it through this program ...    Sum of n natural numbers            The Sum of n natural number formula are 1+2+3+....n = n(n+1)/2=(n^2+n)/2. The math.h header file is used in this program because the pow() function is defined in this header file. The function pow() syntax is double pow(double a , double b).   The double is a data type in c language and it's also defined as %lf for input. In this program add= (k+x)/2 where are k=n^2 ,x=n. /*SUM OF N NATURAL NUMBERS*/ #include"stdio.h" #include"math.h" int main() { double x,y=2; printf("ENTER THE NATURAL NUMBER:"); scanf("%lf",&x); double n=pow(x,y); int add=(n...

Matrix Addition and subtraction program in C language

  Matrix Addition and Subtraction program in C language Today here you will be able to learn about multiple tasks in Matrix-like addition, subtraction, and multiplication. @#1.Matrix Addition   Suppose that we have two matrices of 3X3 orders. This matrix A and B. In this program   C is the addition of A & B; i and k are used for initialization. Matrix Addition Program  #include"stdio.h" int main() { int A[10][10],B[10][10],C[10][10],i,k,row,col; printf("Enter The Matrix row & col = "); scanf("%d %d",&row,&col); printf("Enter the First matrix :\n"); for(i=0;i Output is:  Enter The Matrix row & col = 2 3 Enter the First matrix : Enter matrix[0][0]=2 Enter matrix[0][1]=1 Enter matrix[0][2]=3 Enter matrix[1][0]=6 Enter matrix[1][1]=54 Enter matrix[1][2]=7 First matrix are: 2       1       3 6       54      7 Enter the Second matrix : Enter matrix[0][0]=8 Enter matrix[0][1...

Matrix program or 2D Array in C language Transpose of Matrix program in C language

 Matrix program or 2D Array in C language  In C language ,A two dimensional array is also known as matrix .Today we will learn about Matrix  .We all know that we also use loop to define an array .We will create a matrix program using a nested for loop. 1.Matrix program in C language: /*MATRIX PROGRAM*/ #include"stdio.h" int main() { int a[10][10]; int r,c,k,l; printf("ENTER THE ROW AND COL:"); scanf("%d %d",&r,&c); printf("ENTER THE MATRIX ELEMENTS:"); for(k=0;k Output are: ENTER THE ROW AND COL:2 3 ENTER THE MATRIX ELEMENTS:ENTER a[0][0] : 2 ENTER a[0][1] : 5 ENTER a[0][2] : 7 ENTER a[1][0] : 8 ENTER a[1][1] : 6 ENTER a[1][2] : 1 MATRIX ARE: 2       5       7 8       6       1 2.Transpose of matrix in C language:                         Matrix    a a[0][0]= 4,   a[0][1]=1,   a[0][2]=8:...

Age calculating through date of birth program in C language

DATE OF BIRTH PROGRAM IN C LANGUAGE          Today's date - your date of birth = your current age  There are fifth condition are happening.. @1.IF today date 13.7.2021 and date of birth 15.9.2001 age are (2021-2001).(7-9).(13-15) = 20.-2.-2   but it's wrong real age will be 19year.9month.28days .Then first condition will be (days < 0)&&(month<0) @2.IF today date 13.7.2021 and date of birth 12.9.2001 age are(2021-2001).(7-9).(13-12) = 20.-2.1 but it's wrong real age will be 19 year . 10 month . 1 days .Then  second condition will be (days>0)&&(month<0). @3.IF today date 13.7.2021 and date of birth 13.9.2001 age are(2021-2001).(7-9).(13-13) = 20.-2.0 but it's wrong real age will be 19 year . 10 month . 0days .Then  third condition will be (days==0)&&(month<0). @4.IF today date 13.7.2021 and date of birth 13.9.2001 age are(2021-2001).(7-9).(13-13) = 20.1.0 but it's wrong real age will be 19...

Arithmetic program in C language || Calculator program in C language

  Calculator  program in C language .           First of all let us know its logic .how is this working . Now let's see it's process . In C language , %d is used to define it's integers and %f is used to define it's floats. In C language , the (+) sign is used as a plus , the (-) sign used as a minus , the (*) sign is used for multiplies and the (/) sign is used for division.                %0.2f it means any float value like 52.987 = 52.98.it show only 2 place of the decimal. PROGRAM                          /*ARITHMETIC PROGRAM IN C LANGUAGE*/ #include"stdio.h" int main() { float a,b,sum,sub,mult,div ; char sign; printf("SELECT ANY SIGN (+ - * / ) :"); scanf("%c",&sign); printf("ENTER THE FIRST NUMERIC VALUE:"); scanf("%f",&a); printf("ENTER THE SECOND NUMERIC VALUE:"); scanf("%f",&b); switch(sign) { case '+':...

Two dimensional array in C language or matrix program in c language

 Two dimensional arrays: 1.Two dimensional array is known as matrix. 2.An array with two subscripts is termed as two-dimensional array. 3.We know that a one dimensional array can store a row of elements, so a two-dimensional array enables us to store multiple roes of elements. The syntax of declaring a two-dimensional array is : Data-type array name[row][column]; For reading value : for(k=0;k<4;k++) { for(l=0;l<3;l++) { scanf("%d",&a[k][l]); } } For displaying value : for(k=0;k<4;k++) { for(l=0;l<3;l++) { printf("%d",a[k][l]); } printf("\n"); } Simple Matrix Program : #include"stdio.h" int main() { int a[3][3]; int k,l; printf("Enter the array elements: \n"); for(k=0;k<3;k++)  //for reading value// { for(l=0;l<3;l++) { printf("Enter a[%d][%d] :",k,l); scanf("%d",&a[k][l]); } } printf("\n\nMatrix are: \n"); for(k=0;k<3;k++)  //for displaying value...

One dimensional array declaration in c language basic of array

One D array **Definition of array** Array can be define as a collection of data object which are stored in consecutive memory location with a common variable name.                                                                                                        or  Array is the collection of similar data types or collection of similar entity stored in contiguous memory location . **Initialization of array** Array can be made initialization at the time of declaration itself. The general form of array initialization is as below  1.Data type array name[size] 2. Data type array name[size]={element1,element2,element3,.....} Example: int a[[4]={1,5,8,4} char d[3]={'A','R',u...