C++
program to check entered character is small, capital, digit or a special
character
#include
#include
using namespace std;
int main()
{
char character;
cout<<"Enter a character = ";
cin>>character;
int storeAscii=character;
cout<<"The Ascii value of "<
" is "<
if (storeAscii>=65 && storeAscii<=90)
{
cout<<"\nYou have entered a capital letter";
}
else if (storeAscii>=97 && storeAscii<=122)
{
cout<<"\nYou have entered a small letter";
}
else if (storeAscii>=47 && storeAscii<=57)
{
cout<<"\nYou have entered a digit ";
}
else if (storeAscii>=0 && storeAscii>=47
|| storeAscii>=54 && storeAscii<=64
|| storeAscii>=91 && storeAscii<=96
|| storeAscii>=123 && storeAscii<=127)
{
cout<<"\nYou have entered a special character";
}
return 0;
}
Switch
statement in c++ to calculate grade points when user enter a grade
#include
#include
using namespace std;
int main()
{
char grade; double gpa=0.0;
cout<<"Enter
your Grade= ";
cin>>grade;
switch(grade)
{
case'A':
case'a':
gpa=4.0;
cout<<"your gpa is "<
break;
case'B':
case'b':
gpa=3.0;
cout<<"your gpa is "<
break;
case'C':
case'c':
gpa=2.0;
cout<<"your gpa is "<
break;
case'D':
case'd':
gpa=1.0;
cout<<"your gpa is "<
break;
case'F':
case'f':
gpa=0.0;
cout<<"your gpa is "<
break;
default:
cout<<"invalid grade
entered";
break;
}
return 0;
}
Recursive
function in C++ linear search
#include
#include
using namespace std;
int recursiveLinearSearch(int array[],int key,int size)
{
size=size-1;
if(size <0 span="">0>
{
return -1;
}
else if(array[size]==key)
{
return 1;
}
else
{
return recursiveLinearSearch(array,key,size);
}
}
int main()
{
cout<<"Enter The Size Of Array: ";
int size;
cin>>size;
int array[size], key,i;
for(int j=0;j
{
cout<<"Enter "<
cin>>array[j];
}
for(int a=0;a
{
cout<<"array[ "<
cout<
}
cout<<"Enter key to search in array";
cin>>key;
int result;
result=recursiveLinearSearch(array,key,size--);
if(result==1)
{
cout<<"Key found in Array ";
}
else
{
cout<<"Key not Found in Array ";
}
return 0;
}
C++
program to find perfect number
#include
#include
void main()
{
clrscr();
int i=1, u=1, sum=0;
while(i<=500)
{
while(u<=500)
{
if(u
{
if(i%u==0 )
sum=sum+u;
}
u++;
}
if(sum==i)
{
cout<
}
i++;
u=1; sum=0;
}
getch();
}
No comments:
Post a Comment