|
Some tasks to practice arrays in C
|
|
05-21-2010, 03:19 AM
(This post was last modified: 06-18-2010 02:32 AM by drdebcol.)
Post: #1
|
|||
|
|||
|
Some tasks to practice arrays in C
I have a few solved tasks for arrays in programming language C.
Some of them are a bit complicated for beginners, but they are pretty understandable ! So let's start with one-dimensional arrays. 1) Output array in reversed order. (You can not use reverse() function). This is very simple as you can see : Code: #include <stdio.h>2) Input an array of natural numbers (including zero) and output those members of array which sum of digits is bigger than entered number k. As you can see you need to know "mod div" routine or in C "% /" routine. Here is the code : Code: #include <stdio.h>3) Input an array of natural numbers. Output all members of that array if sum of all members before it is bigger than sum of it's digits. (You don't need to count first member of array). Here is the code : Code: #include <stdio.h>And now Matrix of two-dimensional arrays. 4) Input a square matrix of integers. Output members of matrix that are smaller than difference of sum and product of all members of matrix. (Calculate sum and product on input) I know this seems hard, but it is not really. Here is the code : Code: #include <stdio.h>5) Input a square matrix and check if it is symmetrical or not. (Matrix is symmetrical if for every member satisfy that a(i,j)=a(j,i)) So here is the code : Code: #include <stdio.h>That's all. You can post your solutions in other programming languages ! There's a fine line between genius and insanity. I have erased this line. Oscar Levant There's a fine line between an administrator and black hat hacker. I have erased this line. Dr DEBCOL |
|||
|
06-18-2010, 02:36 AM
(This post was last modified: 06-18-2010 02:36 AM by drdebcol.)
Post: #2
|
|||
|
|||
|
RE: Some tasks to practice arrays in C
I want to add one more task to this list of tasks.
You need to enter matix m*n and find how many sub-matrices dimensions 2*2 have the specified sum s. You can see that m and n need to be bigger or equal to 2. Example : m=4, n=4, s=5 1 2 1 4 0 2 3 1 1 0 2 3 1 4 2 0 Number of sub-matrices is : 1 It is sub-matrix (dimensions 2*2) : 1 2 0 2 Here is the code : Code: #include <stdlib.h>There's a fine line between genius and insanity. I have erased this line. Oscar Levant There's a fine line between an administrator and black hat hacker. I have erased this line. Dr DEBCOL |
|||
|
07-28-2010, 06:08 AM
Post: #3
|
|||
|
|||
|
RE: Some tasks to practice arrays in C
Woah. i just re-read this thread. Very useful info, I'm sorry i skipped over this!
"Character is determined more by the lack of certain experiences than by those one has had." Friedrich Nietzsche |
|||
|
07-31-2010, 04:13 PM
Post: #4
|
|||
|
|||
|
RE: Some tasks to practice arrays in C
Nice examples c arrays can be cumbersome for some people sometimes.
|
|||
|
« Next Oldest | Next Newest »
|





