0% found this document useful (0 votes)
35 views4 pages

Add 2 Integers

This document contains 5 C programs that demonstrate basic programming concepts: 1) Adding two integers, 2) Checking if a number is prime, 3) Printing the Fibonacci series, 4) Checking if a number is a palindrome, and 5) Checking if a number is even or odd. Each program uses simple logic and control structures like if/else statements and for loops to perform its task and print the output.

Uploaded by

Amal Jesudas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views4 pages

Add 2 Integers

This document contains 5 C programs that demonstrate basic programming concepts: 1) Adding two integers, 2) Checking if a number is prime, 3) Printing the Fibonacci series, 4) Checking if a number is a palindrome, and 5) Checking if a number is even or odd. Each program uses simple logic and control structures like if/else statements and for loops to perform its task and print the output.

Uploaded by

Amal Jesudas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

1.

Add 2 integers:

#include <stdio.h>

int main() {

int number1, number2, sum;

printf("Enter two integers: ");

scanf("%d %d", &number1, &number2);

// calculating sum

sum = number1 + number2;

printf("%d + %d = %d", number1, number2, sum);

return 0;

2. Check prime numbers:

#include <stdio.h>

int main() {

int n, i, flag = 0;

printf("Enter a positive integer: ");

scanf("%d", &n);

for (i = 2; i <= n / 2; ++i) {

// condition for non-prime

if (n % i == 0) {

flag = 1;

break;

}
}

if (n == 1) {

printf("1 is neither prime nor composite.");

else {

if (flag == 0)

printf("%d is a prime number.", n);

else

printf("%d is not a prime number.", n);

return 0;

3. Fibonacci series:

#include <stdio.h>

int main() {

int i, n, t1 = 0, t2 = 1, nextTerm;

printf("Enter the number of terms: ");

scanf("%d", &n);

printf("Fibonacci Series: ");

for (i = 1; i <= n; ++i) {

printf("%d, ", t1);

nextTerm = t1 + t2;

t1 = t2;

t2 = nextTerm;

return 0;
}

4. Palindrome or not:

#include <stdio.h>

int main() {

int n, reversedN = 0, remainder, originalN;

printf("Enter an integer: ");

scanf("%d", &n);

originalN = n;

// reversed integer is stored in reversedN

while (n != 0) {

remainder = n % 10;

reversedN = reversedN * 10 + remainder;

n /= 10;

// palindrome if orignalN and reversedN are equal

if (originalN == reversedN)

printf("%d is a palindrome.", originalN);

else

printf("%d is not a palindrome.", originalN);

return 0;

5. Even or odd:

#include <stdio.h>

int main() {

int num;
printf("Enter an integer: ");

scanf("%d", &num);

// True if num is perfectly divisible by 2

if(num % 2 == 0)

printf("%d is even.", num);

else

printf("%d is odd.", num);

return 0;

You might also like