Request - Project details.docx
    19.7 KB
  Project Requirement Details for Final year Project Demo document for your information
  C program to check odd or even using modulus operator
#include<stdio.h>
 
main()
{
int n;
 
printf("Enter an integer\n");
scanf("%d",&n);
 
if ( n%2 == 0 )
printf("Even\n");
else
printf("Odd\n");
 
return 0;
}
  #include<stdio.h>
main()
{
int n;
printf("Enter an integer\n");
scanf("%d",&n);
if ( n%2 == 0 )
printf("Even\n");
else
printf("Odd\n");
return 0;
}
C program to check odd or even using bitwise operator
#include<stdio.h>
 
main()
{
int n;
 
printf("Enter an integer\n");
scanf("%d",&n);
 
if ( n & 1 == 1 )
printf("Odd\n");
else
printf("Even\n");
 
return 0;
}
  #include<stdio.h>
main()
{
int n;
printf("Enter an integer\n");
scanf("%d",&n);
if ( n & 1 == 1 )
printf("Odd\n");
else
printf("Even\n");
return 0;
}
C program to check odd or even without using bitwise or modulus operator
#include<stdio.h>
 
main()
{
int n;
 
printf("Enter an integer\n");
scanf("%d",&n);
 
if ( (n/2)*2 == n )
printf("Even\n");
else
printf("Odd\n");
 
return 0;
}
  #include<stdio.h>
main()
{
int n;
printf("Enter an integer\n");
scanf("%d",&n);
if ( (n/2)*2 == n )
printf("Even\n");
else
printf("Odd\n");
return 0;
}
Find odd or even using conditional operator
#include<stdio.h>
 
main()
{
int n;
 
printf("Enter an integer\n");
scanf("%d",&n);
 
n%2 == 0 ? printf("Even number\n") : printf("Odd number\n");
 
return 0;
}
  #include<stdio.h>
main()
{
int n;
printf("Enter an integer\n");
scanf("%d",&n);
n%2 == 0 ? printf("Even number\n") : printf("Odd number\n");
return 0;
}
c program to check whether input alphabet is a vowel or not 
This code checks whether an input alphabet is a vowel or not. Both lower-case and upper-case are checked.
C programming code
#include <stdio.h>
 
main()
{
char ch;
 
printf("Enter a character\n");
scanf("%c", &ch);
 
if (ch == 'a' ch == 'A'   ch == 'e'  ch == 'E'   ch == 'i'  ch == 'I'   ch =='o'  ch=='O'   ch == 'u' || ch == 'U')
printf("%c is a vowel.\n", ch);
else
printf("%c is not a vowel.\n", ch);
 
return 0;
}
Output:
 
a
a is vowel
  This code checks whether an input alphabet is a vowel or not. Both lower-case and upper-case are checked.
C programming code
#include <stdio.h>
main()
{
char ch;
printf("Enter a character\n");
scanf("%c", &ch);
if (ch == 'a'
printf("%c is a vowel.\n", ch);
else
printf("%c is not a vowel.\n", ch);
return 0;
}
Output:
a
a is vowel
Check vowel using switch statement
#include <stdio.h>
 
main()
{
char ch;
 
printf("Enter a character\n");
scanf("%c", &ch);
 
switch(ch)
{
case 'a':
case 'A':
case 'e':
case 'E':
case 'i':
case 'I':
case 'o':
case 'O':
case 'u':
case 'U':
printf("%c is a vowel.\n", ch);
break;
default:
printf("%c is not a vowel.\n", ch);
}
 
return 0;
}
  #include <stdio.h>
main()
{
char ch;
printf("Enter a character\n");
scanf("%c", &ch);
switch(ch)
{
case 'a':
case 'A':
case 'e':
case 'E':
case 'i':
case 'I':
case 'o':
case 'O':
case 'u':
case 'U':
printf("%c is a vowel.\n", ch);
break;
default:
printf("%c is not a vowel.\n", ch);
}
return 0;
}
Function to check vowel
int check_vowel(char a)
{
if (a >= 'A' && a <= 'Z')
a = a + 'a' - 'A'; /* Converting to lower case or use a = a + 32 */
 
if (a == 'a' a == 'e'   a == 'i'  a == 'o'   a == 'u')
return 1;
 
return 0;
}
  int check_vowel(char a)
{
if (a >= 'A' && a <= 'Z')
a = a + 'a' - 'A'; /* Converting to lower case or use a = a + 32 */
if (a == 'a'
return 1;
return 0;
}
c program to check leap year 
c program to check leap year: c code to check leap year, year will be entered by the user. Please read the leap year article before reading the code, it will help you to understand the program.
C programming code
#include <stdio.h>
 
int main()
{
int year;
 
printf("Enter a year to check if it is a leap year\n");
scanf("%d", &year);
 
if ( year%400 == 0)
printf("%d is a leap year.\n", year);
else if ( year%100 == 0)
printf("%d is not a leap year.\n", year);
else if ( year%4 == 0 )
printf("%d is a leap year.\n", year);
else
printf("%d is not a leap year.\n", year);
 
return 0;
}
  c program to check leap year: c code to check leap year, year will be entered by the user. Please read the leap year article before reading the code, it will help you to understand the program.
C programming code
#include <stdio.h>
int main()
{
int year;
printf("Enter a year to check if it is a leap year\n");
scanf("%d", &year);
if ( year%400 == 0)
printf("%d is a leap year.\n", year);
else if ( year%100 == 0)
printf("%d is not a leap year.\n", year);
else if ( year%4 == 0 )
printf("%d is a leap year.\n", year);
else
printf("%d is not a leap year.\n", year);
return 0;
}
add digits of number in c 
C program to add digits of a number: Here we are using modulus operator(%) to extract individual digits of number and adding them.
C programming code
#include <stdio.h>
 
main()
{
int n, sum = 0, remainder;
 
printf("Enter an integer\n");
scanf("%d",&n);
 
while(n != 0)
{
remainder = n % 10;
sum = sum + remainder;
n = n / 10;
}
 
printf("Sum of digits of entered number = %d\n",sum);
 
return 0;
}
  C program to add digits of a number: Here we are using modulus operator(%) to extract individual digits of number and adding them.
C programming code
#include <stdio.h>
main()
{
int n, sum = 0, remainder;
printf("Enter an integer\n");
scanf("%d",&n);
while(n != 0)
{
remainder = n % 10;
sum = sum + remainder;
n = n / 10;
}
printf("Sum of digits of entered number = %d\n",sum);
return 0;
}
Add digits using recursion
#include <stdio.h>
 
int add_digits(int);
 
int main() {
int n, result;
 
scanf("%d", &n);
 
result = add_digits(n);
 
printf("%d\n", result);
 
return 0;
}
 
int add_digits(int n) {
static int sum = 0;
 
if (n == 0) {
return 0;
}
 
sum = n%10 + add_digits(n/10);
 
return sum;
}
  #include <stdio.h>
int add_digits(int);
int main() {
int n, result;
scanf("%d", &n);
result = add_digits(n);
printf("%d\n", result);
return 0;
}
int add_digits(int n) {
static int sum = 0;
if (n == 0) {
return 0;
}
sum = n%10 + add_digits(n/10);
return sum;
}
Factorial program in c using for loop
: Here we find factorial using for loop.
#include <stdio.h>
 
int main()
{
int c, n, fact = 1;
 
printf("Enter a number to calculate it's factorial\n");
scanf("%d", &n);
 
for (c = 1; c <= n; c++)
fact = fact * c;
 
printf("Factorial of %d = %d\n", n, fact);
 
return 0;
}
  : Here we find factorial using for loop.
#include <stdio.h>
int main()
{
int c, n, fact = 1;
printf("Enter a number to calculate it's factorial\n");
scanf("%d", &n);
for (c = 1; c <= n; c++)
fact = fact * c;
printf("Factorial of %d = %d\n", n, fact);
return 0;
}
Factorial program in c using function
#include <stdio.h>
 
long factorial(int);
 
int main()
{
int number;
long fact = 1;
 
printf("Enter a number to calculate it's factorial\n");
scanf("%d", &number);
 
printf("%d! = %ld\n", number, factorial(number));
 
return 0;
}
 
long factorial(int n)
{
int c;
long result = 1;
 
for (c = 1; c <= n; c++)
result = result * c;
 
return result;
}
  #include <stdio.h>
long factorial(int);
int main()
{
int number;
long fact = 1;
printf("Enter a number to calculate it's factorial\n");
scanf("%d", &number);
printf("%d! = %ld\n", number, factorial(number));
return 0;
}
long factorial(int n)
{
int c;
long result = 1;
for (c = 1; c <= n; c++)
result = result * c;
return result;
}
Factorial program in c using recursion
#include<stdio.h>
 
long factorial(int);
 
int main()
{
int num;
long f;
 
printf("Enter a number to find factorial\n");
scanf("%d", &num);
 
if (num < 0)
printf("Negative numbers are not allowed.\n");
else
{
f = factorial(num);
printf("%d! = %ld\n", num, f);
}
 
return 0;
}
 
long factorial(int n)
{
if (n == 0)
return 1;
else
return(n * factorial(n-1));
}
  #include<stdio.h>
long factorial(int);
int main()
{
int num;
long f;
printf("Enter a number to find factorial\n");
scanf("%d", &num);
if (num < 0)
printf("Negative numbers are not allowed.\n");
else
{
f = factorial(num);
printf("%d! = %ld\n", num, f);
}
return 0;
}
long factorial(int n)
{
if (n == 0)
return 1;
else
return(n * factorial(n-1));
}
