in pointers
can we use for loop in the function or
we should use the recursion with it
Printable View
in pointers
can we use for loop in the function or
we should use the recursion with it
You can use for loops to increment/decrement pointers and such, for arrays or whatever. What are you asking?
heh, what do u mean????
so far, I can give you some hints, where you can find something about pointers:
www.cprogramming.com (the tutorials)
http://cboard.cprogramming.com/showt...threadid=41754
and search the board ;)
i find the answer
i was mean that
if we writing a function
in pointers
can we use for loop inside
the function or we should use only (if -else)
yeah, why not????
I don't know, what you wanna do, so you have to decide, whether it's better or worse for your prog....
Write a function addElement that takes as parameters: a pointer to a sorted array of integer numbers, array size (number of elements stored in the array), and the number to be inserted in the array. The function should insert the element in the proper position to keep the list sorted. Use pointer operations to access the elements of the array. The function prototype is
void addElement(intt *array, int *sizeptr, int num);
#include <stdio.h>
#define size 10
void addelement(int*,int *,int );
int main()
{
int i,array[10],s,num;
printf ("enter the size\n");
scanf("%d",&s);
printf("enter the array:\n");
for(i=0;i<=s;i++)
scanf("%d",&array[s]);
printf("add a number to the array\n");
addelement(array, &s, num);
return 0;
}
void addelement(int*array,int *sizeptr,int num)
{
int i;
for(i=0; i >=sizeptr ; i++)
printf ("add number");
printf("%d\n%d ",array[size],num);
}
}
i do this program but i cant find the error
Write a function addElement that takes as parameters: a pointer to a sorted array of integer numbers, array size (number of elements stored in the array), and the number to be inserted in the array. The function should insert the element in the proper position to keep the list sorted. Use pointer operations to access the elements of the array. The function prototype is
void addElement(intt *array, int *sizeptr, int num);
#include <stdio.h>
#define size 10
void addelement(int*,int *,int );
int main()
{
int i,array[10],s,num;
printf ("enter the size\n");
scanf("%d",&s);
printf("enter the array:\n");
for(i=0;i<=s;i++)
scanf("%d",&array[s]);
printf("add a number to the array\n");
addelement(array, &s, num);
return 0;
}
void addelement(int*array,int *sizeptr,int num)
{
int i;
for(i=0; i >=sizeptr ; i++)
printf ("add number");
printf("%d\n%d ",array[size],num);
}
}
thanx
It think, this is correct now:
heh, solved ya problem again :DCode:#include <stdio.h>
#define size 10
void addelement(int*,int *,int );
int main()
{
int i,array[10],s,num;
printf ("enter the size\n");
scanf("%d",&s);
printf("enter the array:\n");
for(i=0;i<=s;i++)
scanf("%d",&array[s]);
printf("add a number to the array\n");
addelement(array, &s, num);
return 0;
}
void addelement(int*array,int *sizeptr,int num)
{
int i;
for(i=0; i >=*sizeptr ; i++)
printf ("add number");
printf("%d\n%d ",array[size],num);
}
I haven't had compiled it.... I found 2 mistakes.
[edit]
Plz check it, whether it compiles and runs corrently and whether it does, what you want it to do for you
[/edit]
the program run
but
in the end
it doesnt
type the number i add
it gives
the position
of num
Originally posted by itcs
the program run
but
in the end
it doesnt
type the number i add
it gives
the position
of num
Burma Shave!
Sorry, couldn't resist
still not run
as i want
can u
write
all the
program
plz
may be i didnt understand u
Most of it has been written for you already. try piecing it all together, and then askng specific questions when you need help.Quote:
Originally posted by itcs
still not run
as i want
can u
write
all the
program
plz
may be i didnt understand u
[edit]
Doh, beat!
u help me sooooooooooo
much all of u
I promise to post it on tuseday
because i think
i can answer it now
see u then
thank salem &mastercode
????? mastercode ??????
:mad: :mad: :mad: :mad:
I'm codingmaster
i didnt mean 2 heart u r feeling
coodingmaster