0% found this document useful (0 votes)
31 views5 pages

Task 3

The document contains multiple C++ programming tasks that cover various topics such as array manipulation, string handling, and counting elements. Each task includes code snippets that demonstrate operations like reversing an array, counting vowels and consonants in a string, finding unique elements, and summing two arrays. The tasks are designed to help users practice and understand fundamental programming concepts.

Uploaded by

kingofgali36
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views5 pages

Task 3

The document contains multiple C++ programming tasks that cover various topics such as array manipulation, string handling, and counting elements. Each task includes code snippets that demonstrate operations like reversing an array, counting vowels and consonants in a string, finding unique elements, and summing two arrays. The tasks are designed to help users practice and understand fundamental programming concepts.

Uploaded by

kingofgali36
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

task 3.

#include <iostream>
using namespace std;

int main()
{
int b[5]={45,226,25,3,89};

cout<<"Original array: ";


for(int i=0;i<5;i++){
cout<<b[i]<<" ";
}
cout<<endl;

cout<<"Reversed array: ";


for(int i=4;i>=0;i--){
cout<<b[i]<<" ";
}
cout<<endl;

return 0;
}

task 3.2

#include <iostream>
using namespace std;

int main()
{
char str[100];
cout<<"enter a string: ";
cin>>str;
int vowelCount = 0;
for(int i=0;str[i]!='\0'; i++) {
char ch=str[i];
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' ||ch == 'A'
|| ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U') {
vowelCount++;
}

cout<<"Vowel number: "<<vowelCount<<endl;


return 0;
}

task 3.3

#include <iostream>
using namespace std;

int main()
{
int a[10]={};

cout<<"Enter 10 elements: ";


for(int i=0;i<10;i++){
cin>>a[i];
}

for(int i=0;i<10; i++){


cout<<a[i]<<" ";
}
cout<<endl;

int max = a[0];


for(int i=1;i<10;i++){
if(a[i] > max){
max=a[i];
}
}

cout<<"Max: "<<max<<endl;

return 0;
}

task 3.4

#include <iostream>
using namespace std;

int main()
{
string name[10];
string search;
bool found=false;

cout<<"Enter 10 name:"<<endl;
for(int i=0;i<10;i++){
cout<<"Name "<<i;
cin>>name[i];
}

cout<<"Enter the name to search: ";


cin>>search;

for(int i=0;i<10;i++){
if(name[i]==search){
cout<<"Name found at index "<<i<<endl;
found=true;
break;
}
}
if(!found){
cout<<"not found."<<endl;
}

return 0;
}

task 3.5
#include <iostream>
using namespace std;

int main()
{
int a[5]={45,65,32,26,26};

for(int i=0;i<5;i++){
int count=0;
for(int j=0;j<5;j++){
if(a[i]==a[j]){
count++;
}
}
if(count==1){
cout<<a[i]<<" is unique"<<endl;
}
}

return 0;
}

task 3.6

#include <iostream>
using namespace std;

int main()
{
int a[10]={45,65,32,26,26,659,232,59,23,47};
int even=0;
int odd=0;

for(int i=0;i<10;i++){
if(a[i]%2==0){
even++;
}
else{
odd++;
}
}

cout<<"Number of Even number: "<<even<<endl;


cout<<"Number of Odd number: "<<odd<<endl;

return 0;
}

task 3.7

#include <iostream>
using namespace std;
int main(){
char word[50];
int count=0;
cout<<"Please enter word (enter 'end' to stop): "<<endl;
while(true){
cin >> word;
if(word[0]=='e' && word[1]=='n' && word[2]=='d'){
break;
}
count = count + 1;
}

cout<<"total word: "<<count<<endl;


return 0;
}

task 3.8

#include <iostream>
using namespace std;

int main(){
int a[5];
int b[5];
int sum[5];

cout << "enter first array: ";


for(int i=0; i<5; i++){
cin >> a[i];
}

cout <<"enter second array: ";


for(int i=0; i<5; i++){
cin >> b[i];
}

for(int i=0; i<5; i++){


sum[i] = a[i]+b[i];
}

cout<<"Sum: ";
for(int i=0; i<5; i++){
cout << sum[i] << " ";
}

return 0;
}

task 3.9

#include <iostream>
using namespace std;

int main(){
char str[100];
cout<<"Enter a string: ";
cin>>str;

int Count=0;

cout<<"Consonants are : ";


for(int i=0; str[i]!='\0'; i++){
char ch = str[i];
if(ch!='a' && ch!='e' && ch!='i' && ch!='o' && ch!='u' && ch!='A' && ch!='E' &&
ch!='I' && ch!='O' && ch!='U'){
cout<<ch<<" ";
Count = Count + 1;
}
}
cout<<endl;
cout<<"Total consonant: "<<Count<<endl;
return 0;
}

task 3.10

#include <iostream>
using namespace std;

int main(){
char str[100];
cout<<"Enter a string: ";
cin>>str;
for(int i=0; str[i]!='\0'; i++){
for(int j=0; j<i; j++){
if(str[i]==str[j]){
for(int k=i; str[k]!='\0'; k++){
str[k]=str[k+1];
}
i--;
break;
}
}
}
cout<<"Modified string: "<<str<<endl;
return 0;
}

You might also like