当前位置:网站首页>C language array processing batch data
C language array processing batch data
2022-04-23 17:55:00 【Chshyz】
One dimensional array 、 Two dimensional array 、 Array of strings
Environmental Science :CentOS7
PS: An array is a collection of ordered data ( Each element belongs to the same data type , Use a unified array name and subscript to uniquely determine the elements in the array .)
- One dimensional array ( Type character Array name [ Constant expression ])
Example : First give the array elements with a circular structure a[0]~a[9] assignment 0 To 9, And then follow 9-0 Output
#include <stdio.h>
int main() {
int i, a[10]; # Defining integer variables i And integer arrays a
for (i = 0; i <= 9; i ++) # One by one 10 Element assignment
a[i] = i;
for (i = 9; i >= 0; i --) # Output in reverse order
printf ("%d\n", a[i]);
printf("\n");
return 0;
}
[[email protected] c]# gcc -o for2 for2.c
[[email protected] c]# ./for2
9
8
7
6
5
4
3
2
1
0
- Two dimensional array ( Type name Array name [ Constant expression ] [ Constant expression ])
Example : Row and column transpose
#include <stdio.h>
int main() {
int a[2] [3] = {
{
1, 2, 3}, {
4,5,6}
};
int b[3] [2], i, j;
printf ("array a:\n");
for (i = 0; i < 2; i ++) {
for (j = 0; j < 3; j ++) {
printf ("%5d", a[i] [j]);
b[j] [i] = a [i] [j];
}
printf ("\n");
}
printf ("array b:\n");
for (i = 0; i < 3; i ++) {
for (j = 0; j < 2; j ++)
printf ("%5d", b[i] [j]);
printf ("\n");
}
return 0;
}
[[email protected] c]# gcc -o for3 for3.c
[[email protected] c]# ./for3
array a:
1 2 3
4 5 6
array b:
1 4
2 5
3 6
- A character array
Example : The diamond
#include <stdio.h>
int main() {
char a[][5] = {
{
' ',' ','*'},
{
' ','*',' ','*'},
{
'*',' ',' ',' ','*'},
{
' ','*',' ','*'},
{
' ',' ','*'}
};
int i, j;
for (i = 0; i < 5; i ++) {
for (j = 0; j < 5; j ++)
printf ("%c", a[i][j]);
printf ("\n");
}
return 0;
}
[[email protected] c]# gcc -o for4 for4.c
[[email protected] c]# ./for4
*
* *
* *
* *
*
- Count the number of words
#include <stdio.h>
int main() {
char b[100];
int i, num = 0, word = 0;
char c;
gets (b);
for (i = 0; (c = b[i]) != '\0'; i ++)
if (c == ' ') word = 0;
else if (word == 0) {
word = 1;
num ++;
}
printf ("you have %d words in this line.\n", num);
return 0;
}
[[email protected] c]# ./for5
huang hong zhang
you have 3 words in this line.
版权声明
本文为[Chshyz]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230547413965.html
边栏推荐
猜你喜欢

SystemVerilog(六)-变量
![C1 notes [task training chapter I]](/img/2b/94a700da6858a96faf408d167e75bb.png)
C1 notes [task training chapter I]
![SQL optimization for advanced learning of MySQL [insert, primary key, sort, group, page, count]](/img/60/e4d47d458dd98a0c6ba51874e07c30.png)
SQL optimization for advanced learning of MySQL [insert, primary key, sort, group, page, count]

Cross domain settings of Chrome browser -- including new and old versions

Laser slam theory and practice of dark blue College Chapter 3 laser radar distortion removal exercise

MySQL进阶学习之SQL优化【插入,主键,排序,分组,分页,计数】

440. 字典序的第K小数字(困难)-字典树-数节点-字节跳动高频题

Client example analysis of easymodbustcp

Chrome浏览器的跨域设置----包含新老版本两种设置

Implementation of image recognition code based on VGg convolutional neural network
随机推荐
Applet learning notes (I)
Compilation principle first set follow set select set prediction analysis table to judge whether the symbol string conforms to the grammar definition (with source code!!!)
Go对文件操作
C1 notes [task training part 2]
ROS package NMEA_ navsat_ Driver reads GPS and Beidou Positioning Information Notes
MySQL 中的字符串函数
394. 字符串解码-辅助栈
Submit local warehouse and synchronize code cloud warehouse
纳米技术+AI赋能蛋白质组学|珞米生命科技完成近千万美元融资
关于gcc输出typeid完整名的方法
2021 Great Wall Cup WP
958. Complete binary tree test
JS forms the items with the same name in the array object into the same array according to the name
Oil monkey website address
MySQL advanced index [classification, performance analysis, use, design principles]
QTableWidget使用讲解
Hcip fifth experiment
2022 Jiangxi energy storage technology exhibition, China Battery exhibition, power battery exhibition and fuel cell Exhibition
[appium] write scripts by designing Keyword Driven files
Go语言JSON包使用