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.

Recommended Answers

All 7 Replies

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.

I try to solve it plz help me

I try to solve it plz help me

That's great that you tried. Did you write any code in your attempts? Please post it here, so that we might help you troubleshoot it.

thank's alot I'll put it here when i finished

I try and I wrote this code

#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?? :confused:

look to this

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 ;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.