Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   C coding (http://www.go4expert.com/forums/c-coding-t1454/)

sakthi.eeswari 22Sep2006 11:11

C coding
 
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

shabbir 22Sep2006 12:08

Re: C coding
 
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;
}


sakthi.eeswari 22Sep2006 15:14

Re: C coding
 
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

shabbir 25Sep2006 10:37

Re: C coding
 
No problem juts use the pointer instead of aaray and use malloc to allocate the pointer and use like an array.

sakthi.eeswari 25Sep2006 15:15

C coding
 
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

shabbir 25Sep2006 16:23

Re: C coding
 
Please try to put it as a different thread as that will help even others to find the things easier.

sakthi.eeswari 27Dec2006 17:01

Re: C coding
 
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

pradeep 27Dec2006 17:19

Re: C coding
 
I didn't really get your question, kindly explain!

DaWei 27Dec2006 23:11

Re: C coding
 
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.

pradeep 28Dec2006 10:43

Re: C coding
 
LOL! I took shakthi's '&' in the post for a literal AND and not the address-of operator!


All times are GMT +5.5. The time now is 18:42.