Please support our C++ advertiser: Programming Forums
Views: 1438 | Replies: 7
![]() |
•
•
Join Date: Sep 2004
Posts: 9
Reputation:
Rep Power: 0
Solved Threads: 0
I'm learn c++ alone and need help to write programs
plz help me :cry:
A.Write is the greatest number?
You have to stor. In an array, twenty integer number given by the user. One these numbers are stored in this array, you have to find the greatest number and print it.
Note:
To manipulate the array in this exercise you should use only pointers.
------------------------------------------------------------------------------
B. Copy a string in an array using Pointers.
The user give you two strings (assume maximum for each string is 50 characters) ,you have to copy the shortest string in an array. Once this string is hold in an array, you must print it using pointers.
Hint:
The function strcmp can help you to resolve this exercise. This functions is included in the library cstring.
Function: int strcmp ( const char *s1, const char *s2 );
Description:
Compares the string s1 with the string s2. The function returns a value of zero, less than zero or greater than zero if s1 is equal to , less than or greater than s2, respectively.
plz help me :cry:
A.Write is the greatest number?
You have to stor. In an array, twenty integer number given by the user. One these numbers are stored in this array, you have to find the greatest number and print it.
Note:
To manipulate the array in this exercise you should use only pointers.
------------------------------------------------------------------------------
B. Copy a string in an array using Pointers.
The user give you two strings (assume maximum for each string is 50 characters) ,you have to copy the shortest string in an array. Once this string is hold in an array, you must print it using pointers.
Hint:
The function strcmp can help you to resolve this exercise. This functions is included in the library cstring.
Function: int strcmp ( const char *s1, const char *s2 );
Description:
Compares the string s1 with the string s2. The function returns a value of zero, less than zero or greater than zero if s1 is equal to , less than or greater than s2, respectively.
It looks like you forgot to read the Announcement. Post the code you have like this.
[code]/* your code here */[/code]
[code]/* your code here */[/code]
High Plains Blogger #plains #lounge ## I, for one, welcome our new socialist overlords.
"Capitalism is the unequal distribution of wealth. Socialism is the equal distribution of poverty."
"Capitalism is the unequal distribution of wealth. Socialism is the equal distribution of poverty."
•
•
Join Date: Dec 2003
Location: Nashville, TN
Posts: 2,336
Reputation:
Rep Power: 12
Solved Threads: 102
In case you weren't quick enough to read the Announcement that Dave was kind enough to post, please post some code of your own that you're working on. When you post questions in this manner, it seems that they're homework questions. We're not here to do your homework for you- we're here to help you learn.
Alex Cavnar, aka alc6379
•
•
Join Date: Dec 2003
Location: Nashville, TN
Posts: 2,336
Reputation:
Rep Power: 12
Solved Threads: 102
•
•
Join Date: Sep 2004
Posts: 9
Reputation:
Rep Power: 0
Solved Threads: 0
I try and I wrote this code
but I didn't understand the function how i can use it
and I think this function not use for copy??
#include <iostream.h>
#include <string.h>
#include <conio.h>
void main()
{
char str1[6], str2[6], shortest[6];
char *ptr;
int cmp;
clrscr();
cout << "Enter str1 ..." << endl;
cin >> str1;
cout << endl << "Enter str2 ..." << endl;
cin >> str2;
// ....... comparing strings and cop to array SHORTEST ........
cout << endl << "Shortest: ";
*ptr = shortest;
while (*ptr) cout << *ptr++;
getch();
} but I didn't understand the function how i can use it
and I think this function not use for copy??
•
•
Join Date: Sep 2004
Posts: 9
Reputation:
Rep Power: 0
Solved Threads: 0
look to this
it's not work i compile it but it's not the value of max num
it's not work i compile it but it's not the value of max num
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main()
{
int num[2];
int *ptr;
int i , max = 0;
cout << "Enter the 20 numbers: "<< " "<< endl;
for (i = 0; i < 2; ++i)
cin >> num[i];
ptr = &num[2];
for (i = 0; i < 2; ++i)
if(*ptr > max)
{
max = *ptr;
*(ptr++);
}
cout << "MAX = " <<max<< endl;
return 0 ;
}![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)






Linear Mode