Skip to content

Instantly share code, notes, and snippets.

@fisforfaheem
Created January 27, 2018 20:43
Show Gist options
  • Save fisforfaheem/d196a730646cf8b1c002dc61db4b555a to your computer and use it in GitHub Desktop.
Save fisforfaheem/d196a730646cf8b1c002dc61db4b555a to your computer and use it in GitHub Desktop.
// 1
// z = 2
// 2
#include <iostream>
using namespace std;
void encrypt(char *);
void decrypt(char *);
void main()
{
char message[10];
cout << "Type message: ";
cin.getline(message, 10);
encrypt(message);
cout << "Encrypted Message: " << message << endl;
decrypt(message);
cout << "Decrypted Message: " << message << endl;
system("pause");
}
void encrypt(char *x) {
for (int i = 0; i < 9; i++) {
*(x+i) = *(x+i) + 3;
}
}
void decrypt(char *x) {
for (int i = 0; i < 9; i++) {
*(x + i) = *(x + i) - 3;
}
}
// 3
#include <iostream>
using namespace std;
void main()
{
int overs;
cin >> overs;
int *score = new int[overs];
int avg_score = 0;
for (int i = 0; i < overs; i++) {
cin >> score[i];
avg_score += score[i];
}
cout << "Run Rate is: " << avg_score / overs;
system("pause");
}
// 4
#include <iostream>
using namespace std;
void main()
{
int x[10];
int highest = 0;
int *address;
for(int i = 0; i < 10; i++) {
cin >> *(x + i);
if (*(x + i) > highest) {
highest = *(x + i);
address = (x + i);
}
}
cout << highest << endl << address << endl;
system("pause");
}
// 6
#include <iostream>
using namespace std;
void main()
{
char x[20], y[20];
cin.getline(x, 20);
cin.getline(y, 20);
int letters = 0;
int words = 2;
for (int i = 0; x[i] != NULL; i++) {
letters++;
if (x[i] == ' ') {
words++;
}
}
for (int i = 0; y[i] != NULL; i++) {
letters++;
if (y[i] == ' ') {
words++;
}
}
cout << "Total letters: " << letters << endl;
cout << "Total words: " << words << endl;
system("pause");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment