5.2. 최지혁 ¶
#include<stdio.h> int sum_array (int*arr,int a) { int sum = 0; for (int i = 0; i < a; i++) sum += arr[i]; return sum; } int main() { int a = 10; int arr[10] = {1,1,1,1,1,1,1,1,1,1}; printf("%d", sum_array(arr, a)); return 0; }
#include<stdio.h> void func(char* arr[]) { int num = 0; while (num < 5) { printf("%c\n", *arr[num]); num++; } } int main() { char * arr[5]; char cha1 = 'a'; char cha2 = 'b'; char cha3 = 'c'; char cha4 = 'd'; char cha5 = 'e'; arr[0] = &cha1; arr[1] = &cha2; arr[2] = &cha3; arr[3] = &cha4; arr[4] = &cha5; func(&arr); return 0; }
5.3.1. 숙제 1 ¶
#include<stdio.h> int show(int * p, int n){ int sum=0,i; for (i = 0; i < n; i++){ sum += p[i]; } return sum; } int main(){ int a[6] = { 1, 2, 3, 4, 5, 6 }; printf("%d", show(a, 6)); return 0; }
5.3.2. 숙제 2 ¶
#include <stdio.h> void func(char * p[]) { int i; for(i=0;i<5;i++) printf("%c ",*p[i]); } int main() { char * p[5]; char a='1',b='2',c='3',d='4',e='5'; p[0]=&a; p[1]=&b; p[2]=&c; p[3]=&d; p[4]=&e; func(&p); return 0; }
5.5.1. 숙제1 ¶
#include<stdio.h> void show(int *brr, int n){ int num=0; for (int i = 0; i < n; i++){ num += brr[i]; } printf("%d ", num); } int main(){ int a = 6; int arr[6] = { 1, 2, 3, 4, 5, 6 }; show(arr, 6); return 0; }
5.5.2. 숙제2 ¶
#include<stdio.h> void show(char **brr){ for (int i = 0; i < 5; i++){ printf("%c\n", *brr[i]); } } void main(){ char a = 'a'; char b = 'b'; char c = 'c'; char d = 'd'; char e = 'e'; char *arr[5] = {&a, &b, &c, &d, &e}; show(&arr); }