0% found this document useful (0 votes)
3 views32 pages

Lec 02

The document outlines various programming problems in C, focusing on data types, variables, and basic operations. It includes tasks such as printing patterns, performing arithmetic operations, and converting units. Additionally, it explains variable declaration, assignment, and type casting in C programming.

Uploaded by

shamimahsan109
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views32 pages

Lec 02

The document outlines various programming problems in C, focusing on data types, variables, and basic operations. It includes tasks such as printing patterns, performing arithmetic operations, and converting units. Additionally, it explains variable declaration, assignment, and type casting in C programming.

Uploaded by

shamimahsan109
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

Lec 02

Data type and Variables


Problem-1
Write a C program to print the following pattern in screen
*
**
***
****
*****
Problem-2
Write a C program to print the following pattern in screen
*
***
*****
***
*
Problem-3
Write a C program to find summation of two integer number
Variable is like box which store something (data) in it
Variable Declaration:
• Type of Data it contained
• Variable Name
…-2,-1,0,1,2,3

a
int a;
…-1.6,0,1,1.5

c double c;
a,b,A,B,+,…

char d;
d
Variable Assign a=10;
Solve
Solve
Solve
Problem-4
Write a C program to find average of two integer number
and print them on the screen as follows:

Solve:
Placeholders Output Type
%d Integer number

%lf Integer including fraction


number

%c Character

%f floating point number


Practice Problem

▪ Write a C program to find subtraction of two integer number

▪ Write a C program to find quotient and remainder of two


integer number

▪ Write a C program to find square of an integer number


What is
the output
of this
program?
Explanation
In programming,
y = x is not an equation that means y is always equal to x
y=x means the value of x is stored in the y variable.

= is called the assign operator.


It is used when we want to store something inside a
variable.
Problem-5
Write a C program to find summation of two fraction number
print them on the screen as follows:

Solve:
Problem-6
Write a C program that take input 2 number from user and
find summation of two fraction number
Problem-7
Write a C program that take input a character from user and
print it on screen
Highest number in “int” data type

4 Byte
1 Byte = 8 Bit
232= 4294967296
-2147483648 to 2147483648
Type Cast (Type conversions)
• To convert one data type to another.
Find the
problem in
this program
Comments in C Program
Problem-8
Write a C program to find the third angle of a triangle by
taking two angle from the user
Print the result on the screen as follows:
Problem-8
Write a C program that take input temperature in oC scale
from user and convert it into oF scale by taking input from the
user

Print the result on the screen as follows:


Problem-9
Write a C program that calculates the volume of a sphere
by taking radius as input from the user

Print the result on the screen as follows:


Problem-9
Write a C program that converts kilometers per hour to miles
per hour by taking input from the user

Print the result on the screen as follows:


Problem-11

Write a C program that takes hours and minutes as input, and


calculates the total number of minutes
Problem-12
Write a C program to Make a Simple Calculator to Add,
Subtract, Multiply and Divide by taking two number as input
from the user.
Print the result on the screen as follows:
10+2 = 12
10-2 = 8
10*2 = 2
10/2 = 5

You might also like