0% found this document useful (0 votes)
4K views18 pages

12th CS Imp Program Notes by Youth Academy

The document provides 10 computer programs with code examples. The programs cover topics like mathematical operations, area and volume calculations, temperature conversions and more. The Youth Academy aims to provide online computer science tutorials and notes for students.

Uploaded by

naveedeabbas24
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)
4K views18 pages

12th CS Imp Program Notes by Youth Academy

The document provides 10 computer programs with code examples. The programs cover topics like mathematical operations, area and volume calculations, temperature conversions and more. The Youth Academy aims to provide online computer science tutorials and notes for students.

Uploaded by

naveedeabbas24
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/ 18

YOUTH ACADEMY

WHATSAPP USAMA KHALID KAMBOH 0347-2782177 (9TH, 10TH) 0342-1016201(11TH, 12TH)

‫ى‬
‫ا����ڈ��آن���رى�وا�وا�وا�ادارہ‬ ‫ن‬
‫ ��ا������رى‬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

CHAPTER 09 IMPORTANT PROGRAMS

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;

printf("a = %d\n", a);


printf("b = %d\n", b);

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

CHAPTER 10 IMPORTANT PROGRAMS


PROGRAM 01:
Write a program that adds to floating point numbers and shows the sum on screen.
#include <stdio.h>
#include <conio.h>

int main()
{
float num1 = 10.5;
float num2 = 5.3;
float sum;

sum = num1 + num2;

printf("Sum of %.2f and %.2f is: %.2f\n", num1, num2, 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;

printf("Enter the height of the square: ");


scanf("%f", &height);

printf("Enter the width of the square: ");


scanf("%f", &width);

area = height * width;

printf("Area of Square = %.2f\n", 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;

printf("Enter four numbers: ");


scanf("%f %f %f %f", &num1, &num2, &num3, &num4);

sum = num1 + num2 + num3 + num4;


average = sum / 4;
product = num1 * num2 * num3 * num4;

printf("Sum = %.2f\n", sum);


printf("Average = %.2f\n", average);
printf("Product = %.2f\n", 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;

printf("Enter the radius of the sphere: ");


scanf("%f", &radius);

surface_area = 4 * 3.1416 * radius * radius;


3
‫امہایگروہںیااورابروہںیےکےئلڈاٹیرفامہرک ےاواالاوا دااار‬،‫اچراوںالکزسمہن‬
‫سیگرپیپزااورریپگنمیکسےکےیلویھتا ڈکیمویویٹبلنیچاوزٹرکںی‬
WHASTSAPP GROUP 0342-1016201
YOUTH ACADEMY
‫اکیالھکوٹسڈسٹنوکآنالنئایتریرکاوا ےاواالاوا دااار‬
‫ ویھتا ڈکیمےکاسھتاجری‬ONLINE ‫ھٹب‬r‫ااحتمانتیکایتریرھگ‬
YOUTH ACADEMY 0342-1016201 YOUTUBE CHANNEL

volume = (4.0 / 3.0) * 3.1416 * radius * radius * radius;

printf("Surface Area = %.2f\n", surface_area);


printf("Volume = %.2f\n", 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;

printf("Enter the radius of the circle: ");


scanf("%f", &radius);

area = 3.1416 * radius * radius;


circumference = 2 * 3.1416 * radius;

printf("Area = %.2f\n", area);


printf("Circumference = %.2f\n", 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;

printf("Enter temperature in Fahrenheit: ");


scanf("%f", &fahrenheit);

celsius = (fahrenheit - 32) * 5 / 9;

printf("Temperature in Celsius: %.2f\n", celsius);

getch();
}

PROGRAM 08:
4
‫امہایگروہںیااورابروہںیےکےئلڈاٹیرفامہرک ےاواالاوا دااار‬،‫اچراوںالکزسمہن‬
‫سیگرپیپزااورریپگنمیکسےکےیلویھتا ڈکیمویویٹبلنیچاوزٹرکںی‬
WHASTSAPP GROUP 0342-1016201
YOUTH ACADEMY
‫اکیالھکوٹسڈسٹنوکآنالنئایتریرکاوا ےاواالاوا دااار‬
‫ ویھتا ڈکیمےکاسھتاجری‬ONLINE ‫ھٹب‬r‫ااحتمانتیکایتریرھگ‬
YOUTH ACADEMY 0342-1016201 YOUTUBE CHANNEL

Write a program to convert distance from kilometers to meters.

#include <stdio.h>
#include <conio.h>

int main() {
float kilometers, meters;

printf("Enter distance in kilometers: ");


scanf("%f", &kilometers);

meters = kilometers * 1000;

printf("Distance in meters: %.2f\n", 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();
}

CHAPTER 11 IMPORTANT PROGRAMS

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;

printf("Enter your marks: ");


scanf("%d", &marks);

if (marks >= 40) {


printf("Congratulations! You have passed.\n");
}

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;

printf("Enter a number: ");


scanf("%d", &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;

printf("Enter three numbers: ");


scanf("%d %d %d", &num1, &num2, &num3);

if (num1 >= num2 && num1 >= num3) {


printf("Maximum number is: %d\n", num1);
} else if (num2 >= num1 && num2 >= num3) {
printf("Maximum number is: %d\n", num2);
} else {
printf("Maximum number is: %d\n", 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;

printf("Enter two numbers: ");


scanf("%d %d", &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;

printf("Enter a year: ");


scanf("%d", &year);

if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {


printf("%d is a leap year.\n", year);
} else {
printf("%d is not a leap year.\n", 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;

printf("Enter a number: ");


scanf("%d", &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;

printf("Enter two numbers: ");


scanf("%f %f", &num1, &num2);

printf("Enter an operator (+, -, *, /): ");


scanf(" %c", &operator); // Note the space before %c to consume any leading whitespace

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
}

printf("Result: %.2f\n", result);

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;

printf("Enter a number: ");


scanf("%f", &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

CHAPTER 12 IMPORTANT PROGRAMS

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:

Write a program to display alphabet from A to Z using for loop.

#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

clrscr(); // clear the screen


printf("The output is:\n");
for (i = 1; i <= 5; 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

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:

Write a program that displays the following pattern

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

You might also like