An array is a collection of homogeneous data items stored in successive memory locations. It allows storing multiple elements of the same type using a single name. Elements in an array can be accessed using the array name and index number. Common operations on arrays include storing/retrieving elements, searching for a particular element or largest/smallest element, and calculating sum of elements based on certain criteria like even/odd indexing. Arrays can also be modified by inserting or deleting elements.
This document contains some programs of C using Data structures, like Stack, LinkedList, queue, Fibonacci series, addition and multiplication of two matrices,etc.
This document contains some programs of C using Data structures, like Stack, LinkedList, queue, Fibonacci series, addition and multiplication of two matrices,etc.
These problems are so common that you will find in any C learning curriculum. Either in your college or in any IT institute.
I have provided solutions to these problems as well.
Happy learning...
Let us C (by yashvant Kanetkar) chapter 3 SolutionHazrat Bilal
All rights reserved. No part of this slide
may be reproduced, stored in a retrieval
system, or transmitted, in any form or by
any means, without the prior permission.
Ex.1 Write a program to print the following pattern
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
Ex.2 Write a program to find bigger of three integers.
Ex.3 Write a program to calculate GCD between two numbers.
Ex.4 Write a program to find transpose of matrix.
Ex.5 Write a program which deletes an element from an array & display all other elements.
Ex.6 Write a program to calculate XA+YB where A & B are matrix & X=2, Y=3.
Ex.7 Write a program to calculate the total amount of money in the piggy bank, given that coins of Rs.10, Rs.5, Rs.2, RS.1.
& many more.....
Bubble Sort,Insertion Sort, Structures,Students Mark statement ,Pointers, Arithmetic operations on pointers, Files,Creating file, Reading file,Writing a text file,binary file,lab programs,c programs,example programs,c program,Bubble Sort in c,Insertion Sort in c, Structures in c,Students Mark statement in c ,Pointers in c, Arithmetic operations on pointers in c, Files in c,Creating file in c, Reading file in c,Writing a text file in c,binary file in c,lab program in c,c program,example program,c program,thiruvalluvar university,lab manual,c lab manual
These problems are so common that you will find in any C learning curriculum. Either in your college or in any IT institute.
I have provided solutions to these problems as well.
Happy learning...
Let us C (by yashvant Kanetkar) chapter 3 SolutionHazrat Bilal
All rights reserved. No part of this slide
may be reproduced, stored in a retrieval
system, or transmitted, in any form or by
any means, without the prior permission.
Ex.1 Write a program to print the following pattern
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
Ex.2 Write a program to find bigger of three integers.
Ex.3 Write a program to calculate GCD between two numbers.
Ex.4 Write a program to find transpose of matrix.
Ex.5 Write a program which deletes an element from an array & display all other elements.
Ex.6 Write a program to calculate XA+YB where A & B are matrix & X=2, Y=3.
Ex.7 Write a program to calculate the total amount of money in the piggy bank, given that coins of Rs.10, Rs.5, Rs.2, RS.1.
& many more.....
Bubble Sort,Insertion Sort, Structures,Students Mark statement ,Pointers, Arithmetic operations on pointers, Files,Creating file, Reading file,Writing a text file,binary file,lab programs,c programs,example programs,c program,Bubble Sort in c,Insertion Sort in c, Structures in c,Students Mark statement in c ,Pointers in c, Arithmetic operations on pointers in c, Files in c,Creating file in c, Reading file in c,Writing a text file in c,binary file in c,lab program in c,c program,example program,c program,thiruvalluvar university,lab manual,c lab manual
C Programming : Arrays, One Dimensional Arrays, Two Dimensional Arrays, Three Dimensional Arrays, Operations on Arrays like Insertion, Deletion, Searching, Sorting, Merging, Traversing, Matrix Manipulation like Addition, Multiplication etc. : Visit us at : www.rozyph.com
1sequences and sampling. Suppose we went to sample the x-axis from X.pdfrushabhshah600
1sequences and sampling. Suppose we went to sample the x-axis from Xmin to Xmax using a
step size of step
A)Draw a picture of what is going on.
B) Write a expression for n the total number of samples involved (in terms of Xmin, Xmax and
step)
C) Write out the sequence of x-samples
D) Write a direct and general expression for xi that captures the sequence
E) Write a recursive expression for the sequence
F) Write a program to compute and store the x-samples over the range -5x5 using a step size of
0.1 do everything in main ()
2 . We talked about the following string functions that are available in C (as long as you include
string.h):
int strlen(char str[])
void strcpy(char str1[], char str2[])
void strcat(char str1[], str2[])
Write your own versions of these functions; for example: int paul_strlen(int char str[]). Hint: for
your version of the strlen function, start at the first character in the array and keep counting until
you find the ‘\\0’ character (use a while loop for this). Note: Use your version of the strlen
function in the strcpy and strcat functions.
9. We want to insert a number into an array.
(a) Formulate the problem mathematically with two sequences: x and y. (b) Write a function of
the form:
insertNumIntoArray(int n, int array[], int num, int index)
The function inserts num into the array at the specified index. The rest of the array then follows.
For example, if num = 9 and index = 3 and array = [7 2 8 8 3 1 2] then the function will produce:
array = [7 2 8 9 8 3 1 2]
Note: assume that array is properly dimensioned to have at least 1 extra space for storage.
10. Repeat #2 by for the delete operation; that is, we want to delete a single element (at a
specified index) from an array; for example, suppose index = 3 and array = [50 70 10 90 60 20],
then the result will be
array: [50 70 10 60 20]
11. Repeat #2 by for an insert operation where we are inserting several values into the array. The
function should be of the form:
int insertArrayIntoArray(int n, int inArray[],
int nInsert, int insertArray[], int outArray[], int index)
The dimension of outArray is returned (explicitly). For example:
inArrayarray: [7 2 8 6 3 9]
insertArray: [50 60 70]
index: 2
outArray: [7 2 50 60 70 8 6 3 9]
Assume that outArray is large enough to hold all n + nInsert values.
Solution
#include
//Simulates strlen() library function
int paul_strlen(char str[])
{
int l;
for(l = 0; str[l] != \'\\0\'; l++) ;
return l;
}
//Simulates strcpy() library function
void paul_strcpy(char str1[], char str2[])
{
int c;
for(c = 0; str1[c] != \'\\0\'; c++)
str2[c] = str1[c];
str2[c] = \'\\0\';
printf(\"\ Original String: %s\", str1);
printf(\"\ Copied String: %s\", str2);
}
//Simulates strcat() library function
void paul_strcat(char str1[], char str2[])
{
int i, j;
for(i = 0; str1[i] != \'\\0\'; i++) ;
for (j = 0; str2[j] != \'\\0\'; i++, j++)
{
str1[i] = str2[j];
}
str1[i] = \'\\0\';
printf(\"\ Concatenated String: %s\", str1);
}
int main()
{
char data1[20], data2[20];
pri.
COURSE TITLE: SOFTWARE DEVELOPMENT VI
COURSE CODE: VIT 351
TOPICS COVERED:
ARRAYS
TYPES OF ARRAYS
MULTIDIMENSIONAL ARRAYS
CHARACTER HANDLING IN C
STRING HANDLING IN C
QUIZ SET 2
computer dataA computer is a machine that can be programmed to carry out sequences of arithmetic or logical operations (computation) automatically. Modern digital electronic computers can perform generic sets of operations known as programs. These programs enable computers to perform a wide range of tasks. A computer system is a nominally complete computer that includes the hardware, operating system (main software), and peripheral equipment needed and used for full operation. This term may also refer to a group of computers that are linked and function together, such as a computer network or computer cluster.
A broad range of industrial and consumer products use computers as control systems. Simple special-purpose devices like microwave ovens and remote controls are included, as are factory devices like industrial robots and computer-aided design, as well as general-purpose devices like personal computers and mobile devices like smartphones. Computers power the Internet, which links billions of other computers and users.
Early computers were meant to be used only for calculations. Simple manual instruments like the abacus have aided people in doing calculations since ancient times. Early in the Industrial Revolution, some mechanical devices were built to automate long, tedious tasks, such as guiding patterns for looms. More sophisticated electrical machines did specialized analog calculations in the early 20th century. The first digital electronic calculating machines were developed during World War II. The first semiconductor transistors in the late 1940s were followed by the silicon-based MOSFET (MOS transistor) and monolithic integrated circuit chip technologies in the late 1950s, leading to the microprocessor and the microcomputer revolution in the 1970s. The speed, power and versatility of computers have been increasing dramatically ever since then, with transistor counts increasing at a rapid pace (as predicted by Moore's law), leading to the Digital Revolution during the late 20th to early 21st centuries.
Implementation of checking the validity of an arithmetic expression, conversion from infix to postfix form, evaluation of a postfix expression (C code)
Thinking of getting a dog? Be aware that breeds like Pit Bulls, Rottweilers, and German Shepherds can be loyal and dangerous. Proper training and socialization are crucial to preventing aggressive behaviors. Ensure safety by understanding their needs and always supervising interactions. Stay safe, and enjoy your furry friends!
Executive Directors Chat Leveraging AI for Diversity, Equity, and InclusionTechSoup
Let’s explore the intersection of technology and equity in the final session of our DEI series. Discover how AI tools, like ChatGPT, can be used to support and enhance your nonprofit's DEI initiatives. Participants will gain insights into practical AI applications and get tips for leveraging technology to advance their DEI goals.
Read| The latest issue of The Challenger is here! We are thrilled to announce that our school paper has qualified for the NATIONAL SCHOOLS PRESS CONFERENCE (NSPC) 2024. Thank you for your unwavering support and trust. Dive into the stories that made us stand out!
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...Levi Shapiro
Letter from the Congress of the United States regarding Anti-Semitism sent June 3rd to MIT President Sally Kornbluth, MIT Corp Chair, Mark Gorenberg
Dear Dr. Kornbluth and Mr. Gorenberg,
The US House of Representatives is deeply concerned by ongoing and pervasive acts of antisemitic
harassment and intimidation at the Massachusetts Institute of Technology (MIT). Failing to act decisively to ensure a safe learning environment for all students would be a grave dereliction of your responsibilities as President of MIT and Chair of the MIT Corporation.
This Congress will not stand idly by and allow an environment hostile to Jewish students to persist. The House believes that your institution is in violation of Title VI of the Civil Rights Act, and the inability or
unwillingness to rectify this violation through action requires accountability.
Postsecondary education is a unique opportunity for students to learn and have their ideas and beliefs challenged. However, universities receiving hundreds of millions of federal funds annually have denied
students that opportunity and have been hijacked to become venues for the promotion of terrorism, antisemitic harassment and intimidation, unlawful encampments, and in some cases, assaults and riots.
The House of Representatives will not countenance the use of federal funds to indoctrinate students into hateful, antisemitic, anti-American supporters of terrorism. Investigations into campus antisemitism by the Committee on Education and the Workforce and the Committee on Ways and Means have been expanded into a Congress-wide probe across all relevant jurisdictions to address this national crisis. The undersigned Committees will conduct oversight into the use of federal funds at MIT and its learning environment under authorities granted to each Committee.
• The Committee on Education and the Workforce has been investigating your institution since December 7, 2023. The Committee has broad jurisdiction over postsecondary education, including its compliance with Title VI of the Civil Rights Act, campus safety concerns over disruptions to the learning environment, and the awarding of federal student aid under the Higher Education Act.
• The Committee on Oversight and Accountability is investigating the sources of funding and other support flowing to groups espousing pro-Hamas propaganda and engaged in antisemitic harassment and intimidation of students. The Committee on Oversight and Accountability is the principal oversight committee of the US House of Representatives and has broad authority to investigate “any matter” at “any time” under House Rule X.
• The Committee on Ways and Means has been investigating several universities since November 15, 2023, when the Committee held a hearing entitled From Ivory Towers to Dark Corners: Investigating the Nexus Between Antisemitism, Tax-Exempt Universities, and Terror Financing. The Committee followed the hearing with letters to those institutions on January 10, 202
Macroeconomics- Movie Location
This will be used as part of your Personal Professional Portfolio once graded.
Objective:
Prepare a presentation or a paper using research, basic comparative analysis, data organization and application of economic information. You will make an informed assessment of an economic climate outside of the United States to accomplish an entertainment industry objective.
A review of the growth of the Israel Genealogy Research Association Database Collection for the last 12 months. Our collection is now passed the 3 million mark and still growing. See which archives have contributed the most. See the different types of records we have, and which years have had records added. You can also see what we have for the future.
Safalta Digital marketing institute in Noida, provide complete applications that encompass a huge range of virtual advertising and marketing additives, which includes search engine optimization, virtual communication advertising, pay-per-click on marketing, content material advertising, internet analytics, and greater. These university courses are designed for students who possess a comprehensive understanding of virtual marketing strategies and attributes.Safalta Digital Marketing Institute in Noida is a first choice for young individuals or students who are looking to start their careers in the field of digital advertising. The institute gives specialized courses designed and certification.
for beginners, providing thorough training in areas such as SEO, digital communication marketing, and PPC training in Noida. After finishing the program, students receive the certifications recognised by top different universitie, setting a strong foundation for a successful career in digital marketing.
The simplified electron and muon model, Oscillating Spacetime: The Foundation...RitikBhardwaj56
Discover the Simplified Electron and Muon Model: A New Wave-Based Approach to Understanding Particles delves into a groundbreaking theory that presents electrons and muons as rotating soliton waves within oscillating spacetime. Geared towards students, researchers, and science buffs, this book breaks down complex ideas into simple explanations. It covers topics such as electron waves, temporal dynamics, and the implications of this model on particle physics. With clear illustrations and easy-to-follow explanations, readers will gain a new outlook on the universe's fundamental nature.
1. Array
An array is a finite set of same type of data items. In other word it is a collection of homogeneous
data items.
The elements of an array are stored in successive memory locations. An element of an array is
referred by array name and index number (subscript).
Types of array
1. One dimensional (1-D) or linear array
2. Two dimensional (2-D) array
1-D Array
An array that can be represented by only one dimension such as row or column and that holds
finite number of same type of data items is called one dimensional array.
Array B
1 2 3 4 5 6 7 8 9
0 10 12 13 19 20 23 18 29
Fig: Graphical representation of 1-D array
1, 2, …………., 9 index number
0, 10, …….., 29 data items or elements of the array
B the array name
Symbolically the element of the array is expressed as Bi or B[i], which denotes ith
element of the
array.
Store/retrieve an element into/from an array
int a[10], i, n;
scanf(“%d”, &n);
for(i=1;i<=n;i++)
{
scanf(“%d”, &a[i]);
}
for(i=1;i<=n;i++)
{
printf(“%d”, a[i]);
2. }
C Program to Store/retrieve an element into/from an array
#include <stdio.h>
int main()
{
int a[100], i, n;
printf("Enter number of elements in arrayn");
scanf("%d", &n);
printf("Enter %d elementsn", n);
for (i = 1; i <= n; i++)
{
scanf("%d", &a[i]);
}
printf("Array elementsn");
for (i = 1; i <= n; i++)
{
printf("%dt", a[i]);
}
return 0;
}
Sample Output
Enter number of elements in array
5
Enter 5 elements
1
2
3
4
3. 5
Array elements
1 2 3 4 5
Algorithm to search the largest element of a list
1. Input x[1….n]
2. for(i=1;i<=n;i++)
Store data to x[i];
3. large=x[1];
4. for(i=2;i<=n;i++)
if(large<x[i])
large=x[i];
5. Output: The largest number (print the value of large)
C program to search the largest element of a list
#include<stdio.h>
#include<conio.h>
int main()
{
int x[100],i,n,large;
printf("Enter the number of elements: ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d",&x[i]);
}
large=x[1];
for(i=2;i<=n;i++)
{
if(large<x[i])
4. {
large=x[i];
}
}
printf("The largest among the %d elements is %d",n,large);
return 0;
}
Sample Output
Enter the number of elements: 5
12
6
7
9
0
The largest among the 5 elements is 12
Algorithm to search a particular element from a list
1. Input: A set of data in array a, and variable x. i.e., the target element
a[1….n], x;
2. found=0
3. for (i=1; i<=n; i++)
{
if (a[i]==x)
location=i;
found= 1;
break;
}
4. Output: if (found==1)
print”FOUND” message and location.
5. else print ”NOT FOUND” message
C program to search a particular element from a list
#include <stdio.h>
int main()
{
int array[100], search, c, n;
printf("Enter the number of elements in arrayn");
scanf("%d",&n);
printf("Enter %d integer(s)n", n);
for (c = 0; c < n; c++)
scanf("%d", &array[c]);
printf("Enter the number to searchn");
scanf("%d", &search);
for (c = 0; c < n; c++)
{
if (array[c] == search)
{
printf("%d is present at location %d.n", search, c+1);
break;
}
}
if (c == n)
printf("%d is not present in array.n", search);
return 0;
}
Sample Output
Enter the number of elements in array
6. 6
Enter 6 integer(s)
3
4
0
2
9
7
Enter the number to search
0
0 is present at location 3.
Algorithm to find out the summations of even and odd numbers
1. Input: An array and variable (to store the results of summations)
A[1….n], sum_odd=0, sum_even=0;
2. for (i=1; i<=n; i++)
{
if(A[i]%2==0), sum_even=sum_even+A[i];
else sum_odd=sum_odd+A[i];
}
3. Output: Summationof odd numbers (print sum_odd) and
Summation of even numbers (print sum_even)
C program to find out the summations of even and odd numbers
#include <stdio.h>
int main()
{
int array[100], i, num, sum_of_odd = 0, sum_of_even = 0;
printf("Enter the number of elementsn");
7. scanf("%d", &num);
printf("Enter the elements n");
for(i=1;i<=num;i++)
{
scanf("%d",&array[i]);
}
for (i = 1; i <= num; i++)
{
if (array[i] % 2 == 0)
sum_of_even = sum_of_even + array[i];
else
sum_of_odd = sum_of_odd + array[i];
}
printf("Sum of all odd numbers = %dn", sum_of_odd);
printf("Sum of all even numbers = %dn", sum_of_even);
return 0;
}
Sample Output
Enter the number of elements
5
Enter the elements
1
2
5
3
9
Sum of all odd numbers = 18
Sum of all even numbers = 2
8. Algorithm to find out the summations of even and odd indexed numbers
1. Input: An array and variable (to store the results of summations)
A[1….n], sum_odd=0, sum_even=0;
2. for (i=1; i<=n; i++)
{
if(i%2==0), sum_even=sum_even+A[i];
else sum_odd=sum_odd+A[i];
}
3. Output: Summation of numbers in odd indices (print sum_odd) and
Summation of numbers in even indices (print sum_even)
C program to find out the summations of even and odd indexed numbers
#include <stdio.h>
int main()
{
int array[100], i, num, sum_of_odd = 0, sum_of_even = 0;
printf("Enter the number of elementsn");
scanf("%d", &num);
printf("Enter the elements n");
for(i=1;i<=num;i++)
{
scanf("%d",&array[i]);
}
for (i = 1; i <= num; i++)
{
if (i % 2 == 0)
sum_of_even = sum_of_even + array[i];
else
sum_of_odd = sum_of_odd + array[i];
9. }
printf("Sum of all odd number indices = %dn", sum_of_odd);
printf("Sum of all even number indices = %dn", sum_of_even);
return 0;
}
Sample Output
Enter the number of elements
5
Enter the elements
1
2
5
8
7
Sum of all odd number indices = 13
Sum of all even number indices = 10
Algorithm to insert an element into an array
1. Input: An array A[1….n], the position of insertion m and the data x.
2. Increase the size of the array, A[1….n+1]
3. for (i=n; i>=m; i--)
A[i+1]=A[i];
4. A[m]=x;
5. Output: The array, A with size n+1
C program to insert an element into an array
#include <stdio.h>
int main()
{
int array[100], position, c, n, value;
10. printf("Enter number of elements in arrayn");
scanf("%d", &n);
printf("Enter %d elementsn", n);
for (c = 1; c <= n; c++)
{
scanf("%d", &array[c]);
}
printf("Enter the location where you wish to insert an
elementn");
scanf("%d", &position);
printf("Enter the value to insertn");
scanf("%d", &value);
for (c = n; c >= position; c--)
{
array[c+1] = array[c];
}
array[position] = value;
printf("Resultant array isn");
for (c = 1; c <= n+1; c++)
{
printf("%dn", array[c]);
}
return 0;
}
Sample Output
Enter number of elements in array
5
Enter 5 elements
11. 1
2
3
7
5
Enter the location where you wish to insert an element
4
Enter the value to insert
0
Resultant array is
1
2
3
0
7
5
Algorithm to delete an element from an array
1. Input: An array A[1….n], the position of deletion m.
2. for (i=m; i<n; i++)
A[i]=A[i+1];
3. Output: The updated array, A
C program to delete an element from an array
#include <stdio.h>
int main()
{
int array[100], position, c, n;
printf("Enter number of elements in arrayn");
scanf("%d", &n);
12. printf("Enter %d elementsn", n);
for ( c = 1 ; c <= n ; c++ )
{
scanf("%d", &array[c]);
}
printf("Enter the location where you wish to delete
elementn");
scanf("%d", &position);
if ( position >= n+1 )
printf("Deletion not possible.n");
else
{
for ( c = position ; c < n ; c++ )
{
array[c] = array[c+1];
}
printf("Resultant array isn");
for( c = 1 ; c < n ; c++ )
printf("%dn", array[c]);
}
return 0;
}
Sample Output
Enter number of elements in array
4
Enter 4 elements
8
9