



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




int main ( ) { int student1, student2, student3, student4; int quiz1, quiz2, quiz3, quiz4; int exam1, exam2, exam3, exam4; double avg1, avg2, avg3, avg4; printf(āEnter student #1 id, quiz, and exam score\nā); scanf(ā%d%d%d\nā, &student1, &quiz1, &exam1); avg1 = (quiz1+exam1)/200; printf(āStudent #1 average is %d\nā, avg1); printf(āEnter student #2 id, quiz, and exam score\nā); scanf(ā%d%d%d\nā, &student2, &quiz2, &exam2); avg2 = (quiz2+exam2)/200; printf(āStudent #2 average is %d\nā, avg2); printf(āEnter student #3 id, quiz, and exam score\nā); scanf(ā%d%d%d\nā, &student3, &quiz3, &exam3); avg3 = (quiz3+exam3)/200; printf(āStudent #3 average is %d\nā, avg3); printf(āEnter student #4 id, quiz, and exam score\nā); scanf(ā%d%d%d\nā, &student4, &quiz4, &exam4); avg4 = (quiz4+exam4)/200; printf(āStudent #4 average is %d\nā, avg4); }
int main ( ) { int student[3]; /* declare arrays to hold data. each array has 4 cells */ int quiz[3]; int exam[3]; int avg[3]; for (int i = 0; i <= 3; i++) { printf(āEnter student #%d id, quiz, and exam score\nā, i); scanf(ā%d%d%d\nā, &student[i], &quiz[i], &exam[i]); avg[i] = (quiz[i]+exam[i])/200; printf(āStudent #%d average is %d\nā, i, avg[i]); }
//Problem: You are given an array named numbers , indexed from //0 to 99. You are to reverse the contents of the array. The //following solution DOES NOT WORK! WHY? int index, temp, numbers[100]; for (index = 0; index < 99; index++) { temp = numbers[index]; numbers[index] = numbers[99-index]; numbers[99-index] = temp; } //Problem: You are given an array named numbers , indexed from //0 to 99. You are to reverse the contents of the array. int index, temp, numbers[100]; for (index = 0; index < 99/2; index++) { temp = numbers[index]; numbers[index] = numbers[99-index]; numbers[99-index] = temp; }
//The function int sum (int a[ ], int n) { int j, s = 0; for (j = 0; j < n; j++) s = s+ a[j]; return s; } Calling the function (assume we have: int total, x[100]). total = sum(x, 100); total = sum(x, 80); total = sum(&x[5], 50);
int find (int big_array[ ], int size, int value) { int found = 0; loc = 0; while (!found && loc < size) { if (big_array[loc] >= value) { found = 1; return loc; } else loc = loc + 1; } if (found && big_array[loc] != value) found = 0; return found; }