SlideShare a Scribd company logo
1 of 13
1
University of Sargodha
Mandi Bahauddin campus
LAB Sheet#2
C Lab Report Submitted By:
Name: M Umar
RollNo: BSSE-F17-18
Submitted To:
Department of CS & IT University of Sargodha M.B.Din
Lab Date:2 January 2018 Marks & Signature
Submission Date: 16th
January 2018
2
Program No. 1
Title
Write a program to declare two integer and one float variables then initialize them to 10,
15, and 12.6. Also print the variable values in the screen.
Problem Analysis:
In this problem we will need three variables. The data type of two variables will
be integer and one will be float. In this we have to simply declare three variables and
assign them values.
Input Variables
Processing
variables/calculatio
ns
Output Variables Header files
Int a,b printf --------- Stdio.h
Float c
Algorithm:
1. Start.
2. Declare three variables (int a,b, float c)
3. Assign values to variables
4. Use printf to display the output.
5. Stop
Code:
#include<stdio.h>
int main(void)
{
int a,b;
float c;
a=10;b=15;c=12.6;
printf("%d %d %.1f",a,b,c);
return 0;
}
Output:
10 15 12.6
Program No. 2
Title:
Write a C program to prompt the user to input 3 integer values and print these values in
forward
and reversed order.
Problem Analysis:
In this we have to get three variables of data type integer from the user. We will
need three integers int a, int b, int c. We will use scanf () to get values from the user and
simply use
printf () to print values in forward and reverse order.
3
Input variable
Processing
variables/calculation
s
Output variables Header Files
int a,b,c; printf() ----- stdio.h
Algorithm:
1. Start
2. Declare three variables int a, b, c
3. Use scanf to get values from user
4. Use printf to print values in forward and reverse order
5. Display the result
6. Stop
Code:
#include<stdio.h>
int main(){
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
printf("Values in forward order = %dt%dt%d",a,b,c);
printf("nnValues in reverse order = %dt%dt%d",c,b,a);
return 0;}
Output:
5 6 7
Values in forward order = 5 6 7
Values in reverse order = 7 6 5
Program No. 3
Title:
To calculate simple and compound interest.
Problem Analysis:
In the above problem, we have to calculate two things, Simple Interest
and compound interest. We need three input variables for both simple and compound
interest. The three variables will be of float data type. We need the values of principle,
time and rate. Hence, the data types of these values will be float.
Si=(p*r*t)/100 : ci=p*(1+r/100)^t-p;
To use the power function we will have to include math.h header file.
Input variables Processing variables Output variables Header files
float p si=(p*r*t)/100 float si stdio.h
float r ci=p*(1+r/100)^t-p float ci Math.h
float t
4
Algorithm:
1. Start
2. Declare three variables of data type float float p,r,t
3. Use scanf() to get values from the user.
4. Declare an output variable of data type float, float si, to calculate and store the
values of Simple interest. Si=(p*r*t)/100.
5. Declare another output variable of data type float, float ci, to calculate and
store the values of compound interest. ci=p*(1+r/100)^t-p
6. Use printf() to show the output.
7. Stop
Code:
#include<stdio.h>
#include<math.h>
int main()
{
float p,r,t,si,ci;
printf("Enter the values of principle, rate and time =");
scanf("%f%f%f",&p,&r,&t);
si=(p*t*r)/100;
ci=p*pow(1+r/100,t)-p;
printf("Simple interest =%fncompound interest =%f",si,ci);
return 0;
}
Output:
Enter the values of principle, rate and time =2000 3.4 32
Simple interest =2176.000000
compound interest =3830.257813
Program No. 4
Title:
To swap two integers using a third integer.
Problem analysis:
In this we have to declare two variables and get the values from users by using
scanf(). Then declare another temporary variable temp to swap the values. Temp=a;
A=b; B=temp;
Input Varibles
Processing
variables
Output variables Header files
5
int a; Temp=a; -------- Stdio.h
int b; A=b;
int temp; B=temp;
Algorithm:
1. Start
2. Declare three variables int a,b,temp;
3. Use scanf to get values from the user.
4. To swap th values ,we will use an expression. temp=a;a=b;b=temp;
5. Use printf() to show output.
6. Stop
Code:
#include<stdio.h>
int main(){
int a,b,temp;
scanf("%d%d",&a,&b);
printf("values before swapping= %dt%d",a,b);
temp=a;a=b;b=temp;printf("nnvalues after swapping= %dt%d",a,b);
return 0;}
Output:
6 9
values before swapping= 6 9
values after swapping= 9 6
To swap two values without using third variable.
Problem Analysis:
In this we have to declare two variables of data type integer int a, int b. We will
use scanf() to get the values of a & b from the user. To swap the values simply use
printf() statement.
Printf(“%dt %d”,b,a);
Input variable processing variables Output variable Header files
int a; printf stdio.h
int b;
Algorithm:
1. Start
2. Declare two variables of data type integer int a,b.
3. Use scanf() to get values from the user.
4. Use printf() to swap th values.
5. Display the result
6
6. Stop
Code:
#include<stdio.h>
int main()
{
int a,b;
scanf("%d%d",&a,&b);
printf("values before swapping= %dt%d",a,b);
printf("nnvalues after swapping= %dt%d",b,a);
return 0;
}
Output:
7 2
values before swapping= 7 2
values after swapping= 2 7
Program No. 5
Title:
To check that the input number is even or odd (a). Modulus Operator.
Problem Analysis:
In this we will have to get a number from the user. The data type of the number will be
integer int n. We will use modulus operator. If the mode of n%2=0 then it is even,
otherwise it will be an odd number. We will use if-else statement.
Input variable Processing variables Output variable Header files
int n; if(a%2==0),even stdio.h
else odd
Algorithm:
1. Start
2. Declare an variable int n, and use scanf() to get values from the user.
3. Use modulus operator and if-else statement to check whether the number is
even or odd.
4. If(a%2==0) then number is even else the number will be odd.
5. Display the result
6. Stop
Code:
#include<stdio.h>
int main()
{
int n;
7
scanf("%d",&n);
if(n%2==0)
{
printf("%d is an even number",n);
}
else{
printf("%d is an odd number",n);
}
return 0;
}
Output:
57
57 is an odd number
To check that the input number is even or odd.(b). Using bitwise operator.
Problem Analysis:
We can check that the number is even or odd by using AND (&) bitwise
operator. In this we will use scanf() to get value from the user and use AND to check
whether it is even
or odd. If the AND of n will be equal to 1, than it will be odd number, otherwise it will be
even number.
Algorithm:
1. Start
2. Declare an variable of data type integer to get number from user, int n.
3. Use scanf() to get n from user.
4. Use if(n&1) to check whether the number is even or odd.
5. If n&1 , then it is odd number else it is even.
6. Use printf() to show the output.
7. Stop
Code:
#include<stdio.h>
int main(){
int n;
scanf("%d",&n);
if(n&1){
printf("%d is an ODD number",n);
}else{
printf("%d is an EVEN number",n);}
return 0;}
Output:
8
4
4 is an EVEN number
To check that the input number is even or odd. (C). Without Using Modulus and
bitwise operator.
Problem Analysis:
In this we have to check the input number whether it is even or odd without
using modulus or bitwise operator. We will use expression n/2*2==n.
Algorithm:
1. Start
2. Declare an variable int n.
3. Use scanf() to get values from the user.
4. If(n/2*2==n) then it is even else it is an odd number
5. Display the result
6. Stop
Code:
#include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
if(n/2*2==n)
{
printf("%d is an Even number",n);
}
else{
printf("%d is an odd number",n);
}return 0;}
Output:
5
5 is an odd number
Write a program to check odd or even number. (d) using conditional operator.
Problem analysis:
In this we will have to get a number from the user. The data type of the number will be
integer int n. We will use conditional operator. If the mode of n%2=0 then “?” statement
will execute else “:” statement will execute.
Input variable Processing variables Output variable Header files
int n; (a%2==0) ? ------- stdio.h
:
Algorithm:
9
1. Start
2. Declare an variable int n, and use scanf() to get values from the user.
3. Use modulus operator and if-else statement to check whether the number
is even or odd.
4. Display the result
5. Stop
Code:
#include<stdio.h>
int main()
{
int n;
printf("Enter an integern");
scanf("%d",&n);
n%2 == 0 ? printf("Even numbern"): printf("Odd numbern");
return 0;
}
Output:
6
6 is an Even number
Program No. 6
Title:
Print the value of y for given x=2 & z=4 and analyze the output.
(A). y = x++ + ++x;
Code:
#include<stdio.h>
int main()
{
int x=2,z=4,y;
y=x++ + ++x;
printf("%d",y);
return 0;
}
Output:
6
Analyzing Output:
10
As we are using y=x++ + ++x;
When this statement will be executed, at first the value of x=2, and is used and after that
the value of x
is incremented by 1, now x=3. For second x in the expression, the value of x will
preincrement and now
x=4 will be used in place of second x.
So, y=2+4;
Initial value of x=2, and is used in first x in the expression. Then x is incremented by 1,
now x=3.
For second x, the value of x will preincrement and then x=4.
y=2+4;
(b). y=++x + ++x;
Code:
#include<stdio.h>
int main()
{
int x=2,z=4,y;
y=++x + ++x;
printf("%d",y);
return 0;
}
Output:
8
Analyzing Output:
As we are using y=++x + ++x;
++x means first increase the value of x by 1 and then use it. Whereas x++ means first
use the value of x and then increment it’s value by 1.
So the value of x increases from 2 to 3 and the value of z after increases from 4 to 5.
x=3, z=5
3+5=8
(c). y= ++x + ++x + ++x;
Code:
11
#include<stdio.h>
int main()
{
int x=2,z=4,y;
y=++x + ++x + ++x;
printf("%d",y);
return 0;
}
Output:
13
Analyzing output:
As we are using y=++x + ++x + ++x;
++x means first increase the value of x by 1 and then use it
(d). y=x>z;
Code:
#include<stdio.h>
int main()
{
int x=2,z=4,y;
y=x>z ;
printf("%d",y);
return 0;
}
Output:
0
Analyzing Output:
Y=x>z;
In the above statement, we are using a relational operator “>”. When the statement
y=x>z; will run. The
condition x>z will be evaluated. Depending on condition this will return a binary digit 0 or
1. If the
condition is true it will return 1, and if condition is false it will return 0. As x=2, z=4,
y=2>4.As 2 is not
greater than 4, so it will retrun 0 to y.
Y=0.
12
(e). y=x>z?x:z;
Code:
#include<stdio.h>
int main(void)
{
int x=2,z=4,y;
y=x>z?x:z;
printf("%d",y);
return 0;
}
Output:
4
Analyzing Output:
Y=x>z?x:z;
In the above statement a conditional ternary operator “?” is used. The syntax of
conditional ternary
operator is condition? result 1 : result 2;
If condition will be true result 1 will be execute otherwise result 3 will be executed.
(f). y=x&z.
Code:
#include<stdio.h>
int main()
{
int x=2,z=4,y;
y=x&z;
printf("%d",y);
return 0;
}
Output:
0
Analyzing Output:
Y=x&z;
A bitwise operator AND “&” is used. The output of bitwise AND is 1 if the corresponding
bits of two operands is 1. If either bit of an operand is 0, the result of corresponding bit
is evaluated to 0. In the above program bitwise operator is applied on two variables x=2
and z=4.
Applying & operator= 0000
Hence the value 0 will be returned. Therefore y=0.
As 2 in binary= 0010
As 4 in binary= 0100
13
(g). y= x>>2 + z<<1;
Code:
#include<stdio.h>
int main()
{
int x=2,z=4,y;
y= x>>2 + z<<1;
printf("%d",y);
return 0;
}
Output:
0
Analyzing Output:
We are using bitwise right shift and bitwise left shift operators in above program. Bit
Pattern of the data can be shifted by specified number of Positions to Right and Bit
Pattern of the data can be shifted by specified number of Positions to Left. When Data
is Shifted Right , leading zero’s are filled with zero and When Data is Shifted Left ,
trailing zero’s are filled with zero. Right shift Operator is Binary Operator [Bi – two] and
left shift Operator is also Binary Operator [Bi – two]. Binary means , Operator that
require two arguments.

More Related Content

What's hot

How to execute a C program
How to execute a C  program How to execute a C  program
How to execute a C program Leela Koneru
 
C++ Function
C++ FunctionC++ Function
C++ FunctionHajar
 
16717 functions in C++
16717 functions in C++16717 functions in C++
16717 functions in C++LPU
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT03062679929
 
Call by value
Call by valueCall by value
Call by valueDharani G
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given numberMainak Sasmal
 
Let us c (by yashvant kanetkar) chapter 1 solution
Let us c (by yashvant kanetkar) chapter 1 solutionLet us c (by yashvant kanetkar) chapter 1 solution
Let us c (by yashvant kanetkar) chapter 1 solutionHazrat Bilal
 
Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonBasics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonSujith Kumar
 
Dynamic memory allocation in c
Dynamic memory allocation in cDynamic memory allocation in c
Dynamic memory allocation in clavanya marichamy
 
Simple c program
Simple c programSimple c program
Simple c programRavi Singh
 

What's hot (20)

Functions in c
Functions in cFunctions in c
Functions in c
 
Header files in c
Header files in cHeader files in c
Header files in c
 
Function in C program
Function in C programFunction in C program
Function in C program
 
C lab-programs
C lab-programsC lab-programs
C lab-programs
 
How to execute a C program
How to execute a C  program How to execute a C  program
How to execute a C program
 
C++ Function
C++ FunctionC++ Function
C++ Function
 
PPS Notes Unit 5.pdf
PPS Notes Unit 5.pdfPPS Notes Unit 5.pdf
PPS Notes Unit 5.pdf
 
C if else
C if elseC if else
C if else
 
16717 functions in C++
16717 functions in C++16717 functions in C++
16717 functions in C++
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
Call by value
Call by valueCall by value
Call by value
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Let us c (by yashvant kanetkar) chapter 1 solution
Let us c (by yashvant kanetkar) chapter 1 solutionLet us c (by yashvant kanetkar) chapter 1 solution
Let us c (by yashvant kanetkar) chapter 1 solution
 
Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonBasics of Object Oriented Programming in Python
Basics of Object Oriented Programming in Python
 
Dynamic memory allocation in c
Dynamic memory allocation in cDynamic memory allocation in c
Dynamic memory allocation in c
 
I PUC CS Lab_programs
I PUC CS Lab_programsI PUC CS Lab_programs
I PUC CS Lab_programs
 
Recursion in c
Recursion in cRecursion in c
Recursion in c
 
Simple c program
Simple c programSimple c program
Simple c program
 
functions of C++
functions of C++functions of C++
functions of C++
 

Similar to C programming Lab 2

Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given numberMainak Sasmal
 
Cs291 assignment solution
Cs291 assignment solutionCs291 assignment solution
Cs291 assignment solutionKuntal Bhowmick
 
Core programming in c
Core programming in cCore programming in c
Core programming in cRahul Pandit
 
B.Com 1year Lab programs
B.Com 1year Lab programsB.Com 1year Lab programs
B.Com 1year Lab programsPrasadu Peddi
 
SIMPLE C PROGRAMS - SARASWATHI RAMALINGAM
SIMPLE C PROGRAMS - SARASWATHI RAMALINGAMSIMPLE C PROGRAMS - SARASWATHI RAMALINGAM
SIMPLE C PROGRAMS - SARASWATHI RAMALINGAMSaraswathiRamalingam
 
Control structure of c
Control structure of cControl structure of c
Control structure of cKomal Kotak
 
Qust & ans inc
Qust & ans incQust & ans inc
Qust & ans incnayakq
 
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...DR B.Surendiran .
 
Pointers in C Language
Pointers in C LanguagePointers in C Language
Pointers in C Languagemadan reddy
 
C and Data structure lab manual ECE (2).pdf
C and Data structure lab manual ECE (2).pdfC and Data structure lab manual ECE (2).pdf
C and Data structure lab manual ECE (2).pdfjanakim15
 
Write a program to check a given number is prime or not
Write a program to check a given number is prime or notWrite a program to check a given number is prime or not
Write a program to check a given number is prime or notaluavi
 
introduction to c programming and C History.pptx
introduction to c programming and C History.pptxintroduction to c programming and C History.pptx
introduction to c programming and C History.pptxManojKhadilkar1
 
C decision making and looping.
C decision making and looping.C decision making and looping.
C decision making and looping.Haard Shah
 

Similar to C programming Lab 2 (20)

Progr3
Progr3Progr3
Progr3
 
C important questions
C important questionsC important questions
C important questions
 
C programs
C programsC programs
C programs
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
 
Cs291 assignment solution
Cs291 assignment solutionCs291 assignment solution
Cs291 assignment solution
 
Core programming in c
Core programming in cCore programming in c
Core programming in c
 
C code examples
C code examplesC code examples
C code examples
 
Programming egs
Programming egs Programming egs
Programming egs
 
B.Com 1year Lab programs
B.Com 1year Lab programsB.Com 1year Lab programs
B.Com 1year Lab programs
 
SIMPLE C PROGRAMS - SARASWATHI RAMALINGAM
SIMPLE C PROGRAMS - SARASWATHI RAMALINGAMSIMPLE C PROGRAMS - SARASWATHI RAMALINGAM
SIMPLE C PROGRAMS - SARASWATHI RAMALINGAM
 
Control structure of c
Control structure of cControl structure of c
Control structure of c
 
Qust & ans inc
Qust & ans incQust & ans inc
Qust & ans inc
 
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
 
C-LOOP-Session-2.pptx
C-LOOP-Session-2.pptxC-LOOP-Session-2.pptx
C-LOOP-Session-2.pptx
 
Pointers in C Language
Pointers in C LanguagePointers in C Language
Pointers in C Language
 
C and Data structure lab manual ECE (2).pdf
C and Data structure lab manual ECE (2).pdfC and Data structure lab manual ECE (2).pdf
C and Data structure lab manual ECE (2).pdf
 
Write a program to check a given number is prime or not
Write a program to check a given number is prime or notWrite a program to check a given number is prime or not
Write a program to check a given number is prime or not
 
Linux_C_LabBasics.ppt
Linux_C_LabBasics.pptLinux_C_LabBasics.ppt
Linux_C_LabBasics.ppt
 
introduction to c programming and C History.pptx
introduction to c programming and C History.pptxintroduction to c programming and C History.pptx
introduction to c programming and C History.pptx
 
C decision making and looping.
C decision making and looping.C decision making and looping.
C decision making and looping.
 

More from Zaibi Gondal

Wirless Security By Zohaib Zeeshan
Wirless Security By Zohaib ZeeshanWirless Security By Zohaib Zeeshan
Wirless Security By Zohaib ZeeshanZaibi Gondal
 
C project on a bookshop for saving of coustmer record
C project on a bookshop for saving of coustmer recordC project on a bookshop for saving of coustmer record
C project on a bookshop for saving of coustmer recordZaibi Gondal
 
Programming fundamentals
Programming fundamentalsProgramming fundamentals
Programming fundamentalsZaibi Gondal
 
Functional english
Functional englishFunctional english
Functional englishZaibi Gondal
 
application of electronics in computer
application of electronics in computerapplication of electronics in computer
application of electronics in computerZaibi Gondal
 

More from Zaibi Gondal (9)

Modal Verbs
Modal VerbsModal Verbs
Modal Verbs
 
Parts of speech1
Parts of speech1Parts of speech1
Parts of speech1
 
Wirless Security By Zohaib Zeeshan
Wirless Security By Zohaib ZeeshanWirless Security By Zohaib Zeeshan
Wirless Security By Zohaib Zeeshan
 
C project on a bookshop for saving of coustmer record
C project on a bookshop for saving of coustmer recordC project on a bookshop for saving of coustmer record
C project on a bookshop for saving of coustmer record
 
Backup data
Backup data Backup data
Backup data
 
Programming fundamentals
Programming fundamentalsProgramming fundamentals
Programming fundamentals
 
Functional english
Functional englishFunctional english
Functional english
 
application of electronics in computer
application of electronics in computerapplication of electronics in computer
application of electronics in computer
 
Model Verbs
Model VerbsModel Verbs
Model Verbs
 

Recently uploaded

Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 

Recently uploaded (20)

Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 

C programming Lab 2

  • 1. 1 University of Sargodha Mandi Bahauddin campus LAB Sheet#2 C Lab Report Submitted By: Name: M Umar RollNo: BSSE-F17-18 Submitted To: Department of CS & IT University of Sargodha M.B.Din Lab Date:2 January 2018 Marks & Signature Submission Date: 16th January 2018
  • 2. 2 Program No. 1 Title Write a program to declare two integer and one float variables then initialize them to 10, 15, and 12.6. Also print the variable values in the screen. Problem Analysis: In this problem we will need three variables. The data type of two variables will be integer and one will be float. In this we have to simply declare three variables and assign them values. Input Variables Processing variables/calculatio ns Output Variables Header files Int a,b printf --------- Stdio.h Float c Algorithm: 1. Start. 2. Declare three variables (int a,b, float c) 3. Assign values to variables 4. Use printf to display the output. 5. Stop Code: #include<stdio.h> int main(void) { int a,b; float c; a=10;b=15;c=12.6; printf("%d %d %.1f",a,b,c); return 0; } Output: 10 15 12.6 Program No. 2 Title: Write a C program to prompt the user to input 3 integer values and print these values in forward and reversed order. Problem Analysis: In this we have to get three variables of data type integer from the user. We will need three integers int a, int b, int c. We will use scanf () to get values from the user and simply use printf () to print values in forward and reverse order.
  • 3. 3 Input variable Processing variables/calculation s Output variables Header Files int a,b,c; printf() ----- stdio.h Algorithm: 1. Start 2. Declare three variables int a, b, c 3. Use scanf to get values from user 4. Use printf to print values in forward and reverse order 5. Display the result 6. Stop Code: #include<stdio.h> int main(){ int a,b,c; scanf("%d%d%d",&a,&b,&c); printf("Values in forward order = %dt%dt%d",a,b,c); printf("nnValues in reverse order = %dt%dt%d",c,b,a); return 0;} Output: 5 6 7 Values in forward order = 5 6 7 Values in reverse order = 7 6 5 Program No. 3 Title: To calculate simple and compound interest. Problem Analysis: In the above problem, we have to calculate two things, Simple Interest and compound interest. We need three input variables for both simple and compound interest. The three variables will be of float data type. We need the values of principle, time and rate. Hence, the data types of these values will be float. Si=(p*r*t)/100 : ci=p*(1+r/100)^t-p; To use the power function we will have to include math.h header file. Input variables Processing variables Output variables Header files float p si=(p*r*t)/100 float si stdio.h float r ci=p*(1+r/100)^t-p float ci Math.h float t
  • 4. 4 Algorithm: 1. Start 2. Declare three variables of data type float float p,r,t 3. Use scanf() to get values from the user. 4. Declare an output variable of data type float, float si, to calculate and store the values of Simple interest. Si=(p*r*t)/100. 5. Declare another output variable of data type float, float ci, to calculate and store the values of compound interest. ci=p*(1+r/100)^t-p 6. Use printf() to show the output. 7. Stop Code: #include<stdio.h> #include<math.h> int main() { float p,r,t,si,ci; printf("Enter the values of principle, rate and time ="); scanf("%f%f%f",&p,&r,&t); si=(p*t*r)/100; ci=p*pow(1+r/100,t)-p; printf("Simple interest =%fncompound interest =%f",si,ci); return 0; } Output: Enter the values of principle, rate and time =2000 3.4 32 Simple interest =2176.000000 compound interest =3830.257813 Program No. 4 Title: To swap two integers using a third integer. Problem analysis: In this we have to declare two variables and get the values from users by using scanf(). Then declare another temporary variable temp to swap the values. Temp=a; A=b; B=temp; Input Varibles Processing variables Output variables Header files
  • 5. 5 int a; Temp=a; -------- Stdio.h int b; A=b; int temp; B=temp; Algorithm: 1. Start 2. Declare three variables int a,b,temp; 3. Use scanf to get values from the user. 4. To swap th values ,we will use an expression. temp=a;a=b;b=temp; 5. Use printf() to show output. 6. Stop Code: #include<stdio.h> int main(){ int a,b,temp; scanf("%d%d",&a,&b); printf("values before swapping= %dt%d",a,b); temp=a;a=b;b=temp;printf("nnvalues after swapping= %dt%d",a,b); return 0;} Output: 6 9 values before swapping= 6 9 values after swapping= 9 6 To swap two values without using third variable. Problem Analysis: In this we have to declare two variables of data type integer int a, int b. We will use scanf() to get the values of a & b from the user. To swap the values simply use printf() statement. Printf(“%dt %d”,b,a); Input variable processing variables Output variable Header files int a; printf stdio.h int b; Algorithm: 1. Start 2. Declare two variables of data type integer int a,b. 3. Use scanf() to get values from the user. 4. Use printf() to swap th values. 5. Display the result
  • 6. 6 6. Stop Code: #include<stdio.h> int main() { int a,b; scanf("%d%d",&a,&b); printf("values before swapping= %dt%d",a,b); printf("nnvalues after swapping= %dt%d",b,a); return 0; } Output: 7 2 values before swapping= 7 2 values after swapping= 2 7 Program No. 5 Title: To check that the input number is even or odd (a). Modulus Operator. Problem Analysis: In this we will have to get a number from the user. The data type of the number will be integer int n. We will use modulus operator. If the mode of n%2=0 then it is even, otherwise it will be an odd number. We will use if-else statement. Input variable Processing variables Output variable Header files int n; if(a%2==0),even stdio.h else odd Algorithm: 1. Start 2. Declare an variable int n, and use scanf() to get values from the user. 3. Use modulus operator and if-else statement to check whether the number is even or odd. 4. If(a%2==0) then number is even else the number will be odd. 5. Display the result 6. Stop Code: #include<stdio.h> int main() { int n;
  • 7. 7 scanf("%d",&n); if(n%2==0) { printf("%d is an even number",n); } else{ printf("%d is an odd number",n); } return 0; } Output: 57 57 is an odd number To check that the input number is even or odd.(b). Using bitwise operator. Problem Analysis: We can check that the number is even or odd by using AND (&) bitwise operator. In this we will use scanf() to get value from the user and use AND to check whether it is even or odd. If the AND of n will be equal to 1, than it will be odd number, otherwise it will be even number. Algorithm: 1. Start 2. Declare an variable of data type integer to get number from user, int n. 3. Use scanf() to get n from user. 4. Use if(n&1) to check whether the number is even or odd. 5. If n&1 , then it is odd number else it is even. 6. Use printf() to show the output. 7. Stop Code: #include<stdio.h> int main(){ int n; scanf("%d",&n); if(n&1){ printf("%d is an ODD number",n); }else{ printf("%d is an EVEN number",n);} return 0;} Output:
  • 8. 8 4 4 is an EVEN number To check that the input number is even or odd. (C). Without Using Modulus and bitwise operator. Problem Analysis: In this we have to check the input number whether it is even or odd without using modulus or bitwise operator. We will use expression n/2*2==n. Algorithm: 1. Start 2. Declare an variable int n. 3. Use scanf() to get values from the user. 4. If(n/2*2==n) then it is even else it is an odd number 5. Display the result 6. Stop Code: #include<stdio.h> int main() { int n; scanf("%d",&n); if(n/2*2==n) { printf("%d is an Even number",n); } else{ printf("%d is an odd number",n); }return 0;} Output: 5 5 is an odd number Write a program to check odd or even number. (d) using conditional operator. Problem analysis: In this we will have to get a number from the user. The data type of the number will be integer int n. We will use conditional operator. If the mode of n%2=0 then “?” statement will execute else “:” statement will execute. Input variable Processing variables Output variable Header files int n; (a%2==0) ? ------- stdio.h : Algorithm:
  • 9. 9 1. Start 2. Declare an variable int n, and use scanf() to get values from the user. 3. Use modulus operator and if-else statement to check whether the number is even or odd. 4. Display the result 5. Stop Code: #include<stdio.h> int main() { int n; printf("Enter an integern"); scanf("%d",&n); n%2 == 0 ? printf("Even numbern"): printf("Odd numbern"); return 0; } Output: 6 6 is an Even number Program No. 6 Title: Print the value of y for given x=2 & z=4 and analyze the output. (A). y = x++ + ++x; Code: #include<stdio.h> int main() { int x=2,z=4,y; y=x++ + ++x; printf("%d",y); return 0; } Output: 6 Analyzing Output:
  • 10. 10 As we are using y=x++ + ++x; When this statement will be executed, at first the value of x=2, and is used and after that the value of x is incremented by 1, now x=3. For second x in the expression, the value of x will preincrement and now x=4 will be used in place of second x. So, y=2+4; Initial value of x=2, and is used in first x in the expression. Then x is incremented by 1, now x=3. For second x, the value of x will preincrement and then x=4. y=2+4; (b). y=++x + ++x; Code: #include<stdio.h> int main() { int x=2,z=4,y; y=++x + ++x; printf("%d",y); return 0; } Output: 8 Analyzing Output: As we are using y=++x + ++x; ++x means first increase the value of x by 1 and then use it. Whereas x++ means first use the value of x and then increment it’s value by 1. So the value of x increases from 2 to 3 and the value of z after increases from 4 to 5. x=3, z=5 3+5=8 (c). y= ++x + ++x + ++x; Code:
  • 11. 11 #include<stdio.h> int main() { int x=2,z=4,y; y=++x + ++x + ++x; printf("%d",y); return 0; } Output: 13 Analyzing output: As we are using y=++x + ++x + ++x; ++x means first increase the value of x by 1 and then use it (d). y=x>z; Code: #include<stdio.h> int main() { int x=2,z=4,y; y=x>z ; printf("%d",y); return 0; } Output: 0 Analyzing Output: Y=x>z; In the above statement, we are using a relational operator “>”. When the statement y=x>z; will run. The condition x>z will be evaluated. Depending on condition this will return a binary digit 0 or 1. If the condition is true it will return 1, and if condition is false it will return 0. As x=2, z=4, y=2>4.As 2 is not greater than 4, so it will retrun 0 to y. Y=0.
  • 12. 12 (e). y=x>z?x:z; Code: #include<stdio.h> int main(void) { int x=2,z=4,y; y=x>z?x:z; printf("%d",y); return 0; } Output: 4 Analyzing Output: Y=x>z?x:z; In the above statement a conditional ternary operator “?” is used. The syntax of conditional ternary operator is condition? result 1 : result 2; If condition will be true result 1 will be execute otherwise result 3 will be executed. (f). y=x&z. Code: #include<stdio.h> int main() { int x=2,z=4,y; y=x&z; printf("%d",y); return 0; } Output: 0 Analyzing Output: Y=x&z; A bitwise operator AND “&” is used. The output of bitwise AND is 1 if the corresponding bits of two operands is 1. If either bit of an operand is 0, the result of corresponding bit is evaluated to 0. In the above program bitwise operator is applied on two variables x=2 and z=4. Applying & operator= 0000 Hence the value 0 will be returned. Therefore y=0. As 2 in binary= 0010 As 4 in binary= 0100
  • 13. 13 (g). y= x>>2 + z<<1; Code: #include<stdio.h> int main() { int x=2,z=4,y; y= x>>2 + z<<1; printf("%d",y); return 0; } Output: 0 Analyzing Output: We are using bitwise right shift and bitwise left shift operators in above program. Bit Pattern of the data can be shifted by specified number of Positions to Right and Bit Pattern of the data can be shifted by specified number of Positions to Left. When Data is Shifted Right , leading zero’s are filled with zero and When Data is Shifted Left , trailing zero’s are filled with zero. Right shift Operator is Binary Operator [Bi – two] and left shift Operator is also Binary Operator [Bi – two]. Binary means , Operator that require two arguments.