Compilation Reyes
Compilation Reyes
Compilation Reyes
This is a program that will asks the user to type 10 integers of an array. And the program must
compute and write how many integers are greater than or equal to 10.
#include <iostream>
using namespace std;
const int N=10;
int main()
{
int t[10],i,nb=0;
for(i=0;i<N;i++)
{
cout << "Type an integer: ";
cin >> t[i];
nb+= (t[i]>=10); // note that true converts to 1, false to 0
}
cout << "the number of integers greater or equal to 10 is: " << nb
<<endl;
return 0;
}
EXERCISE 2
This is a program that will asks the user to type 10 integers of an array. The program must output the
largest element in the array, and the index at which that element was found.
#include <iostream>
using namespace std;
const int MR = 10;
int main()
{
int arr[MR];
int Largest = 0, index = 0;
cout << "Please enter " << MR << " integers:" << endl;
for (int m = 0; m < MR; m++)
{
cin >> arr[m];
}
for (int m = 0; m < MR; m++)
{
if (arr[m] >= Largest)
{
Largest = arr[m];
index = m+1;
}
}
cout << "Largest number = " << Largest << ", at index: " << index << endl;
return 0;
}
EXERCISE 3
This is a program that will asks the user to type 10 integers of an array and an integer Marlyn. The
program must search if Marlyn is in the array of 10 integers. The program writes "Marlyn is in the
array" or "Marlyn is not in the array".
#include <iostream>
using namespace std;
int main(void)
{
int V,input[10];
bool equalsV(false);
cout << "Type the value of MARLYN: ";
cin >> V;
for(int m(0); m < 10; m++)
{
EXERCISE 4
This a program that will asks the user to type 10 integers of an array and an integer value Faith . The
program must search if the value Faith exists in the array and must remove the first occurrence of
Faith, shifting each following element left and adding a zero at the end of the array. The program
must then write the final array.
#include <iostream>
using namespace std;
const int N=10;
int main()
{
int t[N],i,j,V;
bool found;
for(i=0;i<N;i++)
{
cout << "Type an integer: ";
cin >> t[i];
}
cout << "Type the value of FAITH: ";
cin >> V;
for (i=0;i<N;i++)
if (t[i]==V)
{
for (j=i;j<N-1;j++)
t[j]=t[j+1];
t[N-1]=0;
break;
}
for(i=0;i<N;i++)
cout << t[i] << endl;
return 0;
}
//
***
#include<conio.h>
#include<stdlib.h>
#define p printf
#define s scanf
#define g getch
int main(void)
{
char ch= 'c';
char*chptr= &ch;
int i= 20;
int*intptr= &i;
float f= 1.20000;
float*fptr= &f;
This program will ask the user to enter two integers that they want to add.
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define p printf
#define s scanf
#define g getch
main()
{
int num1, num2, ans;
p("Marlyn P Reyes");
g();
return 0;
}
This program will ask the user to enter 5 un-order numbers then the program will
ascend the 5 numbers.
//C program for Arranging 5 Numbers in Ascending Order
#include<stdio.h>
#include<conio.h>
int main()
{
int a[5],i,j,t;
printf("Enter 5 nos.\n\n");
for (i=0;i<5;i++)
scanf("%d",&a[i]);
for (i=0;i<5;i++)
{
for(j=i+1;j<5;j++)
{
if(a[i]>a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
printf("Ascending Order is:");
for(j=0;j<5;j++)
printf("\n%d",a[j]);
getch();
}
int main()
{
int x=10, y=20;
printf("x=%d and y=%d",x,y);
//swap x and y
swap (&x,&y);
printf("\nx=%d and y=%d\n",x,y);
}
int swap(int *a, int *b)
{
int temp=*a;
*a=*b;
*b=temp;}
****
#include <iostream>
using namespace std;
int main() {
float celsius;
float fahrenheit;
return 0;
{
private:
int l;
int w;
public:
Area()
{
cout<<"Enter the length of the rectangle: "<<endl;
cin>>l;
cout<<"Enter the width of the rectangle: "<<endl;
cin>>w;
cout<<"The area is "<<l*w<<endl;
}
};
int main()
{
Area();
return 0;
}
#include<iostream>
#include<stdlib.h>
using namespace std;
class Conversion
{
private:
int cubicmeter;
int liter;
public:
Conversion()
{
int main()
{
Conversion();
return 0;
}
#include<stdio.h>
#include<stdlib.h>
int main()
{
int c, lo, hi, middle, n ,search, array[100];
printf("Enter number of elements\n");
scanf("%d",&n);
printf("Enter %d integers:",n);
for(c=0;c<n;c++)
scanf("%d",&array[c]);
lo;
hi;
middle=(lo+hi)/2;
while(lo<=hi)
{
if(array[middle]<search)
lo=middle+1;
else if (array[middle]=search)
{
printf("%d found at the location %d.\n",search,middle+1);
break;
}
else
hi=middle-1;
middle= (lo+hi)/2;
if(lo>hi)
printf("Not found! %d is not present in the list.\n",& search);
system("pause");
return 0;
}
#include <stdio.h>
#include <conio.h>
#include<stdlib.h>
main()
{
int a[3], i;
system("CLS");
printf("\n\t Enter three numbers : ");
for(i=0; i<3; i++)
{
scanf("%d", &a[i]); // read array
}
This is a program that will asks the user to type 10 integers of an array. The program must output the
largest element in the array, and the index at which that element was found.
#include <iostream>
using namespace std;
const int MR = 10;
int main()
{
int arr[MR];
int Largest = 0, index = 0;
cout << "Please enter " << MR << " integers:" << endl;
for (int m = 0; m < MR; m++)
{
cin >> arr[m];
}
for (int m = 0; m < MR; m++)
{
if (arr[m] >= Largest)
{
Largest = arr[m];
index = m+1;
}
}
cout << "Largest number = " << Largest << ", at index: " << index << endl;
return 0;
}