SlideShare a Scribd company logo
1 of 31
https://www.facebook.com/fcoursesbd Page 1 of 31
C Programming 28 Program
Table of Contents
Page no
1) C Program to Check Whether a Number is Even or Odd...................................................................................................12
2) C Program to Check Whether a Character is Vowel or Consonant ........................................................................................22
3) C Program to Find the Largest Number Among Three Numbers .......................................................................................33
4) C Program to Check Leap Year ....................................................................................................................................................45
5) C Program to Check Whether a Number is Positive or Negative ...........................................................................................55
6) C Program to Check Whether a Character is an Alphabet or not ......................................................................................66
7 ) C Program to Generate Multiplication Table ....................................................................................................................77
8 ) C Program to Display Fibonacci Sequence .........................................................................................................................88
9 ) C Program to Find GCD of two Numbers............................................................................................................................99
10 ) C Program to Find LCM (Lowest Common Multiple) of two Number ...........................................................................101
11) C Program to Display Characters from A to Z Using Loop ..............................................................................................111
12) C Program to Reverse a Number.....................................................................................................................................122
13 ) C Program to Calculate the Power of a Number............................................................................................................133
14) C Program to Check Whether a Number is Palindrome or Not......................................................................................144
15) C Program to Check Whether a Number is Prime or Not...............................................................................................155
16) C Program to Display Prime Numbers Between Two Intervals......................................................................................166
17 ) C Program to Check Armstrong Number........................................................................................................................177
18) C Program to Display Factors of a Number.....................................................................................................................188
19) C Programming Code To Create Pyramid and Pattern ...................................................................................................199
20) C Program to Make a Simple Calculator Using switch...case .........................................................................................200
21) C Programming Code To Create Pyramid and Pattern ...................................................................................................211
22) C Program to Display Prime Numbers Between Intervals Using Function ....................................................................222
23) C Program to Check Prime or Armstrong Number Using User-defined Function..........................................................233
24) C Program to Find the Sum of Natural Numbers using Recursion .................................................................................255
25) C Program to Find Factorial of a Number Using Recursion ...........................................................................................266
26) C Program to Find G.C.D Using Recursion.......................................................................................................................277
27) C program to Reverse a Sentence Using Recursion........................................................................................................288
28) C program to calculate the power using recursion.........................................................................................................299
https://www.facebook.com/fcoursesbd Page 2 of 31
1) C Program to Check Whether a Number is Even or Odd
#include <stdio.h>
int main()
{
int number;
printf("Enter an integer: ");
scanf("%d", &number);
if(number % 2 == 0)
printf("%d is even.", number);
else
printf("%d is odd.", number);
return 0;
}
Output
https://www.facebook.com/fcoursesbd Page 3 of 31
2) C Program to Check Whether a Character is Vowel or Consonant
#include <stdio.h>
int main()
{
char c;
int isLowercaseVowel, isUppercaseVowel;
printf("Enter an alphabet: ");
scanf("%c",&c);
isLowercaseVowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');
isUppercaseVowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');
if (isLowercaseVowel || isUppercaseVowel)
printf("%c is a vowel.", c);
else
printf("%c is a consonant.", c);
return 0;
}
Output
https://www.facebook.com/fcoursesbd Page 4 of 31
3) C Program to Find the Largest Number Among Three Numbers
#include <stdio.h>
int main()
{
double n1, n2, n3;
printf("Enter three numbers: ");
scanf("%lf %lf %lf", &n1, &n2, &n3);
if( n1>=n2 && n1>=n3)
printf("%.2lf is the largest number.", n1);
else if (n2>=n1 && n2>=n3)
printf("%.2lf is the largest number.", n2);
else
printf("%.2lf is the largest number.", n3);
return 0;
}
Output
https://www.facebook.com/fcoursesbd Page 5 of 31
4) C Program to Check Leap Year
#include <stdio.h>
int main()
{
int year;
printf("Enter year : ");
scanf("%d", &year);
if(((year % 4 == 0) && (year % 100 !=0)) || (year % 400==0))
{
printf("LEAP YEAR");
}
else
{
printf("COMMON YEAR");
}
return 0;
}
Output
https://www.facebook.com/fcoursesbd Page 6 of 31
5) C Program to Check Whether a Number is Positive or Negative
#include <stdio.h>
int main()
{
double number;
printf("Enter a number: ");
scanf("%lf", &number);
if (number < 0.0)
printf("You entered a negative number.");
else if ( number > 0.0)
printf("You entered a positive number.");
else
printf("You entered 0.");
return 0;
}
Output
https://www.facebook.com/fcoursesbd Page 7 of 31
6) C Program to Check Whether a Character is an Alphabet or not
#include <stdio.h>
int main()
{
char c;
printf("Enter a character: ");
scanf("%c",&c);
if( (c>='a' && c<='z') || (c>='A' && c<='Z'))
printf("%c is an alphabet.",c);
else
printf("%c is not an alphabet.",c);
return 0;
}
Output
https://www.facebook.com/fcoursesbd Page 8 of 31
7 ) C Program to Generate Multiplication Table
#include <stdio.h>
int main()
{
int n, i;
printf("Enter an integer: ");
scanf("%d",&n);
for(i=1; i<=10; ++i)
{
printf("%d * %d = %d n", n, i, n*i);
}
return 0;
}
Output
https://www.facebook.com/fcoursesbd Page 9 of 31
8 ) C Program to Display Fibonacci Sequence
#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;
}
https://www.facebook.com/fcoursesbd Page 10 of 31
9 ) C Program to Find GCD of two Numbers
#include <stdio.h>
int main()
{
int n1, n2, i, gcd;
printf("Enter two integers: ");
scanf("%d %d", &n1, &n2);
for(i=1; i <= n1 && i <= n2; ++i)
{
if(n1%i==0 && n2%i==0)
gcd = i;
}
printf("G.C.D of %d and %d is %d", n1, n2, gcd);
return 0;
}
Output
https://www.facebook.com/fcoursesbd Page 11 of 31
10 ) C Program to Find LCM (Lowest Common Multiple) of two Numbers
#include <stdio.h>
int main()
{
int n1, n2, i, gcd, lcm;
printf("Enter two positive integers: ");
scanf("%d %d",&n1,&n2);
for(i=1; i <= n1 && i <= n2; ++i)
{
if(n1%i==0 && n2%i==0)
gcd = i;
}
lcm = (n1*n2)/gcd;
printf("The LCM of two numbers %d and %d is %d.", n1, n2, lcm);
return 0;
}
Output
https://www.facebook.com/fcoursesbd Page 12 of 31
11) C Program to Display Characters from A to Z Using Loop
#include <stdio.h>
int main()
{
char c;
for(c = 'A'; c <= 'Z'; ++c)
printf("%c ", c);
return 0;
}
Output
https://www.facebook.com/fcoursesbd Page 13 of 31
12) C Program to Reverse a Number
#include <stdio.h>
int main()
{
int n, reverse = 0;
printf("Enter a number to reversen");
scanf("%d", &n);
while (n != 0)
{
reverse = reverse * 10;
reverse = reverse + n%10;
n = n/10;
}
printf("Reverse of entered number is = %dn", reverse);
return 0;
}
Output
https://www.facebook.com/fcoursesbd Page 14 of 31
13 ) C Program to Calculate the Power of a Number
#include <stdio.h>
int main()
{
int base, exponent;
long long result = 1;
printf("Enter a base number: ");
scanf("%d", &base);
printf("Enter an exponent: ");
scanf("%d", &exponent);
while (exponent != 0)
{
result *= base;
--exponent;
}
printf("Answer = %lld", result);
return 0;
}
Output
https://www.facebook.com/fcoursesbd Page 15 of 31
14) C Program to Check Whether a Number is Palindrome or Not
#include <stdio.h>
int main()
{
int n, reversedInteger = 0, remainder, originalInteger;
printf("Enter an integer: ");
scanf("%d", &n);
originalInteger = n;
while( n!=0 )
{
remainder = n%10;
reversedInteger = reversedInteger*10 + remainder;
n /= 10;
}
if (originalInteger == reversedInteger)
printf("%d is a palindrome.", originalInteger);
else
printf("%d is not a palindrome.", originalInteger);
return 0;
}
Output
https://www.facebook.com/fcoursesbd Page 16 of 31
15) C Program to Check Whether a Number is Prime or Not
#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)
{
if(n%i == 0)
{
flag = 1;
break;
}
}
if (n == 1)
{
printf("1 is neither a prime nor a composite number.");
}
else
{
if (flag == 0)
printf("%d is a prime number.", n);
else
printf("%d is not a prime number.", n);
}
return 0;
} Output
https://www.facebook.com/fcoursesbd Page 17 of 31
16) C Program to Display Prime Numbers Between Two Intervals
#include <stdio.h>
int main()
{
int low, high, i, flag;
printf("Enter two numbers(intervals): ");
scanf("%d %d", &low, &high);
printf("Prime numbers between %d and %d are: ", low, high);
while (low < high)
{
flag = 0;
for(i = 2; i <= low/2; ++i)
{
if(low % i == 0)
{
flag = 1;
break;
}
}
if (flag == 0)
printf("%d ", low);
++low;
}
return 0;
} Output
https://www.facebook.com/fcoursesbd Page 18 of 31
17 ) C Program to Check Armstrong Number
#include <stdio.h>
int main()
{
int number, originalNumber, remainder, result = 0;
printf("Enter a three digit integer: ");
scanf("%d", &number);
originalNumber = number;
while (originalNumber != 0)
{
remainder = originalNumber%10;
result += remainder*remainder*remainder;
originalNumber /= 10;
}
if(result == number)
printf("%d is an Armstrong number.",number);
else
printf("%d is not an Armstrong number.",number);
return 0;
}
Output
https://www.facebook.com/fcoursesbd Page 19 of 31
18) C Program to Display Factors of a Number
#include <stdio.h>
int main()
{
int number, i;
printf("Enter a positive integer: ");
scanf("%d",&number);
printf("Factors of %d are: ", number);
for(i=1; i <= number; ++i)
{
if (number%i == 0)
{
printf("%d ",i);
}
}
return 0;
}
Output
https://www.facebook.com/fcoursesbd Page 20 of 31
19) C Programming Code To Create Pyramid and Pattern
#include <stdio.h>
int main()
{
int i, j, rows;
printf("Enter number of rows: ");
scanf("%d",&rows);
for(i=1; i<=rows; ++i)
{
for(j=1; j<=i; ++j)
{
printf("* ");
}
printf("n");
}
return 0;
} Output
https://www.facebook.com/fcoursesbd Page 21 of 31
20) C Program to Make a Simple Calculator Using switch...case
# include <stdio.h>
int main() {
char operator;
double firstNumber,secondNumber;
printf("Enter an operator (+, -, *,): ");
scanf("%c", &operator);
printf("Enter two operands: ");
scanf("%lf %lf",&firstNumber, &secondNumber);
switch(operator)
{
case '+':
printf("%.1lf + %.1lf = %.1lf",firstNumber, secondNumber, firstNumber + secondNumber);
break;
case '-':
printf("%.1lf - %.1lf = %.1lf",firstNumber, secondNumber, firstNumber - secondNumber);
break;
case '*':
printf("%.1lf * %.1lf = %.1lf",firstNumber, secondNumber, firstNumber * secondNumber);
break;
case '/':
printf("%.1lf / %.1lf = %.1lf",firstNumber, secondNumber, firstNumber / secondNumber);
break;
default:
printf("Error! operator is not correct");
}
return 0; Output
}
https://www.facebook.com/fcoursesbd Page 22 of 31
21) C Programming Code To Create Pyramid and Pattern
#include <stdio.h>
int main()
{
int i, space, rows, k=0;
printf("Enter number of rows: ");
scanf("%d",&rows);
for(i=1; i<=rows; ++i, k=0)
{
for(space=1; space<=rows-i; ++space)
{
printf(" ");
}
while(k != 2*i-1)
{
printf("* ");
++k;
}
printf("n");
}
return 0;
}
Output
https://www.facebook.com/fcoursesbd Page 23 of 31
22) C Program to Display Prime Numbers Between Intervals Using Function
#include <stdio.h>
int checkPrimeNumber(int n);
int main()
{
int n1, n2, i, flag;
printf("Enter two positive integers: ");
scanf("%d %d", &n1, &n2);
printf("Prime numbers between %d and %d are: ", n1, n2);
for(i=n1+1; i<n2; ++i)
{
flag = checkPrimeNumber(i);
if(flag == 1)
printf("%d ",i);
}
return 0;
}
int checkPrimeNumber(int n)
{
int j, flag = 1;
for(j=2; j <= n/2; ++j)
{
if (n%j == 0)
{
flag =0;
break;
}
} Output
return flag;
}
https://www.facebook.com/fcoursesbd Page 24 of 31
23) C Program to Check Prime or Armstrong Number Using User-defined Function
#include <stdio.h>
#include <math.h>
int checkPrimeNumber(int n);
int checkArmstrongNumber(int n);
int main()
{
int n, flag;
printf("Enter a positive integer: ");
scanf("%d", &n);
flag = checkPrimeNumber(n);
if (flag == 1)
printf("%d is a prime number.n", n);
else
printf("%d is not a prime number.n", n);
flag = checkArmstrongNumber(n);
if (flag == 1)
printf("%d is an Armstrong number.", n);
else
printf("%d is not an Armstrong number.",n);
return 0;
}
int checkPrimeNumber(int n)
{
int i, flag = 1;
for(i=2; i<=n/2; ++i)
{
if(n%i == 0)
{
flag = 0;
break;
https://www.facebook.com/fcoursesbd Page 25 of 31
}
}
return flag;
}
int checkArmstrongNumber(int number)
{
int originalNumber, remainder, result = 0, n = 0, flag;
originalNumber = number;
while (originalNumber != 0)
{
originalNumber /= 10;
++n;
}
originalNumber = number;
while (originalNumber != 0)
{
remainder = originalNumber%10;
result += pow(remainder, n);
originalNumber /= 10;
}
if(result == number)
flag = 1;
else
flag = 0;
return flag;
}
Output
https://www.facebook.com/fcoursesbd Page 26 of 31
24) C Program to Find the Sum of Natural Numbers using Recursion
#include <stdio.h>
int addNumbers(int n);
int main()
{
int num;
printf("Enter a positive integer: ");
scanf("%d", &num);
printf("Sum = %d",addNumbers(num));
return 0;
}
int addNumbers(int n)
{
if(n != 0)
return n + addNumbers(n-1);
else
return n;
}
Output
https://www.facebook.com/fcoursesbd Page 27 of 31
25) C Program to Find Factorial of a Number Using Recursion
#include <stdio.h>
long int multiplyNumbers(int n);
int main()
{
int n;
printf("Enter a positive integer: ");
scanf("%d", &n);
printf("Factorial of %d = %ld", n, multiplyNumbers(n));
return 0;
}
long int multiplyNumbers(int n)
{
if (n >= 1)
return n*multiplyNumbers(n-1);
else
return 1;
}
Output
https://www.facebook.com/fcoursesbd Page 28 of 31
26) C Program to Find G.C.D Using Recursion
#include <stdio.h>
int hcf(int n1, int n2);
int main()
{
int n1, n2;
printf("Enter two positive integers: ");
scanf("%d %d", &n1, &n2);
printf("G.C.D of %d and %d is %d.", n1, n2, hcf(n1,n2));
return 0;
}
int hcf(int n1, int n2)
{
if (n2 != 0)
return hcf(n2, n1%n2);
else
return n1;
}
Output
https://www.facebook.com/fcoursesbd Page 29 of 31
27) C program to Reverse a Sentence Using Recursion
#include <stdio.h>
void reverseSentence();
int main()
{
printf("Enter a sentence: ");
reverseSentence();
return 0;
}
void reverseSentence()
{
char c;
scanf("%c", &c);
if( c != 'n')
{
reverseSentence();
printf("%c",c);
}
}
Output
https://www.facebook.com/fcoursesbd Page 30 of 31
28) C program to calculate the power using recursion
#include <stdio.h>
int power(int n1, int n2);
int main()
{
int base, powerRaised, result;
printf("Enter base number: ");
scanf("%d",&base);
printf("Enter power number(positive integer): ");
scanf("%d",&powerRaised);
result = power(base, powerRaised);
printf("%d^%d = %d", base, powerRaised, result);
return 0;
}
int power(int base, int powerRaised)
{
if (powerRaised != 0)
return (base*power(base, powerRaised-1));
else
return 1;
}
Output
https://www.facebook.com/fcoursesbd Page 31 of 31
-: THE END :-

More Related Content

What's hot

C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming CourseDennis Chang
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programmingABHISHEK fulwadhwa
 
C decision making and looping.
C decision making and looping.C decision making and looping.
C decision making and looping.Haard Shah
 
Bruteforce algorithm
Bruteforce algorithmBruteforce algorithm
Bruteforce algorithmRezwan Siam
 
SMIU Lecture #1 & 2 Introduction to Discrete Structure and Truth Table.pdf
SMIU Lecture #1 & 2 Introduction to Discrete Structure and Truth Table.pdfSMIU Lecture #1 & 2 Introduction to Discrete Structure and Truth Table.pdf
SMIU Lecture #1 & 2 Introduction to Discrete Structure and Truth Table.pdfMuhammadUmerIhtisham
 
Analysis and Design of Algorithms
Analysis and Design of AlgorithmsAnalysis and Design of Algorithms
Analysis and Design of AlgorithmsBulbul Agrawal
 
Function in C Programming
Function in C ProgrammingFunction in C Programming
Function in C ProgrammingAnil Pokhrel
 
Backtracking & branch and bound
Backtracking & branch and boundBacktracking & branch and bound
Backtracking & branch and boundVipul Chauhan
 
Introduction to Basic C programming 01
Introduction to Basic C programming 01Introduction to Basic C programming 01
Introduction to Basic C programming 01Wingston
 
Python Unit 3 - Control Flow and Functions
Python Unit 3 - Control Flow and FunctionsPython Unit 3 - Control Flow and Functions
Python Unit 3 - Control Flow and FunctionsDhivyaSubramaniyam
 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structureZaid Shabbir
 
Chapter 3 : Balagurusamy Programming ANSI in C
Chapter 3 : Balagurusamy Programming ANSI in C Chapter 3 : Balagurusamy Programming ANSI in C
Chapter 3 : Balagurusamy Programming ANSI in C BUBT
 
Constructor and destructor
Constructor  and  destructor Constructor  and  destructor
Constructor and destructor Shubham Vishwambhar
 
C fundamental
C fundamentalC fundamental
C fundamentalSelvam Edwin
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and StringTasnima Hamid
 
Input and Output In C Language
Input and Output In C LanguageInput and Output In C Language
Input and Output In C LanguageAdnan Khan
 
Date and Time Module in Python | Edureka
Date and Time Module in Python | EdurekaDate and Time Module in Python | Edureka
Date and Time Module in Python | EdurekaEdureka!
 
C language
C languageC language
C languagemarar hina
 

What's hot (20)

C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming Course
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
C decision making and looping.
C decision making and looping.C decision making and looping.
C decision making and looping.
 
Bruteforce algorithm
Bruteforce algorithmBruteforce algorithm
Bruteforce algorithm
 
SMIU Lecture #1 & 2 Introduction to Discrete Structure and Truth Table.pdf
SMIU Lecture #1 & 2 Introduction to Discrete Structure and Truth Table.pdfSMIU Lecture #1 & 2 Introduction to Discrete Structure and Truth Table.pdf
SMIU Lecture #1 & 2 Introduction to Discrete Structure and Truth Table.pdf
 
Analysis and Design of Algorithms
Analysis and Design of AlgorithmsAnalysis and Design of Algorithms
Analysis and Design of Algorithms
 
Function in C Programming
Function in C ProgrammingFunction in C Programming
Function in C Programming
 
Backtracking & branch and bound
Backtracking & branch and boundBacktracking & branch and bound
Backtracking & branch and bound
 
Introduction to Basic C programming 01
Introduction to Basic C programming 01Introduction to Basic C programming 01
Introduction to Basic C programming 01
 
Python Unit 3 - Control Flow and Functions
Python Unit 3 - Control Flow and FunctionsPython Unit 3 - Control Flow and Functions
Python Unit 3 - Control Flow and Functions
 
Introduction to c++ ppt 1
Introduction to c++ ppt 1Introduction to c++ ppt 1
Introduction to c++ ppt 1
 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structure
 
Chapter 3 : Balagurusamy Programming ANSI in C
Chapter 3 : Balagurusamy Programming ANSI in C Chapter 3 : Balagurusamy Programming ANSI in C
Chapter 3 : Balagurusamy Programming ANSI in C
 
Constructor and destructor
Constructor  and  destructor Constructor  and  destructor
Constructor and destructor
 
C fundamental
C fundamentalC fundamental
C fundamental
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
 
Input and Output In C Language
Input and Output In C LanguageInput and Output In C Language
Input and Output In C Language
 
Date and Time Module in Python | Edureka
Date and Time Module in Python | EdurekaDate and Time Module in Python | Edureka
Date and Time Module in Python | Edureka
 
Chap 6(decision making-looping)
Chap 6(decision making-looping)Chap 6(decision making-looping)
Chap 6(decision making-looping)
 
C language
C languageC language
C language
 

Similar to C programming 28 program

cbse 12 computer science investigatory project
cbse 12 computer science investigatory project  cbse 12 computer science investigatory project
cbse 12 computer science investigatory project D. j Vicky
 
cbse 12 computer science investigatory project
cbse 12 computer science investigatory project  cbse 12 computer science investigatory project
cbse 12 computer science investigatory project D. j Vicky
 
cbse 12 computer science IP
cbse 12 computer science IPcbse 12 computer science IP
cbse 12 computer science IPD. j Vicky
 
Cs291 assignment solution
Cs291 assignment solutionCs291 assignment solution
Cs291 assignment solutionKuntal Bhowmick
 
Unit-IV.pptx
Unit-IV.pptxUnit-IV.pptx
Unit-IV.pptxMehul Desai
 
Building Simple C Program
Building Simple  C ProgramBuilding Simple  C Program
Building Simple C ProgramJeraldPastorCejas
 
Data structures and algorithms unit i
Data structures and algorithms unit iData structures and algorithms unit i
Data structures and algorithms unit isonalisraisoni
 
C programs Set 2
C programs Set 2C programs Set 2
C programs Set 2Koshy Geoji
 
Best C Programming Solution
Best C Programming SolutionBest C Programming Solution
Best C Programming Solutionyogini sharma
 
Programming fundamentals
Programming fundamentalsProgramming fundamentals
Programming fundamentalsZaibi Gondal
 
'C' language notes (a.p)
'C' language notes (a.p)'C' language notes (a.p)
'C' language notes (a.p)Ashishchinu
 

Similar to C programming 28 program (20)

C lab
C labC lab
C lab
 
C-programs
C-programsC-programs
C-programs
 
C Programming
C ProgrammingC Programming
C Programming
 
Arithmetic operator
Arithmetic operatorArithmetic operator
Arithmetic operator
 
cbse 12 computer science investigatory project
cbse 12 computer science investigatory project  cbse 12 computer science investigatory project
cbse 12 computer science investigatory project
 
cbse 12 computer science investigatory project
cbse 12 computer science investigatory project  cbse 12 computer science investigatory project
cbse 12 computer science investigatory project
 
cbse 12 computer science IP
cbse 12 computer science IPcbse 12 computer science IP
cbse 12 computer science IP
 
comp2
comp2comp2
comp2
 
Cs291 assignment solution
Cs291 assignment solutionCs291 assignment solution
Cs291 assignment solution
 
c programing
c programingc programing
c programing
 
Unit-IV.pptx
Unit-IV.pptxUnit-IV.pptx
Unit-IV.pptx
 
Hargun
HargunHargun
Hargun
 
Building Simple C Program
Building Simple  C ProgramBuilding Simple  C Program
Building Simple C Program
 
Data structures and algorithms unit i
Data structures and algorithms unit iData structures and algorithms unit i
Data structures and algorithms unit i
 
C programs
C programsC programs
C programs
 
C programs Set 2
C programs Set 2C programs Set 2
C programs Set 2
 
Best C Programming Solution
Best C Programming SolutionBest C Programming Solution
Best C Programming Solution
 
Programming fundamentals
Programming fundamentalsProgramming fundamentals
Programming fundamentals
 
'C' language notes (a.p)
'C' language notes (a.p)'C' language notes (a.p)
'C' language notes (a.p)
 
First c program
First c programFirst c program
First c program
 

More from F Courses

Transpose of a Matrix With Example | Class_13 | Matrix Basic
Transpose of a Matrix With Example | Class_13 | Matrix BasicTranspose of a Matrix With Example | Class_13 | Matrix Basic
Transpose of a Matrix With Example | Class_13 | Matrix BasicF Courses
 
Financial performance evaluation and home loan policy
Financial performance evaluation and home loan policy Financial performance evaluation and home loan policy
Financial performance evaluation and home loan policy F Courses
 
Physics Basic
Physics BasicPhysics Basic
Physics BasicF Courses
 
Chemistry in computer science & engineering.
Chemistry in computer science & engineering.Chemistry in computer science & engineering.
Chemistry in computer science & engineering.F Courses
 
Flame test theory explained
Flame test theory explainedFlame test theory explained
Flame test theory explainedF Courses
 
Chemistry laboratory safety
Chemistry laboratory safetyChemistry laboratory safety
Chemistry laboratory safetyF Courses
 
Chemistry laboratory apparatus
Chemistry laboratory apparatusChemistry laboratory apparatus
Chemistry laboratory apparatusF Courses
 
Global warming
Global warmingGlobal warming
Global warmingF Courses
 

More from F Courses (8)

Transpose of a Matrix With Example | Class_13 | Matrix Basic
Transpose of a Matrix With Example | Class_13 | Matrix BasicTranspose of a Matrix With Example | Class_13 | Matrix Basic
Transpose of a Matrix With Example | Class_13 | Matrix Basic
 
Financial performance evaluation and home loan policy
Financial performance evaluation and home loan policy Financial performance evaluation and home loan policy
Financial performance evaluation and home loan policy
 
Physics Basic
Physics BasicPhysics Basic
Physics Basic
 
Chemistry in computer science & engineering.
Chemistry in computer science & engineering.Chemistry in computer science & engineering.
Chemistry in computer science & engineering.
 
Flame test theory explained
Flame test theory explainedFlame test theory explained
Flame test theory explained
 
Chemistry laboratory safety
Chemistry laboratory safetyChemistry laboratory safety
Chemistry laboratory safety
 
Chemistry laboratory apparatus
Chemistry laboratory apparatusChemistry laboratory apparatus
Chemistry laboratory apparatus
 
Global warming
Global warmingGlobal warming
Global warming
 

Recently uploaded

Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 

Recently uploaded (20)

Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 

C programming 28 program

  • 1. https://www.facebook.com/fcoursesbd Page 1 of 31 C Programming 28 Program Table of Contents Page no 1) C Program to Check Whether a Number is Even or Odd...................................................................................................12 2) C Program to Check Whether a Character is Vowel or Consonant ........................................................................................22 3) C Program to Find the Largest Number Among Three Numbers .......................................................................................33 4) C Program to Check Leap Year ....................................................................................................................................................45 5) C Program to Check Whether a Number is Positive or Negative ...........................................................................................55 6) C Program to Check Whether a Character is an Alphabet or not ......................................................................................66 7 ) C Program to Generate Multiplication Table ....................................................................................................................77 8 ) C Program to Display Fibonacci Sequence .........................................................................................................................88 9 ) C Program to Find GCD of two Numbers............................................................................................................................99 10 ) C Program to Find LCM (Lowest Common Multiple) of two Number ...........................................................................101 11) C Program to Display Characters from A to Z Using Loop ..............................................................................................111 12) C Program to Reverse a Number.....................................................................................................................................122 13 ) C Program to Calculate the Power of a Number............................................................................................................133 14) C Program to Check Whether a Number is Palindrome or Not......................................................................................144 15) C Program to Check Whether a Number is Prime or Not...............................................................................................155 16) C Program to Display Prime Numbers Between Two Intervals......................................................................................166 17 ) C Program to Check Armstrong Number........................................................................................................................177 18) C Program to Display Factors of a Number.....................................................................................................................188 19) C Programming Code To Create Pyramid and Pattern ...................................................................................................199 20) C Program to Make a Simple Calculator Using switch...case .........................................................................................200 21) C Programming Code To Create Pyramid and Pattern ...................................................................................................211 22) C Program to Display Prime Numbers Between Intervals Using Function ....................................................................222 23) C Program to Check Prime or Armstrong Number Using User-defined Function..........................................................233 24) C Program to Find the Sum of Natural Numbers using Recursion .................................................................................255 25) C Program to Find Factorial of a Number Using Recursion ...........................................................................................266 26) C Program to Find G.C.D Using Recursion.......................................................................................................................277 27) C program to Reverse a Sentence Using Recursion........................................................................................................288 28) C program to calculate the power using recursion.........................................................................................................299
  • 2. https://www.facebook.com/fcoursesbd Page 2 of 31 1) C Program to Check Whether a Number is Even or Odd #include <stdio.h> int main() { int number; printf("Enter an integer: "); scanf("%d", &number); if(number % 2 == 0) printf("%d is even.", number); else printf("%d is odd.", number); return 0; } Output
  • 3. https://www.facebook.com/fcoursesbd Page 3 of 31 2) C Program to Check Whether a Character is Vowel or Consonant #include <stdio.h> int main() { char c; int isLowercaseVowel, isUppercaseVowel; printf("Enter an alphabet: "); scanf("%c",&c); isLowercaseVowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'); isUppercaseVowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U'); if (isLowercaseVowel || isUppercaseVowel) printf("%c is a vowel.", c); else printf("%c is a consonant.", c); return 0; } Output
  • 4. https://www.facebook.com/fcoursesbd Page 4 of 31 3) C Program to Find the Largest Number Among Three Numbers #include <stdio.h> int main() { double n1, n2, n3; printf("Enter three numbers: "); scanf("%lf %lf %lf", &n1, &n2, &n3); if( n1>=n2 && n1>=n3) printf("%.2lf is the largest number.", n1); else if (n2>=n1 && n2>=n3) printf("%.2lf is the largest number.", n2); else printf("%.2lf is the largest number.", n3); return 0; } Output
  • 5. https://www.facebook.com/fcoursesbd Page 5 of 31 4) C Program to Check Leap Year #include <stdio.h> int main() { int year; printf("Enter year : "); scanf("%d", &year); if(((year % 4 == 0) && (year % 100 !=0)) || (year % 400==0)) { printf("LEAP YEAR"); } else { printf("COMMON YEAR"); } return 0; } Output
  • 6. https://www.facebook.com/fcoursesbd Page 6 of 31 5) C Program to Check Whether a Number is Positive or Negative #include <stdio.h> int main() { double number; printf("Enter a number: "); scanf("%lf", &number); if (number < 0.0) printf("You entered a negative number."); else if ( number > 0.0) printf("You entered a positive number."); else printf("You entered 0."); return 0; } Output
  • 7. https://www.facebook.com/fcoursesbd Page 7 of 31 6) C Program to Check Whether a Character is an Alphabet or not #include <stdio.h> int main() { char c; printf("Enter a character: "); scanf("%c",&c); if( (c>='a' && c<='z') || (c>='A' && c<='Z')) printf("%c is an alphabet.",c); else printf("%c is not an alphabet.",c); return 0; } Output
  • 8. https://www.facebook.com/fcoursesbd Page 8 of 31 7 ) C Program to Generate Multiplication Table #include <stdio.h> int main() { int n, i; printf("Enter an integer: "); scanf("%d",&n); for(i=1; i<=10; ++i) { printf("%d * %d = %d n", n, i, n*i); } return 0; } Output
  • 9. https://www.facebook.com/fcoursesbd Page 9 of 31 8 ) C Program to Display Fibonacci Sequence #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; }
  • 10. https://www.facebook.com/fcoursesbd Page 10 of 31 9 ) C Program to Find GCD of two Numbers #include <stdio.h> int main() { int n1, n2, i, gcd; printf("Enter two integers: "); scanf("%d %d", &n1, &n2); for(i=1; i <= n1 && i <= n2; ++i) { if(n1%i==0 && n2%i==0) gcd = i; } printf("G.C.D of %d and %d is %d", n1, n2, gcd); return 0; } Output
  • 11. https://www.facebook.com/fcoursesbd Page 11 of 31 10 ) C Program to Find LCM (Lowest Common Multiple) of two Numbers #include <stdio.h> int main() { int n1, n2, i, gcd, lcm; printf("Enter two positive integers: "); scanf("%d %d",&n1,&n2); for(i=1; i <= n1 && i <= n2; ++i) { if(n1%i==0 && n2%i==0) gcd = i; } lcm = (n1*n2)/gcd; printf("The LCM of two numbers %d and %d is %d.", n1, n2, lcm); return 0; } Output
  • 12. https://www.facebook.com/fcoursesbd Page 12 of 31 11) C Program to Display Characters from A to Z Using Loop #include <stdio.h> int main() { char c; for(c = 'A'; c <= 'Z'; ++c) printf("%c ", c); return 0; } Output
  • 13. https://www.facebook.com/fcoursesbd Page 13 of 31 12) C Program to Reverse a Number #include <stdio.h> int main() { int n, reverse = 0; printf("Enter a number to reversen"); scanf("%d", &n); while (n != 0) { reverse = reverse * 10; reverse = reverse + n%10; n = n/10; } printf("Reverse of entered number is = %dn", reverse); return 0; } Output
  • 14. https://www.facebook.com/fcoursesbd Page 14 of 31 13 ) C Program to Calculate the Power of a Number #include <stdio.h> int main() { int base, exponent; long long result = 1; printf("Enter a base number: "); scanf("%d", &base); printf("Enter an exponent: "); scanf("%d", &exponent); while (exponent != 0) { result *= base; --exponent; } printf("Answer = %lld", result); return 0; } Output
  • 15. https://www.facebook.com/fcoursesbd Page 15 of 31 14) C Program to Check Whether a Number is Palindrome or Not #include <stdio.h> int main() { int n, reversedInteger = 0, remainder, originalInteger; printf("Enter an integer: "); scanf("%d", &n); originalInteger = n; while( n!=0 ) { remainder = n%10; reversedInteger = reversedInteger*10 + remainder; n /= 10; } if (originalInteger == reversedInteger) printf("%d is a palindrome.", originalInteger); else printf("%d is not a palindrome.", originalInteger); return 0; } Output
  • 16. https://www.facebook.com/fcoursesbd Page 16 of 31 15) C Program to Check Whether a Number is Prime or Not #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) { if(n%i == 0) { flag = 1; break; } } if (n == 1) { printf("1 is neither a prime nor a composite number."); } else { if (flag == 0) printf("%d is a prime number.", n); else printf("%d is not a prime number.", n); } return 0; } Output
  • 17. https://www.facebook.com/fcoursesbd Page 17 of 31 16) C Program to Display Prime Numbers Between Two Intervals #include <stdio.h> int main() { int low, high, i, flag; printf("Enter two numbers(intervals): "); scanf("%d %d", &low, &high); printf("Prime numbers between %d and %d are: ", low, high); while (low < high) { flag = 0; for(i = 2; i <= low/2; ++i) { if(low % i == 0) { flag = 1; break; } } if (flag == 0) printf("%d ", low); ++low; } return 0; } Output
  • 18. https://www.facebook.com/fcoursesbd Page 18 of 31 17 ) C Program to Check Armstrong Number #include <stdio.h> int main() { int number, originalNumber, remainder, result = 0; printf("Enter a three digit integer: "); scanf("%d", &number); originalNumber = number; while (originalNumber != 0) { remainder = originalNumber%10; result += remainder*remainder*remainder; originalNumber /= 10; } if(result == number) printf("%d is an Armstrong number.",number); else printf("%d is not an Armstrong number.",number); return 0; } Output
  • 19. https://www.facebook.com/fcoursesbd Page 19 of 31 18) C Program to Display Factors of a Number #include <stdio.h> int main() { int number, i; printf("Enter a positive integer: "); scanf("%d",&number); printf("Factors of %d are: ", number); for(i=1; i <= number; ++i) { if (number%i == 0) { printf("%d ",i); } } return 0; } Output
  • 20. https://www.facebook.com/fcoursesbd Page 20 of 31 19) C Programming Code To Create Pyramid and Pattern #include <stdio.h> int main() { int i, j, rows; printf("Enter number of rows: "); scanf("%d",&rows); for(i=1; i<=rows; ++i) { for(j=1; j<=i; ++j) { printf("* "); } printf("n"); } return 0; } Output
  • 21. https://www.facebook.com/fcoursesbd Page 21 of 31 20) C Program to Make a Simple Calculator Using switch...case # include <stdio.h> int main() { char operator; double firstNumber,secondNumber; printf("Enter an operator (+, -, *,): "); scanf("%c", &operator); printf("Enter two operands: "); scanf("%lf %lf",&firstNumber, &secondNumber); switch(operator) { case '+': printf("%.1lf + %.1lf = %.1lf",firstNumber, secondNumber, firstNumber + secondNumber); break; case '-': printf("%.1lf - %.1lf = %.1lf",firstNumber, secondNumber, firstNumber - secondNumber); break; case '*': printf("%.1lf * %.1lf = %.1lf",firstNumber, secondNumber, firstNumber * secondNumber); break; case '/': printf("%.1lf / %.1lf = %.1lf",firstNumber, secondNumber, firstNumber / secondNumber); break; default: printf("Error! operator is not correct"); } return 0; Output }
  • 22. https://www.facebook.com/fcoursesbd Page 22 of 31 21) C Programming Code To Create Pyramid and Pattern #include <stdio.h> int main() { int i, space, rows, k=0; printf("Enter number of rows: "); scanf("%d",&rows); for(i=1; i<=rows; ++i, k=0) { for(space=1; space<=rows-i; ++space) { printf(" "); } while(k != 2*i-1) { printf("* "); ++k; } printf("n"); } return 0; } Output
  • 23. https://www.facebook.com/fcoursesbd Page 23 of 31 22) C Program to Display Prime Numbers Between Intervals Using Function #include <stdio.h> int checkPrimeNumber(int n); int main() { int n1, n2, i, flag; printf("Enter two positive integers: "); scanf("%d %d", &n1, &n2); printf("Prime numbers between %d and %d are: ", n1, n2); for(i=n1+1; i<n2; ++i) { flag = checkPrimeNumber(i); if(flag == 1) printf("%d ",i); } return 0; } int checkPrimeNumber(int n) { int j, flag = 1; for(j=2; j <= n/2; ++j) { if (n%j == 0) { flag =0; break; } } Output return flag; }
  • 24. https://www.facebook.com/fcoursesbd Page 24 of 31 23) C Program to Check Prime or Armstrong Number Using User-defined Function #include <stdio.h> #include <math.h> int checkPrimeNumber(int n); int checkArmstrongNumber(int n); int main() { int n, flag; printf("Enter a positive integer: "); scanf("%d", &n); flag = checkPrimeNumber(n); if (flag == 1) printf("%d is a prime number.n", n); else printf("%d is not a prime number.n", n); flag = checkArmstrongNumber(n); if (flag == 1) printf("%d is an Armstrong number.", n); else printf("%d is not an Armstrong number.",n); return 0; } int checkPrimeNumber(int n) { int i, flag = 1; for(i=2; i<=n/2; ++i) { if(n%i == 0) { flag = 0; break;
  • 25. https://www.facebook.com/fcoursesbd Page 25 of 31 } } return flag; } int checkArmstrongNumber(int number) { int originalNumber, remainder, result = 0, n = 0, flag; originalNumber = number; while (originalNumber != 0) { originalNumber /= 10; ++n; } originalNumber = number; while (originalNumber != 0) { remainder = originalNumber%10; result += pow(remainder, n); originalNumber /= 10; } if(result == number) flag = 1; else flag = 0; return flag; } Output
  • 26. https://www.facebook.com/fcoursesbd Page 26 of 31 24) C Program to Find the Sum of Natural Numbers using Recursion #include <stdio.h> int addNumbers(int n); int main() { int num; printf("Enter a positive integer: "); scanf("%d", &num); printf("Sum = %d",addNumbers(num)); return 0; } int addNumbers(int n) { if(n != 0) return n + addNumbers(n-1); else return n; } Output
  • 27. https://www.facebook.com/fcoursesbd Page 27 of 31 25) C Program to Find Factorial of a Number Using Recursion #include <stdio.h> long int multiplyNumbers(int n); int main() { int n; printf("Enter a positive integer: "); scanf("%d", &n); printf("Factorial of %d = %ld", n, multiplyNumbers(n)); return 0; } long int multiplyNumbers(int n) { if (n >= 1) return n*multiplyNumbers(n-1); else return 1; } Output
  • 28. https://www.facebook.com/fcoursesbd Page 28 of 31 26) C Program to Find G.C.D Using Recursion #include <stdio.h> int hcf(int n1, int n2); int main() { int n1, n2; printf("Enter two positive integers: "); scanf("%d %d", &n1, &n2); printf("G.C.D of %d and %d is %d.", n1, n2, hcf(n1,n2)); return 0; } int hcf(int n1, int n2) { if (n2 != 0) return hcf(n2, n1%n2); else return n1; } Output
  • 29. https://www.facebook.com/fcoursesbd Page 29 of 31 27) C program to Reverse a Sentence Using Recursion #include <stdio.h> void reverseSentence(); int main() { printf("Enter a sentence: "); reverseSentence(); return 0; } void reverseSentence() { char c; scanf("%c", &c); if( c != 'n') { reverseSentence(); printf("%c",c); } } Output
  • 30. https://www.facebook.com/fcoursesbd Page 30 of 31 28) C program to calculate the power using recursion #include <stdio.h> int power(int n1, int n2); int main() { int base, powerRaised, result; printf("Enter base number: "); scanf("%d",&base); printf("Enter power number(positive integer): "); scanf("%d",&powerRaised); result = power(base, powerRaised); printf("%d^%d = %d", base, powerRaised, result); return 0; } int power(int base, int powerRaised) { if (powerRaised != 0) return (base*power(base, powerRaised-1)); else return 1; } Output