0% found this document useful (0 votes)
140 views6 pages

15-BISE Lahore - C Language Practicals-StudentNotes

The document provides examples of C language programs to perform various tasks: 1) Convert between Fahrenheit and Celsius temperatures using formulas. 2) Find the maximum and minimum values from three user-input numbers. 3) Print a 3x3 grid of numbers using goto and nested loops. 4) Calculate the product of the first 20 odd numbers. 5) Calculate the area of geometric shapes like squares, rectangles, triangles, and circles using user-input values. 6) Print a pattern of increasing asterisks over 5 lines. 7) Print a pattern with increasing repetitions of a number on each line using nested loops.

Uploaded by

adil
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)
140 views6 pages

15-BISE Lahore - C Language Practicals-StudentNotes

The document provides examples of C language programs to perform various tasks: 1) Convert between Fahrenheit and Celsius temperatures using formulas. 2) Find the maximum and minimum values from three user-input numbers. 3) Print a 3x3 grid of numbers using goto and nested loops. 4) Calculate the product of the first 20 odd numbers. 5) Calculate the area of geometric shapes like squares, rectangles, triangles, and circles using user-input values. 6) Print a pattern of increasing asterisks over 5 lines. 7) Print a pattern with increasing repetitions of a number on each line using nested loops.

Uploaded by

adil
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/ 6

Chapter 15 : BISE Lahore – C Language Practicals

15.1 Year 2007 Onwards

Q : 15-01-01 : Write a program in C Language to Convert Fahrenheit into


Celsius by using formula C = 5 / 9 (F – 32).

#include<stdio.h>
void main (void)
{
float f, c ;
printf(“Please Enter Temperature in Fahrenheit => ”) ;
scanf(“%f”, &f) ;
c = (5 / 9) * (f – 32) ;
printf(“\nTemperature in Celsius = %f”, c) ;
}

OR

#include<stdio.h>
void main (void)
{
float f;
printf(“Please Enter Temperature in Fahrenheit => ”) ;
scanf(“%f”, &f) ;
printf(“\nTemperature in Celsius = %f”, (5 / 9) * (f – 32) ) ;
}

Q : 15-01-01 : Write a program in C Language to Convert Celsius into


Fahrenheit by using formula F = C * (9 / 5) + 32.

#include<stdio.h>
void main (void)
{
float f, c ;
printf(“Please Enter Temperature in Celsius => ”) ;
scanf(“%f”, &c) ;
f = c * (9 / 5) * + 32 ;
printf(“\nTemperature in Fahrenheit = %f”, f) ;
}

OR

1
#include<stdio.h>
void main (void)
{
float f;
printf(“Please Enter Temperature in Celsius => ”) ;
scanf(“%f”, &c) ;
printf(“\nTemperature in Fahrenheit = %f”, c * (9 / 5) * + 32) ;
}

Q : 15-01-02 : Write a program in C Language which displays the Maximum


and Minimum from N numbers (three numbers taken from user), also show its output.

#include<stdio.h>
void main (void)
{
unsigned int a, b, c;
printf(“Please Enter Value of Integer Number a => ”) ;
scanf(“%d”, &a) ;
printf(“Please Enter Value of Integer Number b => ”) ;
scanf(“%d”, &b) ;
printf(“Please Enter Value of Integer Number c => ”) ;
scanf(“%d”, &c) ;

if (a >= b)
{
if (a >= c)
printf (“Maximum Value = %d”, a);
else
printf (“Maximum Value = %d”, c);

if (b >= c)
printf (“Minimum Value = %d”, c);
else
printf (“Minimum Value = %d”, b);
}
else
{
if (b >= c)
printf (“Maximum Value = %d”, b);
else
printf (“Maximum Value = %d”, c);

if (c >= a)
printf (“Minimum Value = %d”, a);

2
else
printf (“Minimum Value = %d”, c);
}
}

Q : 15-01-03 : Write a program in C Language to Print The Output as shown


below by using goto and Nested Loop statement.
1 2 3
4 5 6
7 8 9

#include<stdio.h>
void main (void)
{
unsigned int num = 1 ;
outer_loop:
if (num == 9)
goto stop_printing ;
inner_loop:
printf (“%d\t”, num) ;
num++ ;
if (num % 3 != 0)
goto inner_loop ;
else
goto outer_loop ;

stop_printing ;
}

Q : 15-01-04 : Write a program in C Language to Calculate The Product of


First 20 Odd Numbers.
#include<stdio.h>
void main (void)
{
unsigned int odd, product ;
for (int i = 0 ; i < 20 ; i ++)
{
product = product * (i * 2 + 1) ;
}
printf(“Product of First 20 Odd Numbers = %d”, product) ;
}

3
Q : 15-01-05 : Write a program in C Language to Calculate and Print The
Area of a Geometrical Figure (Square, Rectangle, Right-Angle Triangle, Circle with
appropriate formula). (Take Values from user.). One of following required in EXAM (not all
simultaneously).
// Area of Square
#include<stdio.h>
void main (void)
{
float s, area ;
printf(“Please Enter Length of Side of Square => ”) ;
scanf(“%f”, &s) ;
area = s * s ;
printf(“\nArea of Square = %f”, area) ;
}

// Area of Rectangle
#include<stdio.h>
void main (void)
{
float length, width, area ;
printf(“Please Enter Length of Rectangle => ”) ;
scanf(“%f”, &length) ;
printf(“Please Enter Width of Rectangle => ”) ;
scanf(“%f”, &width) ;
area = length * width ;
printf(“\nArea of Rectangle = %f”, area) ;
}
// Area of Right-Angle Triangle
#include<stdio.h>
void main (void)
{
float base, perpendicular, area ;
printf(“Please Enter Base of Triangle => ”) ;
scanf(“%f”, &base) ;
printf(“Please Enter Perpendicular of Triangle => ”) ;
scanf(“%f”, &perpendicular) ;
area = base * perpendicular / 2 ;
printf(“\nArea of Right-Angle Triangle = %f”, area) ;
}

4
// Area of Circle
#include<stdio.h>
void main (void)
{
float radius, area ;
printf(“Please Enter Radius of Circle => ”) ;
scanf(“%f”, &radius) ;
area = (22 / 7) * radius * radius ;
printf(“\nArea of Circle = %f”, area) ;
}

Q : 15-01-06 : Write a program in C Language to Print out The Output as


below.
*
**
***
****
*****

#include<stdio.h>
void Print_Asterisks (void) ; // function prototype

void main(void)
{
// Function call
Print_Asterisks ( ) ;
}

void Print_Asterisks (void) // function header


{
// Function Body Starts
int inner ;
for (int outer = 1 ; outer <= 5 ; outer++)
{
inner = 1 ;
while ( inner <= outer)
{
printf(“* ”) ;
inner++ ;
}
printf (“\n”) ;
}
// Function Body Ends
}

5
Q : 15-01-07 : Write a program in C Language to Print Following Output
with the Help of Nested Loop statement.
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
6 6 6 6 6 6
7 7 7 7 7 7 7
8 8 8 8 8 8 8 8
9 9 9 9 9 9 9 9 9

#include<stdio.h>
void main (void)
{
unsigned int num ;
printf(“Please Enter a Number => ”) ;
scanf(“%f”, &num) ;
for (int i = 1 ; i <= num ; i ++)
{
for (int j = 1 ; j <= num ; j ++)
{
printf(“%d\t”, i) ;
}
}
} // Enter Value 9 and see result

You might also like