C++ Program to display the ASCII value of given character [DEVCPP/GCC]
ASCII CODE
ASCII stands for American Standard Code for Information Interchange. Computers can only understand binary numbers, so an ASCII code is the numerical representation of a character.
//Program to display the ASCII value of given character
#include <iostream>
using namespace std;
int main()
{
int num;
char ch;
cout<<"ENTER CHARACTER: ";
cin>>ch;
num = (int) ch; //Type Casting
cout<<"ASCII VALUE OF "<<ch<<" IS "<<num;
return 0;
}
ASCII stands for American Standard Code for Information Interchange. Computers can only understand binary numbers, so an ASCII code is the numerical representation of a character.
//Program to display the ASCII value of given character
#include <iostream>
using namespace std;
int main()
{
int num;
char ch;
cout<<"ENTER CHARACTER: ";
cin>>ch;
num = (int) ch; //Type Casting
cout<<"ASCII VALUE OF "<<ch<<" IS "<<num;
return 0;
}
C++ Program to find the maximum of three numbers [DEVCPP/GCC]
//Program to find maximum among three numbers
#include <iostream>
using namespace std;
int main()
{
float a,b,c,max;
cout<<"ENTER FIRST NUMBER: ";
cin>>a;
cout<<"ENTER SECOND NUMBER: ";
cin>>b;
cout<<"ENTER THIRD NUMBER: ";
cin>>c;
if(a>b) //Comparing first two numbers (a & b)
max=a;
else
max=b;
if(c>max) //Comparing the max of above two numbers from the third number
max=c;
cout<<"\nMAXIMUM AMONG "<<a<<","<<b<<","<<c<<" IS:"<<max;
return 0;
}
C++ Program to find maximum among two numbers [DEVCPP/GCC]
//Program to find maximum among two numbers
#include <iostream>
using namespace std;
int main()
{
float a,b,max;
cout<<"ENTER FIRST NUMBER: ";
cin>>a;
cout<<"ENTER SECOND NUMBER: ";
cin>>b;
max = (a>b) ? a : b ;
// Variable = <condition> ? <True> : <False>
cout<<"\nMAXIMUM AMONG "<<a<<" & "<<b<<" IS "<<max;
return 0;
}
C++ Program to find the number of trailing zeros in the factorial of a number [DEVCPP/GCC]
We intend to find the number of trailing zeros in the factorial of a number.
For example 1. If entered number (num) is 5, the factorial of 5 is :120, then
Output:1 (as there is only one zero at end in 120)
example 2. If entered number (num) is 10 ,the factorial of 10 is:3628800
Output:2
//Program to find the number of trailing zeros in the factorial of a number
#include <iostream>
using namespace std;
int main()
{
int count=0,num; //count initialized by 0
cout<<"ENTER THE NUMBER:\n";
cin>>num;
cout<<"\nFINDING THE NUMBER OF TRAILING ZEROS IN THE FACTORIAL OF THIS NUMBER...\n\n";
for(int i=5 ; (num/i)>=1 ; i*=5)
{
count + = num/i; //loop counts the number of trailing zeros
}
cout<<"THE NUMBER OF TRAILING ZEROS IN THE FACTORIAL OF "<<num<<" IS:"<<count<<"\n";
}
C++ Program to check whether given character is vowel or consonant [DEVCPP/GCC]
PROGRAM
//Program to check whether given character is vowel or consonant
#include <iostream>
using namespace std;
int main()
{
char ch;
cout<<"ENTER CHARACTER : ";
cin>>ch;
// Checking for Upper Case Vowel
if(ch>=65 && ch<=90)
{
if(ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U')
{
cout<<ch<<" IS A VOWEL";
}
else
{
cout<<ch<<" IS A CONSONANT";
}
}
// Checking for Lower Case Vowel
else if(ch>=97 && ch<=122)
{
if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u' )
{
cout<<ch<<" IS A VOWEL";
}
else
{
cout<<ch<<" IS A CONSONANT";
}
}
else
{
cout<<"\nPLEASE ENTER A CHARACTER! ";
}
return 0;
}
OUTPUT
//Program to check whether given character is vowel or consonant
#include <iostream>
using namespace std;
int main()
{
char ch;
cout<<"ENTER CHARACTER : ";
cin>>ch;
// Checking for Upper Case Vowel
if(ch>=65 && ch<=90)
{
if(ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U')
{
cout<<ch<<" IS A VOWEL";
}
else
{
cout<<ch<<" IS A CONSONANT";
}
}
// Checking for Lower Case Vowel
else if(ch>=97 && ch<=122)
{
if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u' )
{
cout<<ch<<" IS A VOWEL";
}
else
{
cout<<ch<<" IS A CONSONANT";
}
}
else
{
cout<<"\nPLEASE ENTER A CHARACTER! ";
}
return 0;
}
C++ Program to check whether given year is leap year or not [DEVCPP/GCC]
In the Gregorian calendar(internationally accepted calendar),the following criteria must be taken into consideration to identify leap years:
1. Year must be completely divisible by 4;
2. If the year is divisible by 100, then it must be divisible by 400
This means that in the Gregorian calendar, the years 2000 and 2400 are leap years, while 1800, 1900, 2100, 2200, 2300 and 2500 are NOT leap years.
//Program to check whether given year is leap year or not
#include <iostream>
using namespace std;
int main()
{
int year,flag=1;
cout << "ENTER YEAR: ";
cin >> year;
if (year % 4 == 0)
{
flag=0;
if((year % 100 == 0) && (year % 400 != 0))
{
flag=1; //flag=1 represents the second condition as false
}
}
/*If flag remains 0 after execution of above block, that implies both the conditions are satisfied */
if(flag==0) // If both conditions are true
{
cout <<year << " IS A LEAP YEAR" << endl;
}
else // if either of condition is false
{
cout <<year << " IS NOT A LEAP YEAR" << endl;
}
}
C++ Program to calculate circumference of a circle [DEVCPP/GCC]
//Program to calculate circumference of a circle
#include <iostream>
#define pi 3.14
/* pi is a macro with value 3.14 i.e. The compiler replaces all the occurrences of pi with 3.14 */
using namespace std;
int main()
{
float r,area;
cout<<"ENTER RADIUS: ";
cin>>r;
area= 2*pi*r;
cout<<"CIRCUMFERENCE OF CIRCLE WITH RADIUS "<<r<<" IS "<<area;
return 0;
}
C++ Program to swap two numbers using temporary variable [DEVCPP/GCC]
//Program to swap two numbers using temporary variable
#include<iostream>
using namespace std;
int main()
{
int a,b,temp;
cout<<"ENTER THE VALUE OF a:";
cin>>a;
cout<<"ENTER THE VALUE OF b:";
cin>>b;
cout<<"BEFORE SWAPPING:"<<endl<<"a="<<a<<" "<<"b="<<b<<endl;
temp=a;
a=b;
b=temp;
cout<<"AFTER SWAPPING:"<<endl<<"a="<<a<<" "<<"b="<<b<<endl;
return 0;
}
C++ Program to swap two numbers without using 3rd variable [DEVCPP/GCC]
//Program to swap two numbers without using 3rd variable
#include<iostream>
using namespace std;
int main()
{
int a,b;
cout<<"ENTER THE VALUE OF A:";
cin>>a;
cout<<"ENTER THE VALUE OF B:";
cin>>b;
cout<<"BEFORE SWAPPING:"<<endl<<"A="<<a<<" "<<"B="<<b<<endl;
a=a+b;
b=a-b;
a=a-b;
cout<<"AFTER SWAPPING:"<<endl<<"A="<<a<<" "<<"B="<<b<<endl;
return 0;
}
Introduction
“Programmers never die; They just get lost in programming”
Techcpp is a blog which contains various programs in C++
programming language. All the programs are compiled and executed in DEVC++ with
GCC compiler.
“Out with the old, In with the new”
Subscribe to:
Posts
(
Atom
)