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

Experiment NO 15 &16

The document contains multiple C programming exercises, including printing patterns of asterisks and numbers, sorting an array in ascending order, and calculating the sum of array elements. Each exercise is accompanied by sample code demonstrating the implementation of the respective task. The document serves as a guide for practicing basic programming concepts in C.

Uploaded by

Pranjal Chaugule
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)
10 views6 pages

Experiment NO 15 &16

The document contains multiple C programming exercises, including printing patterns of asterisks and numbers, sorting an array in ascending order, and calculating the sum of array elements. Each exercise is accompanied by sample code demonstrating the implementation of the respective task. The document serves as a guide for practicing basic programming concepts in C.

Uploaded by

Pranjal Chaugule
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

Experiment NO 15

WAP to print

*****

****

***

**

#include <stdio.h>

int main() {

int i, j, rows;

printf("Enter the number of rows: ");

scanf("%d", &rows);

for (i = rows; i >= 1; --i) {

for (j = 1; j <= i; ++j) {

printf("* ");

printf("\n");

return 0;

WAP to print following pattern

12
123

1234

12345

#include <stdio.h>

int main() {

int i, j, rows;

printf("Enter the number of rows: ");

scanf("%d", &rows);

for (i = 1; i <= rows; ++i) {

for (j = 1; j <= i; ++j) {

printf("%d ", j);

printf("\n");

return 0;

WAP to print given array in ascending order

#include <stdio.h>

void main (){

int num[20];

int i, j, a, n;

printf("Enter number of elements in an array");


scanf("%d", &n);

printf("Enter the elements");

for (i = 0; i < n; ++i)

scanf("%d", &num[i]);

//for arranging array in ascending order

for (i = 0; i < n; ++i)

for (j = i + 1; j < n; ++j)

if (num[i] > num[j]){

a = num[i];

num[i] = num[j];

num[j] = a;

//for printing array in ascending order

printf("The numbers in ascending order is:");

for (i = 0; i < n; ++i){

printf("%d", num[i]);

}
Experiment No 16

Write C program to input 5 numbers using array and display sum of it.

#include <stdio.h>

// Main function

int main()

int a[100]; // Declare an array of size 100 to store integer values

int i, n, sum = 0; // Declare variables to store array size, loop counter, and sum

// Display a message to the user about the program's purpose

printf("\n\nFind sum of all elements of array:\n");

printf("--------------------------------------\n");

// Prompt the user to input the number of elements to be stored in the array

printf("Input the number of elements to be stored in the array :");

scanf("%d", &n);

// Prompt the user to input n elements into the array

printf("Input %d elements in the array :\n", n);

for (i = 0; i < n; i++)

printf("element - %d : ", i);

scanf("%d", &a[i]); // Read the input and store it in the array

// Calculate the sum of all elements in the array using a for loop

for (i = 0; i < n; i++)

{
sum += a[i]; // Add each element to the sum

// Display the sum of all elements stored in the array

printf("Sum of all elements stored in the array is : %d\n\n", sum);

return 0;

Write C program to print array in ascending order.

#include <stdio.h>

void main (){

int num[20];

int i, j, a, n;

printf("Enter number of elements in an array");

scanf("%d", &n);

printf("Enter the elements");

for (i = 0; i < n; ++i)

scanf("%d", &num[i]);

//for arranging array in ascending order

for (i = 0; i < n; ++i)

for (j = i + 1; j < n; ++j)

if (num[i] > num[j]){

a = num[i];
num[i] = num[j];

num[j] = a;

//for printing array in ascending order

printf("The numbers in ascending order is:");

for (i = 0; i < n; ++i){

printf("%d", num[i]);

You might also like