ok, once again, I'm back...after this program I don't plan to write anymore...here's the task...

Program # 1: Write a program that can decrypt the following string
Ukjv!lt#xkz#DVT#sxmht1
Each character must be decrypted by applying the decryption algorithm to its ASCII
value. The decryption algorithm is:
• if array index is even, subtract 1
• if array index is odd, subtract 3
That is, the first character has an array index of 0, which is considered even, so subtract
1 from its ASCII value to produce the new ASCII value. The second character has an
array index of 1, which is odd, so subtract 3 from its ASCII value to produce the new
ASCII value. Repeat for all characters.
Example: The encrypted string
erh
can be decrypted to produce
dog
1. In main(), declare an array of chars for storing the encrypted string.
2. Write a function that will be passed this array of chars, which it then processes character by character, printing out each decrypted character as it is determined. The declaration will look like this:
void decrypt(char input[]);
3. Don’t calculate the length of the array. Instead, look for the terminating null that is at the end of each string.
4. Don’t hard-code any ASCII values (or their character equivalents) in your program; it’s unnecessary.
5. If you do the math correctly to produce the decrypted ASCII values, then they will be in the range that is valid for ASCII characters.

Program # 2: Write a program that can find the maximum even and odd numbers in the following two series:
4, 9, 2, 8, 7, 13, 2, 5
and
14, 19, 3, 12, 20, 8, 20, 7, 17, 9
• Store each series of numbers in its own array in the original order in main().
• In main(), you will also declare two variables of type int for storing the maximum even and odd values.
• Write a single function for determining the maximum even and odd values of a 1D array. The function declaration will be
void largest(int data[], int size, int* ptrEven, int* ptrOdd);
where size is the size of the array to be processed, ptrEven is the pointer to the variable
in main() for storing the maximum even value, and ptrOdd is the pointer to the variable
in main() for storing the maximum odd value.
• Don’t hard-code values in your function specific to either array. Instead, the function
should be able to process either of these arrays or any other 1D array of ints.
• In main(), call largest() for the first array and after largest() has completed its work,
from main() print the maximum even and odd values from the sequence. Repeat this
process for the second array.
• You can assume that the array values will be greater than or equal to zero.

can someone please...I thought I was completely lost on the first 3, this one has me stumped, I'm not even sure where to begin

3
Contributors
7
Replies
8
Views
9 Years
Discussion Span
Last Post by devnar

this one has me stumped, I'm not even sure where to begin

You've listed the whole algorithm necessary for solving both the programs. There isn't much left to think about.

Anyway, your decrypt function looks something like this:

``````void decrypt(char input[])
{
char output[20];
int i;
for(i=0; input[i]!='\0';i++)  // without using strlen
{
if(i%2==0)
output[i]=input[i]-1;
else
output[i]=input[i]-3;
.
.
.
}``````

your second program is also simple enough. Just study the algorithm carefully and try to convert it to code. If you have any specific problems, post it here.

will this work the same as what you got?

``````#include <stdio.h>

void decrypt(char input[])
{
while(input[i]!= '\0')
{
i++;

if(i % 2 == 0)
printf("%d", i\n);

if(i % 2 != 0)
printf("%d", i\n);
}

void main(void)
{
decrypt(string)
}

#include <stdio.h>

void largest(int data[], int size, int* ptrEven, int* ptrOdd)
{``````

Nope. Not even close. Read your question's statement and my code more carefully. If you're having trouble understanding the basics of C, then check this thread out: Starting C

here's my latest, not sure I'm doing this right...

``````#include <stdio.h>

void decrypt(char input[])
{
while(input[i]!= '\0')
{
i++;

if(i % 2 == 0)
printf("%d", i\n);

if(i % 2 != 0)
printf("%d", i\n);
}

void main(void)
{
decrypt(string)
}

#include <stdio.h>

void largest(int data[], int size, int* ptrEven, int* ptrOdd)
{
largest(int data[], int size, &even, &odd)
}
void main(void)
{
size = sizeof(Array)/sizeof(int);
}``````

do i need a bubble sort? if so where?

The function largest has got bunch of syntax errors .

No, you're not. Before writing your code first establish an algorithm which you think will solve your problem, then convert that to code. There are too many mistakes in your code and it's logic is not even close to solving your problem. It's best if you first make yourself familiar with loops, variables, functions and other basic stuff.

ok, once again, I'm back...after this program I don't plan to write anymore...

If that's the case then ignore my last post.:icon_rolleyes: I'm outta here!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.