Facebook Twitter Google RSS
Showing posts with label Tutorial. Show all posts
Showing posts with label Tutorial. Show all posts

Friday, 11 December 2015

Find Odd or Even Using Conditional Operator in C and C++

Tapan     20:27  2 comments
// WE USE THIS CODE IN C // 
  
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a;

printf("Enter Any no.");
scanf("%d",&a);

(a%2==0)?printf("Even No."):printf("Odd No.");

getch();
}

  
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a;

cout<<"Enter Any no.";
cin>>a;

(a%2==0)?cout<<"Even No.":cout<<"Odd No.";

getch();
}

Find Odd or Even Using Conditional Operator in C and C++

Thursday, 3 December 2015

C++ Program to Check a Character is Uppercase, Lowercase, Digit or Special Character

Tapan     04:54  No comments
#include<iostream.h>
#include<conio.h>

void main()

{      
char ch; clrscr();    
cout<<"Enter any character: ";
cin>>ch;

if(ch>=65&&ch<=90)    
{
cout<<endl<<"You entered an uppercase character";
}

else if(ch>=48&&ch<=57)

{
cout<<endl<<"You entered a digit";
} 

else if(ch>=97&&ch<=122)

{
cout<<endl<<"You entered a lowercase character";
}

else

cout<<endl<<"You entered a special character";

getch();
}



First of all I read a character an then compare it with ASCII values given below.
Uppercase Alphabet: 65-90
Lowercase Alphabet: 97-122
Digit: 48-57
If ASCII value of character is other then the values mentioned above then it is a special character.

Sunday, 10 August 2014

SWITCH CASE Structure

Tapan     01:30  No comments
When decision from a number of choices is required, at that time switch-case default is used.


A switch statement allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each switch case.

Syntax for the switch - case structure is as follows :

Switch ( integer expression)
{
case value1 : action1 ;
case value2 : action2 ;
default : action3 ;
}

First the expression is evaluated.
After getting the value it is matched one by one with constant values in case statements.
When a match is found, it executes the statements following that case and all subsequent case and default statements as well.

Switch Case Structure


Execution of the Switch:

  1. Integer expression is any constant or expression that evaluates to an integer.
  2. The keyword case is followed by an integer or a character constant.
  3. Float is not allowed as case value.
  4. Each constant in each case must be different from all others.


Notes while using the Switch:

  1. Order is not important while putting the case values.
  2. No enclosure is needed in case statements.
  3. break statement must be used to prevent the execution of subsequent cases.
  4. Use of continue will not take the control to beginning of switch.

Switch & if-else:

Switch is a better way of writing programs.
In certain situations switch is not useful.
Example : i <= 20
More structured program in switch

Popular Post

Website Worth

Contact Us

Name

Email *

Message *

© 2014 BCA Developer. Powered by E Friends.