One Dimensional Array
/* Author : ITVoyagers (https://itvoyagers.in/) Date :25th December 2018 Description : One Dimensional Array. */ #include <conio.h> #include <stdio.h> void main() { int a[10],c; char n[]="myname";// or char n[]={'m','y','n','a','m','e'}; clrscr(); printf("Enter 10 number in array: "); for(c=0;c<10;c++) { scanf(" %d n",&a[c]); } printf("print integer array n"); for(c=0;c<10;c++) { printf("%d n",a[c]); } printf("Enter characters in array: "); scanf("%s n",&a); /* or for(c=1;c<=10;c++) { scanf("%d n",&a[c]); } */ printf("print character array n"); for(c=0;c<10;c++) { printf("%c",n[c]); }// or printf("%s",n); getch(); }
Output:
Enter 10 number in array: 0
1
2
3
4
5
6
7
8
9
0
print integer array
0
1
2
3
4
5
6
7
8
9
Enter characters in array: myname
print character array
myname
Two Dimensional Array
/* Author : ITVoyagers (https://itvoyagers.in/) Date :25th December 2018 Description : Two Dimensional Array. */ #include <stdio.h> #include <conio.h> void main() { int a[][3]={1,2,3,4,5,6,7,8,9},r,c; for(r=0;r<3;r++) { for(c=0;c<3;c++) { printf("%d t",a[r][c]); } printf("n"); } getch(); }
Output:
1 2 3
4 5 6
7 8 9