Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Question:1
- #include <iostream>
- using namespace std;
- int main()
- {
- int a;
- cout<<"Plsease inter the array size : ";
- cin>>a;
- int arr[a];
- cout<<"enter the array input : "<< endl;
- for(int i=0;i<a ;i++){
- cin>>arr[i];
- }
- cout<<endl;
- for(int j=0;j<a; j++){
- cout<<arr[j];
- cout<<" ";
- }
- cout<<endl;
- for(int k=(a-1);k>=0; k--){
- cout<<arr[k];
- cout<<" ";
- }
- return 0;
- }
- Question:1 End--------------------------------------------------------------------------------------------------------------
- Question:2
- #include <iostream>
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- int arr[100];
- int big=0,small=100,sum=0;
- srand(time(0));
- for(int i=0;i<100; i++){
- arr[i]=rand()%100;
- }
- for(int j=0;j<100; j++){
- {
- if( big<arr[j])
- big=arr[j];
- }
- if( small>arr[j])
- small=arr[j];
- }
- cout<<"100 random integers :"<<endl;
- for(int k=0;k<100; k++){
- cout<<arr[k]<<" ";
- sum=sum+arr[k];
- }
- double avg=0,s=sum;
- avg=s/100;
- cout<<endl;
- cout<<"Largest value : "<<big<<endl;
- cout<<"Smallest value : "<<small<<endl;
- cout<<"average value : "<<avg<<endl;
- return 0;
- }
- Question:2 End-----------------------------------------------------------------------------------------------
- Question:3
- #include <iostream>
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- int arr[25],a,b;
- cout<<"input the first number : ";
- cin>>a;
- cout<<"input the second number (2nd num > 1st num) : ";
- cin>>b;
- srand(time(0));
- for(int i=1;i<=25; i++){
- int srand = rand()%(b-a + 1) + a;
- arr[i]=srand;
- cout<<arr[i]<<" ";
- }
- return 0;
- }
- Question:3 end-----------------------------------------------------------------------------------------------
- Question:4
- #include <iostream>
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- int a,b,c;
- int x=0;
- cout<<"print array size : ";
- cin>>a;
- int arr[a];
- srand(time(0));
- for(int i=0;i<a; i++){
- arr[i]=rand()%10;
- }
- for(int k=0;k<a; k++){
- cout<<arr[k]<<" ";
- }
- cout<<endl;
- cout<<"Input the number to Search in the array : ";
- cin>>b;
- for (int j=0;j<=a;j++) {
- //x=counter
- if (arr[j]==b){
- cout<<"The number found in index "<<j<<endl;
- x++;
- }
- }
- cout<<"and the number was found : "<<x<<" times ";
- return 0;
- }
- Question : 4 end-----------------------------------------------------------------------------------------
- Question : 5
- #include <iostream>
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- int a,b,c,t;
- float arr[5],arr2[5];
- srand(time(0));
- for(int i=0;i<5; i++){
- arr[i]=rand()%10;
- arr2[i]=rand()%10;
- }
- cout<<"first array before sorting : ";
- for(int k=0;k<5; k++){
- cout<<arr[k]<<" ";
- }
- cout<<endl;
- cout<<"second array before sorting : ";
- for(int k=0;k<5; k++){
- cout<<arr2[k]<<" ";
- }
- cout<<endl;
- for(int k=0;k<5; k++){
- for(int j=k+1;j<5;j++){
- if(arr[k]>arr[j]){
- t= arr[k];
- arr[k] = arr[j];
- arr[j] = t;
- }
- }}
- cout<<"first array in ascending order : ";
- for(int k=0;k<5; k++){
- cout <<arr[k]<<" ";
- }
- for(int k=0;k<5; k++){
- for(int j=k+1;j<5;j++){
- if(arr2[k]<arr2[j]){
- t= arr2[k];
- arr2[k] = arr2[j];
- arr2[j] = t;
- }
- }
- }cout<<endl;
- cout<<"Second array in descending order : ";
- for(int k=0;k<5; k++){
- cout<<arr2[k]<<" ";
- }
- return 0;
- }
- Question : 5 end-------------------------------------------------------------------------------------------
- Question : 6
- #include <iostream>
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- int arr[10],a=1,b,c,d=1,i=0;
- cout<<"insert 10 array input : "<<endl;
- for(int i=0;i<10;i++){
- cin>>arr[i];
- }
- for (int i = 0; i < 10; i++)
- if (a == 1 || d == 1) {
- if (arr[i] < arr[i+1])
- d = 0;
- else if (arr[i] > arr[i+1])
- a = 0;
- }
- if (a == 1)
- cout<<"The array is sorted in ascending order";
- else if (d == 1)
- cout<<"The array is sorted in descending order ";
- else
- cout<<"The array is not sorted ";
- return 0;
- }
- Question : 6 end -----------------------------------------------------------------------------------------
- Question : 7
- #include<iostream>
- #include<conio.h>
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- float arr[11];
- int big=0,big1=0,small=10,small1=0,t=0;
- float mid=11/2;
- float median;
- srand(time(0));
- for(int i=0;i<11; i++){
- arr[i]=rand()%10;
- cout<<arr[i]<<" ";
- }
- for(int i=0;i<11; i++){
- if(big<arr[i]){
- big=arr[i];
- }
- if(small>arr[i]){
- small=arr[i];
- }
- }
- for(int i=0;i<11; i++){
- if(big1<arr[i] && big>arr[i] ){
- big1=arr[i];
- }
- if(big1>arr[i] && small!=arr[i]){
- small1=arr[i];
- }
- }
- for(int k=0;k<11; k++){
- for(int j=k+1;j<11;j++){
- if(arr[k]>arr[j]){
- t= arr[k];
- arr[k] = arr[j];
- arr[j] = t;
- }
- }}
- {
- median = (arr[(11-1)/2]+arr[11/2])/2.0;
- }
- cout<<endl;
- cout<<"First minimun "<<small<<endl;
- cout<<"Second mimunum "<<small1<<endl;
- cout<<"First maximum "<<big<<endl;
- cout<<"Second Maximum "<<big1<<endl;
- cout << "The median is: " << median << endl;
- return 0;
- }
- Question : 7 end------------------------------------------------------------------------------------------------------
- Question : 8
- #include <iostream>
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- int arr[10],evenArr[10],oddArr[10],a=0,b=0,c,even=0,evenArr1[10],counter=0;
- srand(time(0));
- for(int i=0;i<10; i++){
- arr[i]=rand()%10;
- cout<<arr[i]<<" ";
- }
- cout<<endl;
- for(int i=0;i<10;i++)
- {
- if(arr[i]%2==0){
- evenArr[a]=arr[i];
- a++;
- }
- if(arr[i]%2!=0){
- oddArr[b]=arr[i];
- b++;
- }
- }
- cout<<endl;
- for(int i=0;i<a;i++){
- cout<<evenArr[i]<<" ";
- }
- cout<<endl;
- for(int i=0;i<b;i++){
- cout<<oddArr[i]<<" ";
- }
- return 0;
- }
- Question : 8 end-----------------------------------------------------------------------------------------
- Question :9
- #include<iostream>
- #include<conio.h>
- using namespace std;
- int main()
- {
- int arr[100],i,n;
- cout<<"Enter a Number :";
- cin>>n;
- arr[0]=0;
- arr[1]=1;
- for(i=2;i<n;i++)
- arr[i]=arr[i-1]+arr[i-2];
- cout<<"So the "<<n<<" Fibonaccii numbers are:"<<endl;
- for (i=0;i<n;i++)
- cout<<arr[i]<<" ";
- return 0;
- }
- Question :9 end-----------------------------------------------------------------------------------------------
- Question :10
- #include <iostream>
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- int i,s=0,j,p;
- int arr[10];
- srand(time(0));
- for(int i=0;i<10; i++){
- arr[i]=rand()%100;
- cout<<arr[i]<<" ";
- }
- cout<<endl;
- for (i = 0; i < 10; i++) {
- j = 2;
- p = 1;
- while (j < arr[i]) {
- if (arr[i] % j == 0) {
- p = 0;
- break;
- }
- j++;
- }
- if (p == 1) {
- cout << arr[i] << " ";
- s++;
- }
- }
- cout<<"prime number count : "<<s;
- return 0;
- }
- Question : 10 end-----------------------------------------------------------------------------------------------
- Question : 11
- #include <iostream>
- using namespace std;
- int main()
- {
- int a[10], n, i,j;
- cout<<"Input the number You want to convert ";
- cin>>n;
- j=n;
- for(i=0; n>0; i++)
- {
- a[i]=n%2;
- n= n/2;
- }
- cout<<"Binary number of "<<j<<" = ";
- for(i=i-1 ;i>=0 ;i--)
- {
- cout<<a[i];
- }
- return 0;
- }
- Question: 11 end---------------------------------------------------------------------------------------------------
- Question: 12
- #include <iostream>
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- int arr[10],a,b,c,j;
- srand(time(0));
- for(int i=0;i<10; i++){
- arr[i]=rand()%10;
- cout<<arr[i]<<" ";
- }
- cout<<endl;
- cout<<endl;
- int result = 0;
- for (int i=0; i<10; i++){
- for (int j=0;j<10;j++){
- if (arr[i] == arr[j])
- result++;
- }
- cout<<arr[i]<<" was found "<<result<<" times"<<endl;
- result=0;
- }
- return 0;
- }
- Question : 12 end---------------------------------------------------------------------------------------------------------
- Question :13
- #include <iostream>
- #include <bits/stdc++.h>
- using namespace std;
- const int R=5;
- const int C=3;
- int main() {
- int r=0, c=0;
- int arr[R][C];
- srand(time(0));
- for (r=0; r<R; r++)
- for (c=0;c<C;c++)
- arr[r][c]=rand()%(50-30 + 1) + 30;
- for (c=0;c<C;c++) {
- for (r=0;r<R;r++){
- cout << arr[c][r] << endl;
- }
- cout << endl;
- }
- return 0;
- }
- Question :13 end-------------------------------------------------------------------------------------------------------
Add Comment
Please, Sign In to add comment