More Questions 1) Write a C program to read a matrix A of size nXn and two arrays X and Y of size n and calculate XA-Y?

Slides:



Advertisements
Similar presentations
What is shape function ? shape function is a function that will give the displacements inside an element if its displacement at all the node locations.
Advertisements

Sort the given string, without using string handling functions.
Operations on Arrays. Operation on Array Data Structures  Traversal  Selection  Searching  Insertion  Deletion  Sorting.
CMPE 150: Introduction to Computing Arrays. TT - Spring'08CMPE150: Introduction to Computing1 Motivation You may need to define many variables of the.
Strings A special kind of array is an array of characters ending in the null character \0 called string arrays A string is declared as an array of characters.
Introduction of Arrays. Arrays Array form an important part of almost all programming language. It provides a powerful feature and can be used as such.
UNIT-4. Searching Methods:  Linear Search  Binary Search Sorting Techniques:  Bubble Sort  Selection Sort  Insertion Sort  Quick Sort  Merge Sort.
Advance Use of Structures CHAPTER 5. C.10 1 Using Structures with Functions » A function can return only one value back. » Some of the processes may yield.
EENG212 Algorithms and Data Structures
Array.
MAHENDRAN CHAPTER 6. Session Objectives Explain Type of Functions Discuss category of Functions Declaration & Prototypes Explain User Defined Functions.
POINTERS. 1.a) POINTER EXPRESSIONS Pointer variables can be used in expression If p1 and p2 are properly declared and initialized pointers then following.
SNPL1 GAUSS ELIMINATION & BACK SUBSTITUTION GAUSS ELIMINATION & BACK SUBSTITUTION Dayun Yu Seungmuk Ji.
Computer programming Lecture 5. Lecture 5: Outline Arrays [chap 7 – Kochan] –The concept of array –Defining arrays –Initializing arrays –Character arrays.
Write a C program to pass an array containing age of person to a function. This function should find average age and display the average age in main function.
Topics to be covered  Introduction to array Introduction to array  Types of array Types of array  One dimensional array One dimensional array  Declaration.
PRESENTATION ON SEARCHING SEARCHING Searching is the method to find element from the list of the elements. If element is found then it.
1 nd Semester Module7 Arrays Thanawin Rakthanmanon Create by: Aphirak Jansang Computer Engineering Department Kasetsart.
Arrays  Array is a collection of same type elements under the same variable identifier referenced by index number.  Arrays are widely used within programming.
Arrays in C.
מערכים (arrays) 02 דצמבר דצמבר דצמבר 1502 דצמבר דצמבר דצמבר 1502 דצמבר דצמבר דצמבר 15 1 Department of Computer Science-BGU.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee C Language Part 3.
Passing Structure to function.  structure to function structure to function  Passing structure to function in C Passing structure to function in C 
Chinese Proverb says……... Advantages void main( ) { int n, k, i ; printf(“\n Enter number:-”); scanf(“%d”, &n); for(i=2 ; i
Decision Making It is used to change the order of the program based on condition. Categories: – Sequential structure – Selection structure – Iteration.
CS1010E Programming Methodology Tutorial 9 Pointers in Arrays & Structures C14,A15,D11,C08,C11,A02.
Functions: Part 2 of /11/10: Lecture 16 CMSC 104, Section 0101 John Y. Park 1.
Computer programming Outline Arrays [chap 7 – Kochan] –The concept of array –Defining arrays –Initializing arrays –Character.
Structured Programming Approach Module VIII - Additional C Data Types Arrays Prof: Muhammed Salman Shamsi.
1 Arrays 1090CS, Computer Programming 1 Manesh T
CCSA 221 Programming in C CHAPTER 7 WORKING WITH ARRAYS 1.
Strings program. C Program to Check if a given String is Palindrome #include void main() { char string[25], reverse_string[25] = {'\0'}; int i, length.
Strings program. C Program to Check if a given String is Palindrome #include void main() { char string[25], reverse_string[25] = {'\0'}; int i, length.
Rray Programs. Insert and element in the given position of the Array rray.
UNIT-4 1. Arrays: Definition and declaration, Initialization, Accessing elements of arrays, Storing values in arrays, Inter-function Communication: Passing.
Selection Sort main( ) { int a[ ] = { 17, 6, 13,12, 2 } ; int i, j, t ; for ( i = 0 ; i
Write a C program to pass an array containing age of person to a function. This function should find average age and display the average age in main function.
Pointers A pointer is a variable which stores the address of another variable A pointer is a derived data type in C which is constructed from fundamental.
C A RRAY Continue one dimensional array 1. Assume we have define this array: int hourlyTemp[ 24 ]; And we need to insert this array as parameter into.
Review (before the 1 st test): while (conditions) { statements; } while loop: if/else if/else statements: if (conditions) { statements; } else if (different.
8. ARRAYS. Aggregate variables Scalar variables –Single value Aggregate variables –Collection of values –Arrays: elements have the same type.
Introduction Arrays –Structures of related data items –Static entity - same size throughout program A few types –C-like, pointer-based arrays –C++, arrays.
POINTERS IN C Pointer Basics, Pointer Arithmetic, Pointer to arrays and Pointer in functions.
Array Sort. Sort Pass 1 Sort Pass 2 Sort Pass 3.
UNIT - 3 ARRAYS AND STRINGS. Array An Array is a collection of similar data items, that are stored under a common name. Types –One-Dimensional array –Two-Dimensional.
Lecture #15 ARRAYS By Shahid Naseem (Lecturer). 2 ARRAYS DEFINITION An array is a sequence of objects of same data type. The objects in an array are also.
Functions The fruitful & parameterized functions.
CSC COMPUTER EDUCATION, M.K.B.NAGAR CHAPTER 3. CSC COMPUTER EDUCATION, M.K.B.NAGAR Session Objectives Explain If, If..else statements Understand Looping.
Explain Declaration,Initialization of Array Explain Types of Array One Dimensional,Two Dimensional and Multi Dimensional Array Explain Arrays.
MAHENDRAN. Session Objectives Explain Declaration,Initialization of Array Explain Types of Array One Dimensional,Two Dimensional and Multi Dimensional.
UNIT - 5 FUNCTIONS AND POINTERS. FUNCTION Functions is a sub-program that contains one or more statements and it performs some task when called.
Chapter 2 Array and String. Array Definition of Array : An array is a sequence or collection of the related data items that share a common name. Purpose.
מערכים (arrays) 02 אוקטובר אוקטובר אוקטובר 1602 אוקטובר אוקטובר אוקטובר 1602 אוקטובר אוקטובר אוקטובר 16 Department.
WHILE, DO-WHILE AND FOR LOOPS
Advance Use of Structures
Lecture 7 Arrays 1. Concept of arrays Array and pointers
Array 9/8/2018.
ARRAYS An array is a sequence of data item of homogeneous value(same type). Arrays are of two types: 1. One-dimensional arrays 2. Multi-Dimensional arrays.
CHAPTER 7 RECURSIVE FUNCTION
Chapter 5 POINTERs.
Arrays.
Shaker.
Recursion Prog #include <stdio.h> #include<conio.h> main()
Chapter 2 Array and String Visit to more Learning Resources.
UNIT - 3 Noornilo Nafees.
To refer to an element, specify
UNIT – IV Searching – Linear search - binary search Sorting
Character Arrays char string1[] = “first”;
Chapter 5 POINTERs Visit to more Learning Resources.
Visit for more Learning Resources
Presentation transcript:

More Questions 1) Write a C program to read a matrix A of size nXn and two arrays X and Y of size n and calculate XA-Y?

More Questions #include void main() { int a[10][10],x[10],y[10],i,j,r,c,R[10][10],k; clrscr(); printf("enter order of the mat :- "); scanf("%d%d",&r,&c); if(r==c) { printf("enter matrix"); for(i=0;i<r;i++) { for(j=0;j<c;j++) { scanf("%d",&a[i][j]); }

More Questions printf("given matrix\n"); for(i=0;i<r;i++) { for(j=0;j<c;j++) { printf("%d ",a[i][j]); } printf("\n"); } printf("Enter first array :- "); for(i=0;i<r;i++) { scanf("%d",&x[i]); } printf("Enter second array :- "); for(i=0;i<r;i++) { scanf("%d",&y[i]); }

More Questions //calculating X*A for(i=0;i<1;i++) { for(j=0;j<c;j++) { R[i][j]=0; for(k=0;k<r;k++) { R[i][j]=R[i][j]+x[k]*a[k][j]; } //calculation of X*A - Y for(i=0;i<1;i++) { for(j=0;j<c;j++) { R[i][j]=R[i][j]-y[j]; }

More Questions printf(“\nresultant matrix “); for(i=0;i<1;i++) { for(j=0;j<c;j++) { printf("%d ",R[i][j]); } printf("\n"); } else {printf(“Not a square matrix”);} getch(); }

More Questions 2) Write a function that receives a sorted array of integers and an integer value and insert the integer value in its correct place in the sorted array

More Questions #include void main() { void array(int [],int,int ); int a[10],i,j,t,n,no; clrscr(); printf("Enter limit "); scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d",&a[i]); } printf("given array :- "); for(i=0;i<n;i++) { printf("%d ",a[i]); }

More Questions //sorting for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { if(a[i]>a[j]) { t=a[i]; a[i]=a[j]; a[j]=t; } printf("\nsorted array "); for(i=0;i<n;i++) { printf("%d ",a[i]); } printf("\nEnter a no to insert"); scanf("%d",&no); //passing sorted array to function array(a,n,no); getch(); }

More Questions void array(int a[10],int n,int no) { int i,pos=0; //finding the position to insert for(i=0;i<n;i++) { if(no>=a[i]) { pos=i; } pos=pos+1;

More Questions //inserting for(i=n;i>pos;i--) { a[i]=a[i-1]; } a[pos]=no; printf("\nnew inserted array "); for(i=0;i<=n;i++) { printf("%d ",a[i]); }

More Questions 3) Write a C program to read an array of size n and calculate its standard deviation given by √∑(xi-x) 2 /n

More Questions #include void main() { int a[10],i,n,x,s=0; float sd; clrscr(); printf("enter limit "); scanf("%d",&n); printf("Enter array "); for(i=0;i<n;i++) { scanf("%d",&a[i]); } printf("given array :- "); for(i=0;i<n;i++) { printf("%d ",a[i]); s=s+a[i]; } x=s/n; s=0; for(i=0;i<n;i++) { s=s+pow((a[i]-x),2); } sd=sqrt(s/n); printf("\nSD=%f",sd); getch(); }

More Questions 4) Write a C program to read a data stored in a file. Find the value of ∑(xi 2 /n) –∑(xi/n) 2 and write it in another file

More Questions #include void main() { int a[10],i,n,no,s=0,k=0; float z; FILE *fp,*fp2; clrscr(); fp=fopen("num.txt","w"); printf("Enter limit "); scanf("%d",&n); for(i=1;i<=n;i++) { printf("enter a no "); scanf("%d",&no); putw(no,fp); } fclose(fp);

More Questions fp=fopen("num.txt","r"); for(i=0;i<n;i++) { a[i]=getw(fp); } fclose(fp); printf("content of the array "); for(i=0;i<n;i++) { printf("%d ",a[i]); s=s+pow(a[i],2); k=k+a[i]; } z=(s/n)-pow((k/n),2); printf("\nresult= %f",z); fp2=fopen("second.txt","w"); fprintf(fp2,"%f",z); fclose(fp2); getch(); }

Find biggest word in the given sentences

17 Find biggest word in the given sentences #include main() { int i=0,ss=0,big=0; char s[100],c,temp[50],bigstr[50]; clrscr(); printf("enter a text "); gets(s); printf("GIven string : %s\n",s); 1

18 Find biggest word in the given sentences for(i=0;s[i]!='\0';i++) { if(s[i]==' ') { temp[ss]='\0'; //printf(" %s %d\n",temp,ss); if(ss>big) { big=ss; strcpy(bigstr,temp); } ss=0; } else { temp[ss]=s[i]; ss++; //printf("%c",s[i]); } 2

19 Find biggest word in the given sentences temp[ss]='\0'; //printf("%s %d",temp,ss); if(ss>big) { big=ss; strcpy(bigstr,temp); } printf("\n Big string %s",bigstr); printf("\n Biggest string length %d",big); getch(); } 3

Search the given sub string pattern in the main string

More Questions #include void main() { char str[20],sub[20],temp[20][20]; int i,j,n=0,k,l,f=1; clrscr(); printf("enter main string"); gets(str); printf("sub string "); gets(sub); for(i=0;str[i]!='\0';i++) { l=i;k=0; for(j=0;sub[j]!='\0';j++) { temp[n][k]=str[l]; k++;l++; } temp[n][k]='\0'; n++; }

More Questions for(i=0;i<strlen(str)-strlen(sub)+1;i++) { //printf("\n%s",temp[i]); if(strcmp(temp[i],sub)==0) { printf("\npattern found"); f=0; } if(f==1) { printf("\npattern not found"); } getch(); }