- Related Questions & Answers
- Add minimum number to an array so that the sum becomes even in C programming
- C/C++ Program for nth Catalan Number?
- C Program to Check if all digits of a number divide it
- Concatenate a string given number of times in C++ programming
- Superperfect Number in C programming
- HTML DOM Input Number value Property
- HTML DOM Input Number type Property
- How to find the number of days in a month of a particular year in Java?
- Number of elements a particular tag contains in JavaScript?
- Print multiples of Unit Digit of Given Number in C Program
- C/C++ Programming to Count trailing zeroes in factorial of a number?
- C++ Programming for Smallest K digit number divisible by X?
- To find sum of even factors of a number in C++ Program?
- Generating random number list in Python
- Abundant Number in C ?

A program to add 1 to a given number increments the value of the variable by 1 . This is general used in counters.

There are 2 methods to increase that can be used to increase a given number by 1 −

Simple adding of one to the number and reassigning it to the variable.

Using increment operator in the program.

This method takes the variable, add 1 to it and then reassigns its value.

#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

This method uses the increment operator to add 1 to the given number. This is a shorthand trick to add 1 to a number.

#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

Advertisements