Professional Documents
Culture Documents
Lecture #3: Click To Edit Master Subtitle Style
Lecture #3: Click To Edit Master Subtitle Style
Lecture #3: Click To Edit Master Subtitle Style
5/5/12
Write a program If Basic salary is <1500 HRA=10%of BS DA=90%of BS If Basic salary is <1500 HRA=500 DA=98%of BS Employees salary is entered through 5/5/12 key board. Find Gross Salary.
A Simple Calculator
int main() { int a,b.choice,c; scanf("%d %d %d ",&a,&b,&choice); if(choice===0) { c=a+b; } else { if(choice==1)
5/5/12
5/5/12
5/5/12
#include "stdio.h" int main() { int n1.n2,result,choice; scanf(%d %d %d ",&n1.,$&n2,&choice); switch(choice) { case 1: result=n1+n2; break; case 2: result=n1-n2;
5/5/12
case 4: if(n2==0) {
5/5/12
Conditional Operators.
5/5/12
1st Precedence : 2nd Precedence: 3rd Precedence: In case of tie, Evaluate from left to right E.g M=a+b+c/5 In C M= (a+b+c)/5 Z=10*3%1+5/2-3
5/5/12
Repetition Statements.
For Loop. Nested For loops. While Loop. Do while Loop. Break and Continue Statements
5/5/12
For Loop
5/5/12
For Loop.
printf("%d\n",x); }
5/5/12
#include "stdio.h" int main() { int sum=0; int number; for(number=2;number<=100;number+=2) { sum+=number; } printf("sum is %d\n",sum); 5/5/12
5/5/12
#include "stdio.h" int main() { int x=0; int y=0; for(x=0;x<4;x++) { for(y=0;y<=x;y++) { printf("*"); }
5/5/12
#include "stdio.h" int main() { int x,y; for(x=0;x<6;x++) { for(y=0;y<6;y++) { if(x==0||y==0||x==5||y==5) printf(*); else printf(" ");
5/5/12
#include "stdio.h" int main() { int x,y; for(x=0;x<4;x++) { for(y=0;y<4;y++) { printf("%d",x+y); } printf(\n");
5/5/12
While Loop
Do While Loop:
Enter Loop
Increment
F
Test 5/5/12 Exit Loop
When to Use
C Structure
We know how many loop for, while repetitions will be needed in advance. Input of a list of data ended by a special value while while
Repeated interactive input do-while of a value until a desired value is entered. Repeated processing of datawhile, for until a desired condition is 5/5/12 met.
Break Statements
Continue Statement
Surprise
5/5/12