World Top Softwares
Login Please

Join the forum, it's quick and easy

World Top Softwares
Login Please
World Top Softwares
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Search
 
 

Display results as :
 


Rechercher Advanced Search

Log in

I forgot my password

Latest topics
» Practically as cut-price as files
8th program EmptyMon Aug 01, 2011 11:44 pm by Guest

» Netbook Brands
8th program EmptyMon Aug 01, 2011 5:39 am by Guest

» backlinks checker backlink service
8th program EmptySun Jul 31, 2011 8:56 am by Guest

» how to buy facebook fans f4
8th program EmptySat Jul 30, 2011 2:34 pm by Guest

» Alle bijzondere dingen in de zaanstreek
8th program EmptySat Jul 30, 2011 8:11 am by Guest

» HERE YOU CAN POST ALL WEBSITE LINKS...
8th program EmptyWed Aug 26, 2009 2:16 pm by onesimpletech

» cool web site for all must check it
8th program EmptyMon Jul 06, 2009 2:32 pm by Snopy Cobra

» poetry spirit
8th program EmptyMon Jul 06, 2009 2:31 pm by Snopy Cobra

» best to learn VC++
8th program EmptySun May 10, 2009 3:22 pm by Guest

Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search
Statistics
We have 30 registered users
The newest registered user is deigavr

Our users have posted a total of 191 messages in 126 subjects
Who is online?
In total there is 1 user online :: 0 Registered, 0 Hidden and 1 Guest

None

[ View the whole list ]


Most users ever online was 125 on Wed Apr 07, 2021 9:18 am
RSS feeds


Yahoo! 
MSN 
AOL 
Netvibes 
Bloglines 



8th program

Go down

8th program Empty 8th program

Post by Snopy Cobra Sun Jan 04, 2009 7:41 pm

Objective

Understanding the use of Switch.

Theory

A switch statement is a type of control statement that exists in most modern imperative programming languages (e.g., C, C++, C#, and Java). Its purpose is to allow the value of a variable or expression to control the flow of program execution. In some other programming languages, a statement that is syntactically different but conceptually the same as the switch statement is known as a case statement or a select statement.
A typical syntax is that the first line contains the actual word switch followed by either the name of a variable or some other expression allowed by the language's syntax. This variable or expression is usually referred to as the "control variable" of the switch statement. After this line, following lines define one or more blocks of code that represent possible branches that program execution may take.

Each block begins with a line containing the case keyword followed a value that the control variable may have. If the value of the control variable matches this value, program execution will jump to that block of code. If not, the value specified in the next block (if present) is examined and the process repeats.


Task

. Accept two numbers from the user. Then, display a menu with four options as given below:
1. Add numbers
2. Subtract second number from first
3. Multiply numbers
4. Divide first number by second number
* Prompt the user to enter a choice. Using switch to perform the appropriate calculation and display the result.


Coding:
#include<stdio.h>
void main(void)
{
float a=0.0,b=0.0;
char s;
printf("TYPE 1ST NUMBER THEN OPRETER THAN 2ND NUMBER\n");
scanf("%f %c %f",&a,&s,&b);
switch (s)
{
case'+':
printf("\n=%2.f",a+b);
break;
case'-':
printf("\n=%2.f",a-b);
break;
case'*':
printf("\n=%2.f",a*b);
break;
case'/':
printf("\n=%2.f",a/b);
break;
default:
printf("\nwrong opretor");
}
printf("\n\n");
}
Snopy Cobra
Snopy Cobra
Admin
Admin

Number of posts : 99
Age : 34
Location : Bahria University Karachi
Reputation : 0
Registration date : 2008-07-31

https://telecompk.forumotion.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum