hw5 - int main(void int A[10 ={1,2,3,4,5,6,7,8,9,10 int...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
55b4e816b5c607fc63807a54395de17e541ee1d2.doc Page 1 of 2 COS120 Software Development Using C++ Student: Homework Nmr 05 (Arrarys/strings) Tasks: Task 1 : Write a program to multiply two one-dimensional arrays (vectors) with size of n . Result to be saved in third one-dimensional array (vector) C[k] = A[k] * B[k], k is integer subscript in the range 0…n–1 Implement a function with three parameters for the arrays and one parameter for the same size of all the three arrays. Task 2 : Write a program to demonstrate reverse of string operator. Implement a function to reverse a string: void reverse(char par[]);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
55b4e816b5c607fc63807a54395de17e541ee1d2.doc Page 2 of 2 Task 1 # include <iostream> # include <iomanip> using namespace std; void mul(int *, int *, int *, int );
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: int main (void) { int A[10] = {1,2,3,4,5,6,7,8,9,10}; int B[10] = {11,12,13,14,15,16,17,18,19,20}; int C[10]; mul(A,B,C,10); for(int i=0; i<10; i++) cout << setw(2) << A[i] << setw(2) << "*" << setw(2) << B[i] << setw(2) << "=" << setw(4) << C[i] << endl; return 0; } void mul (int a, int b, int c, int n) { for (int i=0; i<n; i++) c[i] = a[i]*b[i]; } Task 2 # include <iostream> # include <string.h> using namespace std; void reverse(char *); int main (void) { char a = "American University in Bulgaria"; reverse(a); int i = 0; while(a[i]!='\0') { cout << a[i]; i++; } } void reverse(char par) { int begin = 0; int end = strlen(par) - 1; while (begin < end) swap(par[begin++], par[end--]); }...
View Full Document

This note was uploaded on 04/24/2010 for the course COS 120 taught by Professor Bonev during the Fall '08 term at American University in Bulgaria.

Page1 / 2

hw5 - int main(void int A[10 ={1,2,3,4,5,6,7,8,9,10 int...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online