Python provides numerous built-in functions that are readily available to us at the Python prompt. Some of the functions like input() and print() are widely used for standard input and output operations respectively.
Dictionary in Python is an unordered collection of data values, used to store data values like a map, which unlike other Data Types that hold only single value as an element, Dictionary holds key:value pair. Key value is provided in the dictionary to make it more optimized. Each key-value pair in a Dictionary is separated by a colon :, whereas each key is separated by a ‘comma’.
A Dictionary in Python works similar to the Dictionary in a real world. Keys of a Dictionary must be unique and of immutable data type such as Strings, Integers and tuples, but the key-values can be repeated and be of any type.
Programming Fundamentals Arrays and Strings imtiazalijoono
Programming Fundamentals
Arrays and Strings
• Arrays
• Initializing arrays
• Multidimensional arrays
• Arrays as arguments to functions
• Strings
• String functions
Accessing Individual Components
Declaring Arrays
Arrays: Example Garbage
Multidimensional Arrays
1) Write a C program using arrays that produces the multiplication of two 2x2 matrices.
3-Dimensional Array
Write a program of your own choice that makes use of arrays of more than 2 dimensions.
2-Dimensional Arrays
Python provides numerous built-in functions that are readily available to us at the Python prompt. Some of the functions like input() and print() are widely used for standard input and output operations respectively.
Dictionary in Python is an unordered collection of data values, used to store data values like a map, which unlike other Data Types that hold only single value as an element, Dictionary holds key:value pair. Key value is provided in the dictionary to make it more optimized. Each key-value pair in a Dictionary is separated by a colon :, whereas each key is separated by a ‘comma’.
A Dictionary in Python works similar to the Dictionary in a real world. Keys of a Dictionary must be unique and of immutable data type such as Strings, Integers and tuples, but the key-values can be repeated and be of any type.
Programming Fundamentals Arrays and Strings imtiazalijoono
Programming Fundamentals
Arrays and Strings
• Arrays
• Initializing arrays
• Multidimensional arrays
• Arrays as arguments to functions
• Strings
• String functions
Accessing Individual Components
Declaring Arrays
Arrays: Example Garbage
Multidimensional Arrays
1) Write a C program using arrays that produces the multiplication of two 2x2 matrices.
3-Dimensional Array
Write a program of your own choice that makes use of arrays of more than 2 dimensions.
2-Dimensional Arrays
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
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.
An array is a group of similar elements or data items of the same type collected at contiguous memory locations. In simple words, we can say that in computer programming, arrays are generally used to organize the same type of data.
Array for Integral value:
Array for Integral value
Array for Character value:
Array for Character value
Representation of an Array:
Arrays can be represented in several ways, depending on the different languages. To make you understand, we can take one example of the C language. The picture below shows the representation of the array.
Representation of the array
Arrays always store the same type of values. In the above example:
int is a type of data value.
Data items stored in an array are known as elements.
The location or placing of each element has an index value.
Important: Array can store only the same type of data items. From the below example you can see how it works:
Array work image
In the array a, we have stored all integral values (same type)
In the array b, we have stored all char values (same type)
In the array c, there is integral, float, char all types of values and this is not something an array can store so, option 3 is wrong because an array cannot store different types of values.
Declaration Syntax of Array:
VariableType VariableName[Sequence of Elements];
Example 1: For integral value
int A[10];
Here 10 means, this array A can have 10 integer elements.
2 5 8 44 21 11 7 9 3 1
Example 2: For character value
char B[10];
This array B can have 10 character elements.
f d a b n j l s e y
Initialization of an Array:
If an array is described inside a function, the elements will have garbage value. And in case an array is static or global, its elements will be initialized automatically to 0.
We can say that we can simply initialize elements of an array at the time of declaration and for that, we have to use the proper syntax:
Syntax: datatype Array_Name[size] = { value1, value2, value3, ….. valueN };
Types of Arrays:
There are two types of arrays:
One-Dimensional Arrays
Multi-Dimensional Arrays
One -Dimensional Arrays
A one-dimensional array is a kind of linear array. It involves single sub-scripting. The [] (brackets) is used for the subscript of the array and to declare and access the elements from the array.
Syntax: DataType ArrayName [size];
For example: int a[10];
Multi-Dimensional Arrays
In multi-dimensional arrays, we have two categories:
Two-Dimensional Arrays
Three-Dimensional Arrays
1. Two-Dimensional Arrays
An array involving two subscripts [] [] is known as a two-dimensional array. They are also known as the array of the array. Two-dimensional arrays are divided into rows and columns and are able to handle the data of the table.
Syntax: DataType ArrayName[row_size][column_size];
For Example: int arr[5][5];
2. Three-Dimensional Arrays
When we require to create two or more tables of the elements to declare the array elements, then in such a situation we use three-di
We have compiled the most important slides from each speaker's presentation. This year’s compilation, available for free, captures the key insights and contributions shared during the DfMAy 2024 conference.
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)MdTanvirMahtab2
This presentation is about the working procedure of Shahjalal Fertilizer Company Limited (SFCL). A Govt. owned Company of Bangladesh Chemical Industries Corporation under Ministry of Industries.
Saudi Arabia stands as a titan in the global energy landscape, renowned for its abundant oil and gas resources. It's the largest exporter of petroleum and holds some of the world's most significant reserves. Let's delve into the top 10 oil and gas projects shaping Saudi Arabia's energy future in 2024.
Understanding Inductive Bias in Machine LearningSUTEJAS
This presentation explores the concept of inductive bias in machine learning. It explains how algorithms come with built-in assumptions and preferences that guide the learning process. You'll learn about the different types of inductive bias and how they can impact the performance and generalizability of machine learning models.
The presentation also covers the positive and negative aspects of inductive bias, along with strategies for mitigating potential drawbacks. We'll explore examples of how bias manifests in algorithms like neural networks and decision trees.
By understanding inductive bias, you can gain valuable insights into how machine learning models work and make informed decisions when building and deploying them.
Student information management system project report ii.pdfKamal Acharya
Our project explains about the student management. This project mainly explains the various actions related to student details. This project shows some ease in adding, editing and deleting the student details. It also provides a less time consuming process for viewing, adding, editing and deleting the marks of the students.
6th International Conference on Machine Learning & Applications (CMLA 2024)ClaraZara1
6th International Conference on Machine Learning & Applications (CMLA 2024) will provide an excellent international forum for sharing knowledge and results in theory, methodology and applications of on Machine Learning & Applications.
Cosmetic shop management system project report.pdfKamal Acharya
Buying new cosmetic products is difficult. It can even be scary for those who have sensitive skin and are prone to skin trouble. The information needed to alleviate this problem is on the back of each product, but it's thought to interpret those ingredient lists unless you have a background in chemistry.
Instead of buying and hoping for the best, we can use data science to help us predict which products may be good fits for us. It includes various function programs to do the above mentioned tasks.
Data file handling has been effectively used in the program.
The automated cosmetic shop management system should deal with the automation of general workflow and administration process of the shop. The main processes of the system focus on customer's request where the system is able to search the most appropriate products and deliver it to the customers. It should help the employees to quickly identify the list of cosmetic product that have reached the minimum quantity and also keep a track of expired date for each cosmetic product. It should help the employees to find the rack number in which the product is placed.It is also Faster and more efficient way.
2. An array is a collection of data that holds
fixed number of values of same type. float
marks[100].
The size and type of arrays cannot be
changed after its declaration.
Arrays are of two types:
One-dimensional rrays
Multidimensional Arrays
3. data_type array_name[array_size]; For
example,
float mark[5];Here, we declared an
array, mark, of floating-point type and size
5. Meaning, it can hold 5 floating-point
values.
4. You can access elements of an array by indices.
Few key notes:
Arrays have 0 as the first index not 1. In this
example, mark[0]
If the size of an array is n, to access the last
element, (n-1) index is used. In this
example, mark[4]
Suppose the starting address of mark[0] is 2120d.
Then, the next address, a[1], will be 2124d, address
of a[2] will be 2128d and so on. It's because the size
of a float is 4 bytes.
5. It's possible to initialize an array during
declaration. For example,
int mark[5] = {19, 10, 8, 17, 9};
OR
int mark[] = {19, 10, 8, 17, 9};
6.
7. // Program to find the average of n (n < 10) numbers using arrays
#include <stdio.h>
int main()
{ int marks[10], i, n, sum = 0, average;
printf("Enter n: ");
scanf("%d", &n);
for(i=0; i<n; ++i)
{ printf("Enter number%d: ",i+1);
scanf("%d", &marks[i]);
sum += marks[i]; }
average = sum/n;
printf("Average = %d", average);
return 0;
}
8. Enter n: 5
Enter number1: 45
Enter number2: 35
Enter number3: 38
Enter number4: 31
Enter number5: 49
Average = 39
9. In C programming, a single array element or
an entire array can be passed to a function.
This can be done for both one-dimensional
array or a multi-dimensional array.
11. While passing arrays as arguments to the
function, only the name of the array is
passed (,i.e, starting address of memory area
is passed as argument).
12. #include <stdio.h>
float average(float age[]);
main()
{ float avg, age[] = { 23.4, 55, 22.6, 3, 40.5, 18 };
avg = average(age); /* Only name of array is passed
as argument. */
printf("Average age=%.2f", avg); }
float average(float age[])
{ int i;
float avg, sum = 0.0;
for (i = 0; i < 6; ++i) {
sum += age[i]; }
avg = (sum / 6);
return avg;
}
13. void displayNumbers(int num[2][2]);
main()
{ int num[2][2], i, j;
printf("Enter 4 numbers:n");
for (i = 0; i < 2; ++i)
for (j = 0; j < 2; ++j)
scanf("%d", &num[i][j]);
// passing multi-dimensional array to displayNumbers function
displayNumbers(num); }
void displayNumbers(int num[2][2])
{ int i, j;
printf("Displaying:n");
for (i = 0; i < 2; ++i)
for (j = 0; j < 2; ++j)
printf("%dn", num[i][j]);
}
14. main()
{
int mat[4][4],trans[4][4],row,col;
printf("enter elements od an array");
filling Matrix
for(row=0;row<4;row++)
for(col=0;col<4;col++)
scanf("%d",&mat[row][col]);
Converting rows into cols
for(row=0;row<4;row++)
for(col=0;col<4;col++)
trans[col][row]=mat[row][col];
16. In C programming, array of characters is
called a string. A string is terminated by a
null character /0. For example:
char greeting[6] = {'H', 'e', 'l', 'l', 'o', '0'}; OR
char greeting[] = "Hello";
When, compiler encounter strings, it appends
a null character /0 at the end of string.
17. Using arrays
char c[] = "abcd";
OR
char c[50] = "abcd";
OR,
char c[] = {'a', 'b', 'c', 'd', '0'};
OR,
char c[5] = {'a', 'b', 'c', 'd', '0'};
The given string is initialized and stored in
the form of arrays as above.
18. Write a C program to illustrate how to read string from terminal.
#include <stdio.h>
int main()
{
char name[20];
printf("Enter name: ");
scanf("%s", name);
printf("Your name is %s.", name);
return 0;
}
Output
Enter name: Dennis Ritchie
Your name is Dennis.
Here, program ignores Ritchie because, scanf() function takes
only a single string before the white space, i.e. Dennis.
19. Example #2: Using getchar() to read a line of text
1. C program to read line of text character by character.
#include <stdio.h>
int main()
{ char name[30], ch;
int i = 0;
printf("Enter name: ");
while(ch != 'n') // terminates if user hit enter
{ ch = getchar();
name[i] = ch;
i++;
}
name[i] = '0'; // inserting null character at end
printf("Name: %s", name);
return 0;
}
20. #include <stdio.h>
int main()
{ char name[30];
printf("Enter name: ");
gets(name); //Function to read string from user.
printf("Name: ");
puts(name); //Function to display string.
return 0;}
Output
Enter name: Dennis Ritchie
Name: Dennis Ritchie
21. Sr.No. Function & Purpose
1 strcpy(s1, s2);
Copies string s2 into string s1.
2 strcat(s1, s2);
Concatenates string s2 onto the end of string s1.
3 strlen(s1);
Returns the length of string s1.
4 strcmp(s1, s2);
Returns 0 if s1 and s2 are the same; less than 0 if s1<s2; greater than 0 if
s1>s2.
5 strchr(s1, ch);
Returns a pointer to the first occurrence of character ch in string s1.
6 strstr(s1, s2);
Returns a pointer to the first occurrence of string s2 in string s1.
22. #include <string.h>
int main () {
char str1[12] = "Hello";
char str2[12] = "World";
char str3[12];
int len ;
/* copy str1 into str3 */
strcpy(str3, str1);
printf("strcpy( str3, str1) : %sn", str3 );
/* concatenates str1 and str2 */
strcat( str1, str2);
printf("strcat( str1, str2): %sn", str1 );
/* total lenghth of str1 after concatenation */
len = strlen(str1);
printf("strlen(str1) : %dn", len );
return 0;