Skip to content
Snippets Groups Projects
Commit 827d20b9 authored by SoC Account's avatar SoC Account
Browse files

more labsheet 2 done

parent ecde9e28
No related branches found
No related tags found
No related merge requests found
File added
File added
/*
Labsheet 2, Task 3
Name: lab2-count-odd-number.c
Input: array of numbers
Output: total number of odd elements
*/
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char*argv[]) {
int size = 10;
/* initialise array with given max size */
int numbers[size];
/* read all the inputs and add to array */
for (int i = 0; i < argc; i++) {
numbers[i] = atoi(argv[i]);
}
int oddCount = 0;
/* loop through all inputs, use modulus to find odds */
for (int i = 0; i < argc; i++) {
if (numbers[i] % 2 == 1) {
oddCount++;
}
}
printf("%d\n", oddCount);
return 0;
}
No preview for this file type
......@@ -22,7 +22,12 @@ int main(int argc, char*argv[])
for (int i = 0; i < (size - 2); i++)
{
printf(" * ");
printf("*");
/* this loop prints the spaces between each * */
for (int j = 0; j < (size - 2); j++) {
printf(" ");
}
printf("*\n");
}
// print bottom line
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment