将1加到给定的数字上?
将1加到给定数字的程序会将变量的值加1。这通常在计数器中使用。
有2种增加方法,可用于将给定数增加1-
将数字简单加一,然后将其重新分配给变量。
在程序中使用增量运算符。
方法1-使用重新分配方法
此方法采用变量,将其加1,然后重新分配其值。
范例程式码
#include <stdio.h>
int main(void) {
int n = 12;
printf("The initial value of number n is %d \n", n);
n = n+ 1;
printf("The value after adding 1 to the number n is %d", n);
return 0;
}输出结果
The initial value of number n is 12 The value after adding 1 to the number n is 13
方法2-使用增量运算符
此方法使用增量运算符将1加到给定的数字上。这是将数字加1的简便方法。
范例程式码
#include <stdio.h>
int main(void) {
int n = 12;
printf("The initial value of number n is %d \n", n);
n++;
printf("The value after adding 1 to the number n is %d", n);
return 0;
}输出结果
The initial value of number n is 12 The value after adding 1 to the number n is 13
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下