Вы находитесь на странице: 1из 13

COMPUTER PROGRAMMING

Engr. Anees Ahmed Soomro


Assistant Professor
CSE QUEST Nawabshah
INTRODUCTION TO COMPUTER PROGRAMMING

1) Comments in C
2) Program Style, Round one, format specifiers
3) Variable, identifiers or Names in C and CONSTANTS IN C
4) Working with variable, identifiers or Names in C etc
Why use Comments
• Documentation of variables, functions and their usage.
• Explaining difficult section of code.
• Describes author, program, data, modification changes and
revisions.
• Best programmers comment as they write the code not after the fact.
Comments
• The addition of comments inside programs is desirable.
• These may be added to C programs by enclosing them as follows.
/* This code will not be compiled and executed*/
• Note that /*opens the comment field and
• */ closes the comment field
• Comments may span multiple lines
• Comments may not be nested one inside the another
• For example /* and /* and */ */ error generated.
Program Style, Round one, format specifiers

void main(void){printf(“This is the number two:%d”,2);}

• The white space characters(space, tab, newline) are invisible


by compiler.
• C distinguishes between UPPERCASE and LOWERCASE

Printing Numbers
void main(void)
{
printf(“This is the number two:%d”,2);
}
Format specifier

• It tells printf function to put a value in String and what forma


to use in printing value.

Printing Strings
void main(void)
{
printf(“%s is %d million miles from sun”, “venus”,67);
}

o/p
venus is 67 million miles from sun
Printing Characters

void main(void)
{
printf(“The letter %c is ”, ‘j’);
printf(“pronounced %s”, “jay”);
}

o/p
The letter j is pronounced jay
Variable

• Variable may be the most fundamental aspect of any computer


language.
• Variable is space in computer memory. Set aside for a certain
kind data and given a name for easy reference.
• Variables are used so that, the same space in memory can hold
different times.
• You need to store at least hourly rate and hours worked.

Identifiers or Names in C
• Identifiers in C must begin with a character or underscore
and may be followed by any combination of characters,
underscores or digits 0-9.
Example
summary exit_flag
Jerry7 Number_of_moves

Rule
Variables in lower case
Constant in upper case

void main(void)
{
int num; //variable declared
num=2; // variable assigned value
printf(“This is number two:%d”,num);
}
• All variables must be defined to specify their
name and set aside storage.

int apples, oranges, mangoes;


Format Specifiers

%c Single character.
%s String.
%d Signed Decimal Integer.
%f floating point(decimal notation).
%e floating point(exponential notation).
%u unsigned decimal integer.
%x unsigned hexadecimal (uses “abcdef”).
%o unsigned octal integer.
Escape Sequences
Escape Sequence Character
\a Bell (speaker beeps)
\b Backspace (non-erase)
\f Form feed/clear screen
\n New line
\r Carriage Return
\t Tab
\v Vertical tab
\\ Backslash
\? Question mark
\' Single quote
\" Double quote
\xnn Hexadecimal character code nn
\onn Octal character code nn
Working with variable

#include<stdio.h>
#include<conio.h>
void main(void)
{
int first,second,third;
first=10;
second=10;
third=10;

printf(“%d, %d and %d ”,first,second,third);

}
Working with variable

a. Write a program in C for three variables and display its addition.


b. Write a program in C for two variable and display its multiplication.
c. Write a program in C for two variables and display its division.
d. Write a program in C for two variables and display its subtraction.
e. Write a program in C for subject marks and find its percentage.
f. Write a program in C for radius and pi for area of circle.
g. Write a program in C for side of Square and find its Area.
h. Write a program in C for length and width of rectangle and find its Area

Вам также может понравиться