C lecture
C lecture
C lecture
Single-Dimensional Arrays
C programming Arrays is the collection of
elements of the same data types.
Declaration:
typename variablename[size]
typename is any type
For example
int a[10]; ----Defines an array of int with subscripts
ranging from 0 to 9
There are 10*sizeof(int) bytes of memory
reserved for this array.
for(i=0;i<n;i++)
{ for(j=0;j<=i;j++)
printf("%d ",A[i][j]);
printf("\n\n");
}
#include<stdio.h> printf("\nThe Second matrix
int main(){ is\n");
int a[3][3],b[3][3],c[3][3],i,j; for(i=0;i<3;i++){
printf("Enter the First matrix"); printf("\n");
for(i=0;i<3;i++) for(j=0;j<3;j++)
for(j=0;j<3;j++) printf("%d\t",b[i][j]);
scanf("%d",&a[i][j]); }
printf("\nEnter the Second for(i=0;i<3;i++)
matrix"); for(j=0;j<3;j++)
for(i=0;i<3;i++) c[i][j]=a[i][j]+b[i][j];
for(j=0;j<3;j++) printf("\nThe Addition of
scanf("%d",&b[i][j]); two matrix is\n");
printf("\nThe First matrix is\n"); for(i=0;i<3;i++){
for(i=0;i<3;i++){ printf("\n");
printf("\n"); for(j=0;j<3;j++)
for(j=0;j<3;j++) printf("%d\t",c[i][j]);
printf("%d\t",a[i][j]); }
} return 0;
#include<stdio.h> printf("The Second Matrix is : \n");
void main() { for (i = 0; i < 3; i++) {
int a[10][10], b[10][10], c[10][10], for (j = 0; j < 3; j++) {
i, j, k; printf(" %d ", b[i][j]); }
int sum = 0; printf("\n"); }
printf("\nEnter First Matrix : \n"); for (i = 0; i < 3; i++) {
for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) {
for (j = 0; j < 3; j++) { sum = 0;
scanf("%d", &a[i][j]); for (k = 0; k <3; k++) {
} } sum = sum + a[i][k] * b[k][j];
printf("\nEnter Second Matrix:\n"); }
for (i = 0; i < 3; i++) { c[i][j] = sum;
for (j = 0; j < 3; j++) { } }
scanf("%d", &b[i][j]); printf("\nMultiplication Of Two
} } Matrices : \n");
printf("The First Matrix is: \n"); for (i = 0; i < 3; i++) {
for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) {
for (j = 0; j < 3; j++) { printf(" %d ", c[i][j]);
printf(" %d ", a[i][j]); }
} printf("\n");
printf("\n"); } } }