Array Declaration and Dimensional :

What is array ?

An array is a collection of data items or a kind of data structure that can store a fixed size sequential collection of elements of the same type.

Single / One Dimensional Array :

Single / One Dimensional array is used to represent and store data in a liner form and only one subscript variable is called Single / One dimensional array.

Syntax :

<data-type> <array_name> [size];

Example :

  1. /* Description: program to find sum of N integers */
  2. #include<stdio.h>
  3. main()
  4. {
  5. int a[20],i,n,sum=0;
  6. printf("How many integers : ");
  7. scanf("%d",&n);
  8. printf("----------------------");
  9. for(i=1;i<=n;i++)
  10. {
  11. printf("\nNo. %d - Value enter: ",i);
  12. scanf("%d",&a[i]);
  13. }
  14. for(i=1;i<=n;i++)
  15. {
  16. sum=sum+a[i];
  17. }
  18. printf("----------------------");
  19. printf("\nsum of all integers: %d",sum);
  20. getch();
  21. }

Output :

c language - program to find sum of N integers

Multi Dimensional Array :

Array have more than one subscript variable is called multi dimensional array, Multi dimensional array also represent or store data.

Syntax :

<data-type> <array_name> [row_subscript][colum_subscript];

Example :

  1. /* Description: matrix sum */
  2. #include<stdio.h>
  3. main()
  4. {
  5. int a[10][10],b[10][10],sum[10][10],i,j,m,n;
  6. printf("Enter order of matrix: ");
  7. scanf("%d %d",&m,&n);
  8. printf("\nput 1st matrix values:\n");
  9. for(i=1;i<=m;i++)
  10. {
  11. for(j=1;j<=n;j++)
  12. {
  13. scanf("%d",&a[i][j]);
  14. }
  15. }
  16. printf("\nput 2nd matrix values:\n");
  17. for(i=1;i<=m;i++)
  18. {
  19. for(j=1;j<=n;j++)
  20. {
  21. scanf("%d",&b[i][j]);
  22. }
  23. }
  24. printf("\nCalculating...\n");
  25. for(i=1;i<=m;i++)
  26. {
  27. for(j=1;j<=n;j++)
  28. {
  29. sum[i][j]=a[i][j]+b[i][j];
  30. }
  31. }
  32. printf("Result :\n\n");
  33. for(i=1;i<=m;i++)
  34. {
  35. for(j=1;j<=n;j++)
  36. {
  37. printf("%d \t",sum[i][j]);
  38. }
  39. printf("\n");
  40. }
  41. getch();
  42. }

Output :

c language - matrix sum

Computer Science Engineering

Special Notes

It's a special area where you can find special questions and answers for CSE students or IT professionals. Also, In this section, we try to explain a topic in a very deep way.

CSE Notes