sounds like you need to go back to MS DOS. representing a mathematical calculation like that in integer format will take up the whole screen. Otherwise start using powers and forget the writing of the program: use a calculator.
Write a c program to multiply a 50 digit number with a 4 digit number using array?
I am not in the habit of actually writing out solutions to what appears like homework, something like this isn't too hard. A couple arrays, a few loops and you can do it quite easily. Experiment.
Reply:Just do it in Python!
Monday, May 24, 2010
Using C++ what is the easiest way to write a recursive function to sort an array in ascending order?
I just googled for it and there's a recursive merge sort here.
void mergeSort(int numbers[], int temp[], int array_size)
{
m_sort(numbers, temp, 0, array_size - 1);
}
void m_sort(int numbers[], int temp[], int left, int right)
{
int mid;
if (right %26gt; left)
{
mid = (right + left) / 2;
m_sort(numbers, temp, left, mid);
m_sort(numbers, temp, mid+1, right);
merge(numbers, temp, left, mid+1, right);
}
}
void merge(int numbers[], int temp[], int left, int mid, int right)
{
int i, left_end, num_elements, tmp_pos;
left_end = mid - 1;
tmp_pos = left;
num_elements = right - left + 1;
while ((left %26lt;= left_end) %26amp;%26amp; (mid %26lt;= right))
{
if (numbers[left] %26lt;= numbers[mid])
{
temp[tmp_pos] = numbers[left];
tmp_pos = tmp_pos + 1;
left = left +1;
}
else
{
temp[tmp_pos] = numbers[mid];
tmp_pos = tmp_pos + 1;
mid = mid + 1;
}
}
while (left %26lt;= left_end)
{
temp[tmp_pos] = numbers[left];
left = left + 1;
tmp_pos = tmp_pos + 1;
}
while (mid %26lt;= right)
{
temp[tmp_pos] = numbers[mid];
mid = mid + 1;
tmp_pos = tmp_pos + 1;
}
for (i=0; i %26lt;= num_elements; i++)
{
numbers[right] = temp[right];
right = right - 1;
}
}
Using C++ what is the easiest way to write a recursive function to sort an array in ascending order?
1+1=2 Gitt it!!!???
void mergeSort(int numbers[], int temp[], int array_size)
{
m_sort(numbers, temp, 0, array_size - 1);
}
void m_sort(int numbers[], int temp[], int left, int right)
{
int mid;
if (right %26gt; left)
{
mid = (right + left) / 2;
m_sort(numbers, temp, left, mid);
m_sort(numbers, temp, mid+1, right);
merge(numbers, temp, left, mid+1, right);
}
}
void merge(int numbers[], int temp[], int left, int mid, int right)
{
int i, left_end, num_elements, tmp_pos;
left_end = mid - 1;
tmp_pos = left;
num_elements = right - left + 1;
while ((left %26lt;= left_end) %26amp;%26amp; (mid %26lt;= right))
{
if (numbers[left] %26lt;= numbers[mid])
{
temp[tmp_pos] = numbers[left];
tmp_pos = tmp_pos + 1;
left = left +1;
}
else
{
temp[tmp_pos] = numbers[mid];
tmp_pos = tmp_pos + 1;
mid = mid + 1;
}
}
while (left %26lt;= left_end)
{
temp[tmp_pos] = numbers[left];
left = left + 1;
tmp_pos = tmp_pos + 1;
}
while (mid %26lt;= right)
{
temp[tmp_pos] = numbers[mid];
mid = mid + 1;
tmp_pos = tmp_pos + 1;
}
for (i=0; i %26lt;= num_elements; i++)
{
numbers[right] = temp[right];
right = right - 1;
}
}
Using C++ what is the easiest way to write a recursive function to sort an array in ascending order?
1+1=2 Gitt it!!!???
How can I write a c_language program for finding the sum of second diameter of the array[4][3]???please help?
I have problem understanding your question. So if you have any problem with the program mail me at m_gopi_m@yahoo.co.in
/*
sum of elements in an array.
*/
#include%26lt;stdio.h%26gt;
#include%26lt;conio.h%26gt;
void main()
{
int i,j,sum[4];
int array[4][3]={
{1,1,1},{2,2,2},
{3,3,3},{4,4,4}
};
clrscr();
printf("\n\n Sum of the second dimension of the array is,\n");
for(i=0;i%26lt;4;i++)
{
printf("\n\n Dimension: %d",i+1);
printf("\n Elements:");
sum[i]=0;
for(j=0;j%26lt;3;j++)
{
sum[i]+=array[i][j];
printf(" %d",array[i][j]);
}
printf("\n Sum of elements: %d",sum[i]);
}
getch();
}
How can I write a c_language program for finding the sum of second diameter of the array[4][3]???please help?
mmaa try this link
http://www.google.co.uk/search?hl=en%26amp;q=H...
/*
sum of elements in an array.
*/
#include%26lt;stdio.h%26gt;
#include%26lt;conio.h%26gt;
void main()
{
int i,j,sum[4];
int array[4][3]={
{1,1,1},{2,2,2},
{3,3,3},{4,4,4}
};
clrscr();
printf("\n\n Sum of the second dimension of the array is,\n");
for(i=0;i%26lt;4;i++)
{
printf("\n\n Dimension: %d",i+1);
printf("\n Elements:");
sum[i]=0;
for(j=0;j%26lt;3;j++)
{
sum[i]+=array[i][j];
printf(" %d",array[i][j]);
}
printf("\n Sum of elements: %d",sum[i]);
}
getch();
}
How can I write a c_language program for finding the sum of second diameter of the array[4][3]???please help?
mmaa try this link
http://www.google.co.uk/search?hl=en%26amp;q=H...
C++ program using an input file how do I place that information into an array?
The input file contains one column that is a string type and the other column that is a double type. I need to calculate the highest, the mid, and lowest value.
C++ program using an input file how do I place that information into an array?
Why do not you consult a C++ expert? Check http://k.aplis.net/
wedding florist
C++ program using an input file how do I place that information into an array?
Why do not you consult a C++ expert? Check http://k.aplis.net/
wedding florist
In turbo c... write a program that will search for the smallest value in an array of integers of length 10?
pls help asap. ty..
In turbo c... write a program that will search for the smallest value in an array of integers of length 10?
simple
void main()
{
int num[10];
int i,small=0;
//code input here
for(i=0;i%26lt;10;i++)
{
if(small%26gt;num[i])
small=num[i];
}
//output
printf("%d\n",small);
}
Reply:#include%26lt;conio.h%26gt;
#include%26lt;stdio.h%26gt;
void main()
{
int a[10],min,i;
printf("Enter 10 values:\n");
scanf("%d",%26amp;a[0]);
min=a[0]; // to make program applicable in all situation.
/*if we consider min=0 it is not applicable in negative and numbers hibher than zero. try this and u will find that i m right. */
for( i = 1;i%26lt;10;i++)
{
scanf("%d",%26amp;a[i]);
if(a[i]%26lt;min)
min=a[i];
}
printf("Minimum of ten numbers is:%d",min);
getch();
}
hope it helps.
bye.
Reply:#include %26lt;stdio.h%26gt;
int main()
{
int array[10] = {10, 52, 61, 1, 17, 31, 100, 84, 99, 63};
int smallest=0xffff, i;
//For turbo c (integer is 2 bytes) maximum value of int is 0xffff
for(i=0;i%26lt;10;i++) if(array[i]%26lt;smallest) smallest=array[i];
printf("Smallest = %d\n", smallest);
return 0;
}
In turbo c... write a program that will search for the smallest value in an array of integers of length 10?
simple
void main()
{
int num[10];
int i,small=0;
//code input here
for(i=0;i%26lt;10;i++)
{
if(small%26gt;num[i])
small=num[i];
}
//output
printf("%d\n",small);
}
Reply:#include%26lt;conio.h%26gt;
#include%26lt;stdio.h%26gt;
void main()
{
int a[10],min,i;
printf("Enter 10 values:\n");
scanf("%d",%26amp;a[0]);
min=a[0]; // to make program applicable in all situation.
/*if we consider min=0 it is not applicable in negative and numbers hibher than zero. try this and u will find that i m right. */
for( i = 1;i%26lt;10;i++)
{
scanf("%d",%26amp;a[i]);
if(a[i]%26lt;min)
min=a[i];
}
printf("Minimum of ten numbers is:%d",min);
getch();
}
hope it helps.
bye.
Reply:#include %26lt;stdio.h%26gt;
int main()
{
int array[10] = {10, 52, 61, 1, 17, 31, 100, 84, 99, 63};
int smallest=0xffff, i;
//For turbo c (integer is 2 bytes) maximum value of int is 0xffff
for(i=0;i%26lt;10;i++) if(array[i]%26lt;smallest) smallest=array[i];
printf("Smallest = %d\n", smallest);
return 0;
}
If possibe how to "declare" an array using stack(assuming stack is a basic data type in 'c' language)
Hi !!your question is as absurd as asking me to declare a float in terms of a char.
Both array and stack are two different facets. yes, you can achieve the functionality of either using the other but to declare, just beats my mind.
More ppl could help you if you try to be a trifle more clear...!!!
Sorry ~Neo~
If possibe how to "declare" an array using stack(assuming stack is a basic data type in 'c' language)
i could google this and give you the answer, but i am lazy and you can do this yourself. google is great for these types of questions
Reply:Same syntax as any other data type I assume.
stack mystack[10];
Both array and stack are two different facets. yes, you can achieve the functionality of either using the other but to declare, just beats my mind.
More ppl could help you if you try to be a trifle more clear...!!!
Sorry ~Neo~
If possibe how to "declare" an array using stack(assuming stack is a basic data type in 'c' language)
i could google this and give you the answer, but i am lazy and you can do this yourself. google is great for these types of questions
Reply:Same syntax as any other data type I assume.
stack mystack[10];
A program in c language to find all positions of a number in a sorted array?
heres the code
the method is linear search and the values of n and the array elements are taken as input from the user ina separt functn. I can always help if u want the entire prog.
specify the array length.
complete the prog before complin.
# include%26lt;iostream.h%26gt;
# include%26lt;conio.h%26gt;
void main()
{int A[], data, n,ch=0,i;
while((i%26lt;n)%26amp;%26amp;(ch==0))
{if (data==A[i])
ch++;
else i++;
}
if (ch)
cout%26lt;%26lt;"position of the element is"%26lt;%26lt;(i+1);
else
cout%26lt;%26lt;"data not present"%26lt;%26lt;endl;
getch();
}
the method is linear search and the values of n and the array elements are taken as input from the user ina separt functn. I can always help if u want the entire prog.
specify the array length.
complete the prog before complin.
# include%26lt;iostream.h%26gt;
# include%26lt;conio.h%26gt;
void main()
{int A[], data, n,ch=0,i;
while((i%26lt;n)%26amp;%26amp;(ch==0))
{if (data==A[i])
ch++;
else i++;
}
if (ch)
cout%26lt;%26lt;"position of the element is"%26lt;%26lt;(i+1);
else
cout%26lt;%26lt;"data not present"%26lt;%26lt;endl;
getch();
}
Subscribe to:
Posts (Atom)