# C Programing Code ```Addition of two numbers in C
The addition of two numbers in C language is performing the arithmetic
operation of adding them and printing their sum on the screen. For
example, if the input is 5, 6, the output will be 11.
 Addition program in C
#include &lt;stdio.h&gt;
int main()
{
int x, y, z;
printf(&quot;Enter two numbers to add\n&quot;);
scanf(&quot;%d%d&quot;, &amp;x, &amp;y);
z = x + y;
printf(&quot;Sum of the numbers = %d\n&quot;, z);
return 0;
}
 Addition without using third variable
#include&lt;stdio.h&gt;
int main()
{
int a = 1, b = 2;
/* Storing result of the addition in variable a */
a = a + b;
printf(&quot;Sum of a and b = %d\n&quot;, a);
return 0;
}
 C program to add two numbers repeatedly
#include &lt;stdio.h&gt;
int main()
{
int a, b, c;
char ch;
while (1) {
printf(&quot;Input two integers\n&quot;);
scanf(&quot;%d%d&quot;, &amp;a, &amp;b);
getchar();
c = a + b;
printf(&quot;(%d) + (%d) = (%d)\n&quot;, a, b, c);
printf(&quot;Do you wish to add more numbers (y/n)\n&quot;);
scanf(&quot;%c&quot;, &amp;ch);
if (ch == 'y' || ch == 'Y')
continue;
else
break;
}
return 0;
}
 C program for addition of two numbers using a
function
We can calculate sum of two integers using a function.
#include&lt;stdio.h&gt;
int main()
{
long first, second, sum;
scanf(&quot;%ld%ld&quot;, &amp;first, &amp;second);
sum = addition(first, second);
printf(&quot;%ld\n&quot;, sum);
return 0;
}
long addition(long a, long b)
{
long result;
result = a + b;
return result;
}
 Sum of Natural Numbers Using for Loop
#include &lt;stdio.h&gt;
int main() {
int n, i, sum = 0;
printf(&quot;Enter a positive integer: &quot;);
scanf(&quot;%d&quot;, &amp;n);
for (i = 1; i &lt;= n; ++i) {
sum += i;
}
printf(&quot;Sum = %d&quot;, sum);
return 0;
}
 C program to calculate sum of n numbers using an
array
#include &lt;stdio.h&gt;
int main()
{
int n, sum = 0, c, array;
scanf(&quot;%d&quot;, &amp;n);
for (c = 0; c &lt; n; c++)
{
scanf(&quot;%d&quot;, &amp;array[c]);
sum = sum + array[c];
}
printf(&quot;Sum = %d\n&quot;, sum);
return 0;
}
 C program for addition of n numbers using recursion
#include &lt;stdio.h&gt;
long calculate_sum(int [], int);
int main()
{
int n, c, array;
long result;
scanf(&quot;%d&quot;, &amp;n);
for (c = 0; c &lt; n; c++)
scanf(&quot;%d&quot;, &amp;array[c]);
result = calculate_sum(array, n);
printf(&quot;Sum = %ld\n&quot;, result);
return 0;
}
long calculate_sum(int a[], int n) {
static long sum = 0;
if (n == 0)
return sum;
sum = sum + a[n-1];
return calculate_sum(a, --n);
}
 C Program to check whether the given integer is
positive or negative
#include &lt;stdio.h&gt;
void main()
{
int num;
printf(&quot;Enter a number: \n&quot;);
scanf(&quot;%d&quot;, &amp;num);
if (num &gt; 0)
printf(&quot;%d is a positive number \n&quot;, num);
else if (num &lt; 0)
printf(&quot;%d is a negative number \n&quot;, num);
else
printf(&quot;0 is neither positive nor negative&quot;);
}
 Program to Check Even or Odd
#include &lt;stdio.h&gt;
int main() {
int num;
printf(&quot;Enter an integer: &quot;);
scanf(&quot;%d&quot;, &amp;num);
// True if num is perfectly divisible by 2
if(num % 2 == 0)
printf(&quot;%d is even.&quot;, num);
else
printf(&quot;%d is odd.&quot;, num);
return 0;
}
 C program to find HCF and LCM
C program to find HCF and LCM: The code below find the highest
common factor and the least common multiple of two integers.
HCF is also known as the greatest common divisor (GCD) or the
greatest common factor (GCF).
C programming code
#include &lt;stdio.h&gt;
int main() {
int a, b, x, y, t, gcd, lcm;
printf(&quot;Enter two integers\n&quot;);
scanf(&quot;%d%d&quot;, &amp;x, &amp;y);
a = x;
b = y;
while
t =
b =
a =
}
(b != 0) {
b;
a % b;
t;
gcd = a;
lcm = (x*y)/gcd;
printf(&quot;Greatest common divisor of %d and %d = %d\n&quot;, x, y,
gcd);
printf(&quot;Least common multiple of %d and %d = %d\n&quot;, x, y,
lcm);
return 0;
}
 C Program for Sum the digits of a given number
# include&lt;stdio.h&gt;
/* Function to get sum of digits */
int getSum(int n)
{
int sum = 0;
while (n != 0)
{
sum = sum + n % 10;
n = n/10;
}
return sum;
}
int main()
{
int n = 687;
printf(&quot; %d &quot;, getSum(n));
return 0;
}
 Program to Check Prime Number
#include &lt;stdio.h&gt;
int main() {
int n, i, flag = 0;
printf(&quot;Enter a positive integer: &quot;);
scanf(&quot;%d&quot;, &amp;n);
for (i = 2; i &lt;= n / 2; ++i) {
// condition for non-prime
if (n % i == 0) {
flag = 1;
break;
}
}
if (n == 1) {
printf(&quot;1 is neither prime nor composite.&quot;);
}
else {
if (flag == 0)
printf(&quot;%d is a prime number.&quot;, n);
else
printf(&quot;%d is not a prime number.&quot;, n);
}
return 0;
}
```