Presentation is loading. Please wait.

Presentation is loading. Please wait.

LESSON 3 IO, Variables and Operators

Similar presentations


Presentation on theme: "LESSON 3 IO, Variables and Operators"— Presentation transcript:

1 LESSON 3 IO, Variables and Operators

2 Review 1 #include(stdio.h) #include<conio.H> void Main() {
printf(“English /n”); print(“Physics”); printf(“Chem”) get ch; } Find the syntax error in each line.

3 Sample Code What is the output of the program?
#include <stdio.h> #include <conio.h> void main() { clrscr(); // printf(“English \n”); /* printf(“Physics”); printf(“Chemistry”);*/ printf(“Engineering Workshop”); getch(); } What is the output of the program?

4 Review 2 Find the syntax error in each line. #include<stdio.h>
#include<conio.h> void main(); { printF(“English \n”); printf(Physics”); printf(‘Chem’); /printf(“Math”); /*printf(“Math”); getch(); } Find the syntax error in each line.

5 Variable Memory places to store data. 123 Total

6

7 Data Types

8 Rules in Naming a Variable
Variables must consist of letters, digits and underscore (_) only. It should not be a keyword. White space is not allowed. Special characters/symbol NOT allowed. In one program 2 variables cant have the same name.

9 C Keywords auto break case char const continue default do double else
enum extern float for goto if inline int long register return short signed sizeof static struct switch typedef union unsigned void volatile while

10 Valid/Invalid Variable Names
X int Name double NAME name2 first_name _name first-name 2name first name v.a.l.u.e

11 Format Specifier

12 Sample Code Write a program that will print the following output:
#include<stdio.h> #include<conio.h> void main(); { int value1 = 10; float value2 = ; double value3 = ; char value4 = ‘C’; printf(“Value 1: %d \n”, value1); printf(“Value 2: %f \n”, value2); printf(“Value 3: %1f \n”, value3); printf(“Value 4: %c \n”, value4); getch(); } Write a program that will print the following output: Value 1: 10 Value 2: Value 3: Value 4: C Store the initial values to a variable.

13 Tell what data type will you use for the following data?
Sample Declaration 10 936.36 50000 ‘x’ 412.00

14 Tell what data type will you use for the following data?
Sample Declaration 10 int int n1=10; 936.36 float float n2=936.36; 50000 int n3=50000; ‘x’ char char n4=‘x’; 412.00 float n5=412.00

15 Write a program that adds two integers of 30 and 10.
Problem Write a program that adds two integers of 30 and 10.

16 Solution #include<stdio.h> #include<conio.h> void main() {
int n1,n2,sum; n1=30; n2=10; sum=n1+n2; printf(“Sum result of %d and %d = %d”, n1,n2,sum); getch(); }

17 Problem Write a program that reads two integers from keyboard and finds the addition of two the two numbers.

18 Solution #include<stdio.h> #include<conio.h> void main() {
int n1,n2,sum; printf(“Enter first number”); scanf(“%d”,&n1); printf(“Enter second number”); scanf(“%d”,&n2); sum=n1+n2; printf(“Sum result of %d and %d = %d”, n1,n2,sum); getch(); }

19 Arithmetic Operators

20 C Language Expression

21 Precedence of Operators


Download ppt "LESSON 3 IO, Variables and Operators"

Similar presentations


Ads by Google