C coding

Go4Expert Member
22Sep2006,11:11   #1
sakthi.eeswari's Avatar
Hi,
I need the coding to add 10 numbers using function and array and by not using pointers.whethet it is possible to add the numbers without using pointers.i need a clear idea about array and functions.If any one knows plaz help me.
-Sakthi
Go4Expert Founder
22Sep2006,12:08   #2
shabbir's Avatar
Simple
Code: C
int add(int arr[10])
{
    int res = 0;
    for(int i=0;i<10;i++)
        res += arr[i];
    return res;
}

int main()
{   
    int arr[10] = {1,2,3,4,5,6,7,8,9,10};
    int x = add(arr);
    return 0;
}
Go4Expert Member
22Sep2006,15:14   #3
sakthi.eeswari's Avatar
Hi,

I need the coding without specifying the array size directly.that is u gave the array size as 10 na,for that we have to get the number from the user.
-Sakthi
Go4Expert Founder
25Sep2006,10:37   #4
shabbir's Avatar
No problem juts use the pointer instead of aaray and use malloc to allocate the pointer and use like an array.
Go4Expert Member
25Sep2006,15:15   #5
sakthi.eeswari's Avatar
Hi,

Thanks for replying the previous program.I need a C coding for another program
for finding the inverse of the matrix,sorting of the matrix,without using the pointers only by using the array.Please help me.
-Sakthi
Go4Expert Founder
25Sep2006,16:23   #6
shabbir's Avatar
Please try to put it as a different thread as that will help even others to find the things easier.
Go4Expert Member
27Dec2006,17:01   #7
sakthi.eeswari's Avatar
hi

i have one doubt regarding Strings.for reading the input from the keyboard we are using & for all other data type xcept string.can i know the reason y we are not using & for string in the scanf function.

Sakthi
Team Leader
27Dec2006,17:19   #8
pradeep's Avatar
I didn't really get your question, kindly explain!
Team Leader
27Dec2006,23:11   #9
DaWei's Avatar
Scanf needs a pointer to the variable. Consequently, the "address-of" operator (&) is applied to the name of the variable. A C-string is not a single "thing", but a collection of such things (chars). The name of the array is treated as a pointer to its first element. Since it's already a pointer, the address-of operator is not required.

As Shabbir mentions, please put separate questions in separate threads. It's a matter of organization and promotes searchability.

Last edited by DaWei; 27Dec2006 at 23:13..
Team Leader
28Dec2006,10:43   #10
pradeep's Avatar
LOL! I took shakthi's '&' in the post for a literal AND and not the address-of operator!