12th CS Imp Program Notes by Youth Academy
12th CS Imp Program Notes by Youth Academy
ى
ا����ڈ��آن���رى�وا�وا�وا�ادارہ ن
��ا������رىONLINE �ا��ات��رى
12TH COMPUTER
PROGRAMS NOTES
YOUTH PAID SERVICE
FOR ALL PUNJAB BOARDS
BY USAMA KHALID KAMBOH
CEO YOUTH ACADEMY
ڑ
�� اONLINE �� ب�ڑى
�پا�ن� ب
YOUTH ACADEMY
اکیالھکوٹسڈسٹنوکآنالنئایتریرکاوا ےاواالاوا دااار
ویھتا ڈکیمےکاسھتاجریONLINE ھٹبrااحتمانتیکایتریرھگ
YOUTH ACADEMY 0342-1016201 YOUTUBE CHANNEL
PROGRAM 01:
Write a program that performs all mathematical operations on two variables.
#include <stdio.h>
#include <conio.h>
int main()
{
int a = 10;
int b = 5;
// Addition
printf("Addition: a + b = %d\n", a + b);
// Subtraction
printf("Subtraction: a - b = %d\n", a - b);
// Multiplication
printf("Multiplication: a * b = %d\n", a * b);
// Division
printf("Division: a / b = %d\n", a / b);
// Modulus
printf("Modulus: a %% b = %d\n", a % b);
getch();
}
1
امہایگروہںیااورابروہںیےکےئلڈاٹیرفامہرک ےاواالاوا دااار،اچراوںالکزسمہن
سیگرپیپزااورریپگنمیکسےکےیلویھتا ڈکیمویویٹبلنیچاوزٹرکںی
WHASTSAPP GROUP 0342-1016201
YOUTH ACADEMY
اکیالھکوٹسڈسٹنوکآنالنئایتریرکاوا ےاواالاوا دااار
ویھتا ڈکیمےکاسھتاجریONLINE ھٹبrااحتمانتیکایتریرھگ
YOUTH ACADEMY 0342-1016201 YOUTUBE CHANNEL
int main()
{
float num1 = 10.5;
float num2 = 5.3;
float sum;
getch();
}
PROGRAM 02:
Write A Program To Calculate And Print The Area Of Square With Given Height And
Width.
#include <stdio.h>
#include <conio.h>
int main()
{
float height, width, area;
getch();
}
PROGRAM 03:
Write a program to display the following output on screen using printf.
*
* *
2
امہایگروہںیااورابروہںیےکےئلڈاٹیرفامہرک ےاواالاوا دااار،اچراوںالکزسمہن
سیگرپیپزااورریپگنمیکسےکےیلویھتا ڈکیمویویٹبلنیچاوزٹرکںی
WHASTSAPP GROUP 0342-1016201
YOUTH ACADEMY
اکیالھکوٹسڈسٹنوکآنالنئایتریرکاوا ےاواالاوا دااار
ویھتا ڈکیمےکاسھتاجریONLINE ھٹبrااحتمانتیکایتریرھگ
YOUTH ACADEMY 0342-1016201 YOUTUBE CHANNEL
* * *
* * * *
#include <stdio.h>
#include <conio.h>
int main() {
printf("*\n **/n ***/n ****/n");
getch();
}
PROGRAM 04:
Write a program that inputs four numbers and calculate the sum, average, and
product of all numbers.
#include <stdio.h>
#include <conio.h>
int main() {
float num1, num2, num3, num4;
float sum, average, product;
getch();
}
PROGRAM 05:
write a program that Inputs radius of sphere from the user. Calculate its surface area
and volume.
#include <stdio.h>
#include <conio.h>
int main() {
float radius, surface_area, volume;
getch();
}
PROGRAM 06:
Write a program that inputs radius of a circle from the user. Calculate is area and
circumference.
#include <stdio.h>
#include <conio.h>
int main() {
float radius, area, circumference;
getch();
}
PROGRAM 07:
Write a program that converts a temperature from Fahrenheit to Degree Celsius.
#include <stdio.h>
#include <conio.h>
int main() {
float fahrenheit, celsius;
getch();
}
PROGRAM 08:
4
امہایگروہںیااورابروہںیےکےئلڈاٹیرفامہرک ےاواالاوا دااار،اچراوںالکزسمہن
سیگرپیپزااورریپگنمیکسےکےیلویھتا ڈکیمویویٹبلنیچاوزٹرکںی
WHASTSAPP GROUP 0342-1016201
YOUTH ACADEMY
اکیالھکوٹسڈسٹنوکآنالنئایتریرکاوا ےاواالاوا دااار
ویھتا ڈکیمےکاسھتاجریONLINE ھٹبrااحتمانتیکایتریرھگ
YOUTH ACADEMY 0342-1016201 YOUTUBE CHANNEL
#include <stdio.h>
#include <conio.h>
int main() {
float kilometers, meters;
getch();
}
PROGRAM 09:
Write a program to display the following output on screen.
1 2 3 4 5
6 7 8 9 10
#include <stdio.h>
#include <conio.h>
int main() {
printf("1\t2\t3\t4\t5\n");
printf("6\t7\t8\t9\t10\n");
getch();
}
PROGRAM 10:
Write a program to display the following output on screen.
Pakistan is my country
Islamabad is its capital
#include <stdio.h>
#include <conio.h>
int main() {
printf("Pakistan\t is\tmy\tcountry\n");
printf("Islamabad\tis\tits\tcapital\n");
5
امہایگروہںیااورابروہںیےکےئلڈاٹیرفامہرک ےاواالاوا دااار،اچراوںالکزسمہن
سیگرپیپزااورریپگنمیکسےکےیلویھتا ڈکیمویویٹبلنیچاوزٹرکںی
WHASTSAPP GROUP 0342-1016201
YOUTH ACADEMY
اکیالھکوٹسڈسٹنوکآنالنئایتریرکاوا ےاواالاوا دااار
ویھتا ڈکیمےکاسھتاجریONLINE ھٹبrااحتمانتیکایتریرھگ
YOUTH ACADEMY 0342-1016201 YOUTUBE CHANNEL
getch();
}
PROGRAM 01:
Write a program that inputs marks and displays “Congratulations! You have passed”.
if the marks are 40 or more.
#include <stdio.h>
#include <conio.h>
void main() {
int marks;
getch();
}
PROGRAM 02:
write a program that inputs are number and find whether it is given or odd using if-
else structure.
#include <stdio.h>
#include <conio.h>
void main() {
int num;
if (num % 2 == 0) {
printf("%d is even.\n", num);
} else {
printf("%d is odd.\n", num);
}
getch();
6
امہایگروہںیااورابروہںیےکےئلڈاٹیرفامہرک ےاواالاوا دااار،اچراوںالکزسمہن
سیگرپیپزااورریپگنمیکسےکےیلویھتا ڈکیمویویٹبلنیچاوزٹرکںی
WHASTSAPP GROUP 0342-1016201
YOUTH ACADEMY
اکیالھکوٹسڈسٹنوکآنالنئایتریرکاوا ےاواالاوا دااار
ویھتا ڈکیمےکاسھتاجریONLINE ھٹبrااحتمانتیکایتریرھگ
YOUTH ACADEMY 0342-1016201 YOUTUBE CHANNEL
PROGRAM 03:
write a program that input three numbers and displays maximum number.
#include <stdio.h>
#include <conio.h>
void main() {
int num1, num2, num3;
getch();
}
PROGRAM 04:
Write a program that inputs two numbers and find whether these numbers are equal
or not using if-else structure.
#include <stdio.h>
#include <conio.h>
void main() {
int num1, num2;
if (num1 == num2) {
printf("The numbers are equal.\n");
} else {
printf("The numbers are not equal.\n");
}
getch();
7
امہایگروہںیااورابروہںیےکےئلڈاٹیرفامہرک ےاواالاوا دااار،اچراوںالکزسمہن
سیگرپیپزااورریپگنمیکسےکےیلویھتا ڈکیمویویٹبلنیچاوزٹرکںی
WHASTSAPP GROUP 0342-1016201
YOUTH ACADEMY
اکیالھکوٹسڈسٹنوکآنالنئایتریرکاوا ےاواالاوا دااار
ویھتا ڈکیمےکاسھتاجریONLINE ھٹبrااحتمانتیکایتریرھگ
YOUTH ACADEMY 0342-1016201 YOUTUBE CHANNEL
PROGRAM 05:
write a program that inputs an year and finds whether it is a leap year or not using if-
else structure.
#include <stdio.h>
#include <conio.h>
void main() {
int year;
getch();
}
PROGRAM 06:
write a program that inputs a number from user and determines whether it is positive,
negative or zero.
#include <stdio.h>
#include <conio.h>
void main() {
int num;
if (num > 0) {
printf("The number is positive.\n");
} else if (num < 0) {
printf("The number is negative.\n");
} else {
printf("The number is zero.\n");
}
getch();
}
8
امہایگروہںیااورابروہںیےکےئلڈاٹیرفامہرک ےاواالاوا دااار،اچراوںالکزسمہن
سیگرپیپزااورریپگنمیکسےکےیلویھتا ڈکیمویویٹبلنیچاوزٹرکںی
WHASTSAPP GROUP 0342-1016201
YOUTH ACADEMY
اکیالھکوٹسڈسٹنوکآنالنئایتریرکاوا ےاواالاوا دااار
ویھتا ڈکیمےکاسھتاجریONLINE ھٹبrااحتمانتیکایتریرھگ
YOUTH ACADEMY 0342-1016201 YOUTUBE CHANNEL
PROGRAM 10:
Write a program that inputs two numbers and one arithmetic operator it applies
arithmetic operation on numbers on the basis of the operator by using switch
statement.
#include <stdio.h>
#include <conio.h>
void main() {
float num1, num2, result;
char operator;
switch (operator) {
case '+':
result = num1 + num2;
break;
case '-':
result = num1 - num2;
break;
case '*':
result = num1 * num2;
break;
case '/':
if (num2 != 0) {
result = num1 / num2;
} else {
printf("Error! Division by zero.\n");
getch(); due to error
return; // Exit the program early due to error
}
break;
default:
printf("Error! Invalid operator.\n");
getch(); due to error
return; // Exit the program early due to error
}
getch();
}
PROGRAM 11:
9
امہایگروہںیااورابروہںیےکےئلڈاٹیرفامہرک ےاواالاوا دااار،اچراوںالکزسمہن
سیگرپیپزااورریپگنمیکسےکےیلویھتا ڈکیمویویٹبلنیچاوزٹرکںی
WHASTSAPP GROUP 0342-1016201
YOUTH ACADEMY
اکیالھکوٹسڈسٹنوکآنالنئایتریرکاوا ےاواالاوا دااار
ویھتا ڈکیمےکاسھتاجریONLINE ھٹبrااحتمانتیکایتریرھگ
YOUTH ACADEMY 0342-1016201 YOUTUBE CHANNEL
Write a program that a number it displays square root of the number if the number is
positive. otherwise the program display a message "invalid output" using if else
#include <stdio.h>
#include <math.h>
#include <conio.h>
void main() {
float num;
if (num >= 0) {
printf("Square root of %.2f is %.2f\n", num, sqrt(num));
} else {
printf("Invalid output\n");
}
getch();
}
10
امہایگروہںیااورابروہںیےکےئلڈاٹیرفامہرک ےاواالاوا دااار،اچراوںالکزسمہن
سیگرپیپزااورریپگنمیکسےکےیلویھتا ڈکیمویویٹبلنیچاوزٹرکںی
WHASTSAPP GROUP 0342-1016201
YOUTH ACADEMY
اکیالھکوٹسڈسٹنوکآنالنئایتریرکاوا ےاواالاوا دااار
ویھتا ڈکیمےکاسھتاجریONLINE ھٹبrااحتمانتیکایتریرھگ
YOUTH ACADEMY 0342-1016201 YOUTUBE CHANNEL
PROGRAM 01:
Write a program that inputs a number from the user and displace a table of that number
using while loop.
#include <stdio.h>
#include <conio.h>
int main()
{
int num, i = 1;
printf("Enter a number: ");
scanf("%d", &num);
clrscr(); // clear the screen
printf("Table of %d:\n", num);
while (i <= 10)
{
printf("%d x %d = %d\n", num, i, num * i);
i++;
}
getch(); // wait for a key press
PROGRAM 02:
write a program that displays the following series using while loop.
3 5 7 9 11 13 15
#include <stdio.h>
#include <conio.h>
int main()
{
int num = 3;
clrscr(); // clear the screen
printf("The series is:\n");
while (num <= 15)
{
printf("%d ", num);
num += 2; // increment by 2
}
printf("\n");
getch(); // wait for a key press
11
امہایگروہںیااورابروہںیےکےئلڈاٹیرفامہرک ےاواالاوا دااار،اچراوںالکزسمہن
سیگرپیپزااورریپگنمیکسےکےیلویھتا ڈکیمویویٹبلنیچاوزٹرکںی
WHASTSAPP GROUP 0342-1016201
YOUTH ACADEMY
اکیالھکوٹسڈسٹنوکآنالنئایتریرکاوا ےاواالاوا دااار
ویھتا ڈکیمےکاسھتاجریONLINE ھٹبrااحتمانتیکایتریرھگ
YOUTH ACADEMY 0342-1016201 YOUTUBE CHANNEL
PROGRAM 03:
Write a program that inputs are number from the user and displace the factorial of that
number.
#include <stdio.h>
#include <conio.h>
int main()
{
int num, i, fact = 1;
printf("Enter a number: ");
scanf("%d", &num);
clrscr(); // clear the screen
printf("The factorial of %d is: ", num);
i = num;
while (i > 0)
{
fact *= i; // multiply by i
i--;
}
printf("%d\n", fact);
getch(); // wait for a key press
PROGRAM 04:
#include <stdio.h>
#include <conio.h>
int main()
{
char ch;
clrscr(); // clear the screen
printf("The alphabet is:\n");
for (ch = 'A'; ch <= 'Z'; ch++)
{
printf("%c ", ch);
}
printf("\n");
getch(); // wait for a key press
PROGRAM 05:
Write a program to get a number and print “Prime number” if it is a prime number or print
“Not a Prime Number” if it is not.
#include <stdio.h>
#include <conio.h>
12
امہایگروہںیااورابروہںیےکےئلڈاٹیرفامہرک ےاواالاوا دااار،اچراوںالکزسمہن
سیگرپیپزااورریپگنمیکسےکےیلویھتا ڈکیمویویٹبلنیچاوزٹرکںی
WHASTSAPP GROUP 0342-1016201
YOUTH ACADEMY
اکیالھکوٹسڈسٹنوکآنالنئایتریرکاوا ےاواالاوا دااار
ویھتا ڈکیمےکاسھتاجریONLINE ھٹبrااحتمانتیکایتریرھگ
YOUTH ACADEMY 0342-1016201 YOUTUBE CHANNEL
int main()
{
int num, i, flag = 1;
printf("Enter a number: ");
scanf("%d", &num);
clrscr(); // clear the screen
printf("The number %d is: ", num);
for (i = 2; i < num; i++)
{
if (num % i == 0) // check if divisible by i
{
flag = 0; // not a prime number
break;
}
}
if (flag == 1)
{
printf("Prime number\n");
}
else
{
printf("Not a Prime number\n");
}
getch(); // wait for a key press
PROGRAM 06:
Write a program that is print the series of first 10 natural numbers and their sum.
#include <stdio.h>
#include <conio.h>
int main()
{
int i, sum = 0;
clrscr(); // clear the screen
printf("The series of first 10 natural numbers is:\n");
for (i = 1; i <= 10; i++)
{
printf("%d ", i);
sum += i; // add to sum
}
printf("\nThe sum is: %d\n", sum);
getch(); // wait for a key press
• Write a program that is print the series of first 10 odd numbers and their sum.
#include <stdio.h>
#include <conio.h>
13
امہایگروہںیااورابروہںیےکےئلڈاٹیرفامہرک ےاواالاوا دااار،اچراوںالکزسمہن
سیگرپیپزااورریپگنمیکسےکےیلویھتا ڈکیمویویٹبلنیچاوزٹرکںی
WHASTSAPP GROUP 0342-1016201
YOUTH ACADEMY
اکیالھکوٹسڈسٹنوکآنالنئایتریرکاوا ےاواالاوا دااار
ویھتا ڈکیمےکاسھتاجریONLINE ھٹبrااحتمانتیکایتریرھگ
YOUTH ACADEMY 0342-1016201 YOUTUBE CHANNEL
int main()
{
int i, sum = 0;
clrscr(); // clear the screen
printf("The series of first 10 odd numbers is:\n");
for (i = 1; i <= 20; i += 2) // increment by 2
{
printf("%d ", i);
sum += i; // add to sum
}
printf("\nThe sum is: %d\n", sum);
getch(); // wait for a key press
PROGRAM 07:
Write a program that is print the series of first 10 even numbers and their sum.
#include <stdio.h>
#include <conio.h>
int main()
{
int i, sum = 0;
clrscr(); // clear the screen
printf("The series of first 10 even numbers is:\n");
for (i = 2; i <= 20; i += 2) // increment by 2
{
printf("%d ", i);
sum += i; // add to sum
}
printf("\nThe sum is: %d\n", sum);
getch(); // wait for a key press
PROGRAM 09:
Write a program to produce the following output using nested for loop. *
*
**
***
****
*****
#include <stdio.h>
#include <conio.h>
int main()
{
int i, j;
14
امہایگروہںیااورابروہںیےکےئلڈاٹیرفامہرک ےاواالاوا دااار،اچراوںالکزسمہن
سیگرپیپزااورریپگنمیکسےکےیلویھتا ڈکیمویویٹبلنیچاوزٹرکںی
WHASTSAPP GROUP 0342-1016201
YOUTH ACADEMY
اکیالھکوٹسڈسٹنوکآنالنئایتریرکاوا ےاواالاوا دااار
ویھتا ڈکیمےکاسھتاجریONLINE ھٹبrااحتمانتیکایتریرھگ
YOUTH ACADEMY 0342-1016201 YOUTUBE CHANNEL
PROGRAM 10:
write a program that is displays the following output
0
0 1
0 1 4
0 1 4 9
0 1 4 9 16
0 1 4 9 16 25
#include <stdio.h>
#include <conio.h>
int main()
{
int i, j;
clrscr(); // clear the screen
printf("The output is:\n");
for (i = 0; i <= 5; i++) // outer loop for rows
{
for (j = 0; j <= i; j++) // inner loop for columns
{
printf("%d ", j * j); // print square of j
}
printf("\n"); // new line
}
getch(); // wait for a key press
PROGRAM 11:
4 4 4 4
3 3 3
2 2
15
امہایگروہںیااورابروہںیےکےئلڈاٹیرفامہرک ےاواالاوا دااار،اچراوںالکزسمہن
سیگرپیپزااورریپگنمیکسےکےیلویھتا ڈکیمویویٹبلنیچاوزٹرکںی
WHASTSAPP GROUP 0342-1016201
YOUTH ACADEMY
اکیالھکوٹسڈسٹنوکآنالنئایتریرکاوا ےاواالاوا دااار
ویھتا ڈکیمےکاسھتاجریONLINE ھٹبrااحتمانتیکایتریرھگ
YOUTH ACADEMY 0342-1016201 YOUTUBE CHANNEL
#include <stdio.h>
#include <conio.h>
int main()
{
int i, j;
clrscr(); // clear the screen
printf("The pattern is:\n");
for (i = 4; i >= 1; i--) // outer loop for rows
{
for (j = 1; j <= i; j++) // inner loop for columns
{
printf("%d ", i); // print i
}
printf("\n"); // new line
}
getch(); // wait for a key press
PROGRAM 12:
Write a program to produce the following output using nested for loop.
* * * * *
* * * *
* * *
* *
*
#include <stdio.h>
#include <conio.h>
int main()
{
int i, j;
clrscr(); // clear the screen
printf("The output is:\n");
for (i = 5; i >= 1; i--) // outer loop for rows
{
for (j = 1; j <= i; j++) // inner loop for columns
{
printf("* "); // print star
}
printf("\n"); // new line
}
getch(); // wait for a key press
16
امہایگروہںیااورابروہںیےکےئلڈاٹیرفامہرک ےاواالاوا دااار،اچراوںالکزسمہن
سیگرپیپزااورریپگنمیکسےکےیلویھتا ڈکیمویویٹبلنیچاوزٹرکںی
WHASTSAPP GROUP 0342-1016201