write a program to input 10 numbers in an array and print the 3 digit numbers entered by the user
write a program to initialize the array with first 10 multiples of 3 starting with 9 and the even multiples of 3
wap to store first 10 fibonacci numbers in an array starting from zero also count the number of prime fibonacci numbers
wap to input 10 integers in an array (-ve or +ve) print the smallest and largest integers entered by the user
wap to store 10 positive integers in an array input another number 'n' in form of the user amd check how many times its present in the array
wap to store first 10 prime nos entered by the user in an array and print them
wap to store 10 integers in an array (both positive as well as negative) and shift positive integers towards right and negative integers towards left part of the array
wap to input 10 no.s in an array and print the numbers in ascending order without using any sorting technique
#include <iostream>
using namespace std;
int main(){
cout<<"Enter 10 numbers;\n";
int arr[10];
for(int i = 0; i < 10; i++) cin>>arr[i];
cout<<"3 digit numbers: ";
for(int i = 0; i < 10; i++) if(arr[i] > 99 && arr[i] < 1000) cout<<arr[i]<<" ";
return 0;
}
#include <iostream>
using namespace std;
int main(){
int arr[10];
for(int i = 0; i < 10; i++){
arr[i] = 3 * (i + 3);
}
for(int i = 0; i < 10; i++) cout<<arr[i]<<" ";
for(int i = 0; i < 10; i++){
arr[i] = 3 * (2 * (i + 1));
}
cout<<endl;
for(int i = 0; i < 10; i++) cout<<arr[i]<<" ";
return 0;
}
#include <iostream>
using namespace std;
bool is_prime(int a){
if(a <= 1) return false;
else if(a == 2) return true;
else{
for(int i = 2; i < a;i++){
if(a % i == 0) return false;
}
return true;
}
}
int fibonacci(int n){
int a = 0, b = 1;
if(n == 0) return a;
else if(n == 1) return b;
else return fibonacci(n - 1) + fibonacci(n - 2);
}
int main(){
int arr[10], count = 0;
for(int i = 0; i < 10; i++){
arr[i] = fibonacci(i);
}
for(int i = 0; i < 10; i++) cout<<arr[i]<<" ";
cout<<endl;
for(int i = 0; i < 10; i++){
if(is_prime(arr[i])){
count++;
cout<<arr[i]<<" ";
}
}
cout<<"\n"<<count<<" Prime fibonacci";
return 0;
}
#include <iostream>
using namespace std;
int main(){
int min = INT_MAX, max = INT_MIN;
cout<<"Input numbers\n";
int arr[10];
for(int i = 0; i < 10; i++){
cin>>arr[i];
if(arr[i] < min) min = arr[i];
if(arr[i] > max) max = arr[i];
}
cout<<"Smallest: "<<min<<endl;
cout<<"Largest: "<<max<<endl;
return 0;
}
#include <iostream>
using namespace std;
int main(){
int arr[10], n, count = 0;
cout<<"Input array elements\n";
for(int i = 0; i < 10; i++) cin>>arr[i];
cout<<"Input n: ";
cin>>n;
for(int i = 0; i < 10; i++){
if(arr[i] == n) count++;
}
if(count == 0) cout<<"\nNot present";
else cout<<n<<" appears "<<count<<" times";
return 0;
}
#include <iostream>
using namespace std;
bool is_prime(int a){
if(a <= 1) return false;
else if(a == 2) return true;
else{
for(int i = 2; i < a;i++){
if(a % i == 0) return false;
}
return true;
}
}
int main(){
int n, count = 0, arr[10];
while(count < 10){
cout<<"Enter a number: ";
cin>>n;
if(is_prime(n)){
arr[count] = n;
count++;
}
else cout<<"Not a prime\n";
}
for(int i = 0; i < 10; i++) cout<<arr[i]<<" ";
return 0;
}
#include <iostream>
using namespace std;
void swap(int* a, int* b){
int c;
c = *a;
*a = *b;
*b = c;
}
int main(){
int arr[10];
cout<<"Enter array elements\n";
for(int i = 0; i < 10; i++) cin>>arr[i];
for(int i = 0; i < 10; i++){
if(arr[i] > 0)
for(int j = i + 1; j < 10; j++){
if(arr[j] < 0){
swap(&arr[i], &arr[j]);
break;
}
}
}
for(int i = 0; i < 10; i++) cout<<arr[i]<<" ";
return 0;
}
#include <iostream>
using namespace std;
int main(){
int arr[10], min = INT_MAX, point;
cout<<"Input array elements\n";
for(int i = 0; i < 10; i++) cin>>arr[i];
for(int j = 0; j < 10; j++){
for(int i = 0; i < 10; i++) if(arr[i] < min){
min = arr[i];
point = i;
}
cout<<min<<" ";
arr[point] = INT_MAX;
min = INT_MAX;
}
return 0;
}
Comments
Leave a comment