[ create a new paste ] login | about

Link: http://codepad.org/fbx5JfMf    [ raw code | output | fork | 6 comments ]

C, pasted on Sep 15:
#include<stdio.h>
#include<conio.h>
#define MAX 100

void nhap (float a[], int &n)
{
	do
	{
		printf("\nNhap so phan tu: ");
		scanf("%d", &n);
		if(n <= 0 || n > MAX)
		{
			printf("\nSo phan tu khong hop le. Xin kiem tra lai !");
		}
	}while(n <= 0 || n > MAX);
	for(int i = 0; i < n; i++)
	{
		printf("\nNhap a[%d]: ", i);
		scanf("%f", &a[i]);
	}
}

void xuat(float a[], int n)
{
	for(int i = 0; i < n; i++)
	{
		printf("%8.3f", a[i]);
	}
}

int timvitrinhonhat(float a[], int n)
{
	int vtnn = 0;
	for(int i = 0; i < n; i++)
	{
		if(a[i] < a[vtnn])
		{
			vtnn = i;
		}
	}
	return vtnn;
}
int main()
{
	int n;
	float a[MAX];
	nhap(a, n);
	xuat(a, n);

	int vtnn = timvitrinhonhat(a, n);

	printf("\nVi tri chua phan tu nho nhat la %d", vtnn);

	getch();
	return 0;
}


Output:
1
2
3
4
5
6
Line 17: error: conio.h: No such file or directory
Line 5: error: expected ';', ',' or ')' before '&' token
In function 'xuat':
Line 25: error: 'for' loop initial declaration used outside C99 mode
In function 'timvitrinhonhat':
Line 34: error: 'for' loop initial declaration used outside C99 mode


Create a new paste based on this one


Comments:
posted by yonnon on Aug 2
#include<bits/stdc++.h>
#define MAX 100
using namespace std;

void getinfomation(int *arr, int n)
{
for(int i = 0; i < n; ++i)
{
cout<<"Arr["<<i+1<<"]= ";
cin >> arr[i];
}
}

void check(int *arr, int n, int min = 0)
{
min = arr[0];
for (int i = 0 ; i < n; ++i)
{
if( arr[i] < min )
{
min = arr[i];
}
}
for(int i = 0; i < n; ++i)
{
if(min == arr[i])
{
cout<<i+1<<
endl;
}
}
}

int main()
{
int n;
cout <<"Enter your sentence: ";
cin >> n;
int *arr = new int [MAX];
getinfomation(arr,n);
check(arr,n);
return 0;
}
reply
posted by hthao93 on Aug 21
Tai sao lai la i + 1 a
reply
posted by yonnon on Aug 2
#include<bits/stdc++.h>
#define MAX 100
using namespace std;

void getinfomation(int *arr, int n)
{
for(int i = 0; i < n; ++i)
{
cout<<"Arr["<<i+1<<"]= ";
cin >> arr[i];
}
}

void check(int *arr, int n, int min = 0)
{
min = arr[0];
for (int i = 0 ; i < n; ++i)
{
if( arr[i] < min )
{
min = arr[i];
}
}
for(int i = 0; i < n; ++i)
{
if(min == arr[i])
{
cout<<i+1<<
endl;
}
}
}

int main()
{
int n;
cout <<"Enter your sentence: ";
cin >> n;
int *arr = new int [MAX];
getinfomation(arr,n);
check(arr,n);
return 0;
}
reply
posted by luongphongnhan on Oct 25
#include <iostream>
#include "math.h"

#define MAX 100
using namespace std;

void nhapMang(int arr[], int &n) {
do
{
cout << "Press num of arr:";
cin >> n;
if (0 >= n > 100)
{
cout << "Num of integer arr is invalue. Re-Press!! " << endl;
}

} while (0 >= n >100);
for(int i = 0; i <n ; i++)
{
cout << "Press integer of arr " << i << " is: ";
cin >> arr[i];
}
}

void xuatMang(int arr[], int n) {
cout << "Arr imported is: ";
for (int i = 0; i < n; i++)
{
cout << arr[i] << " ";
}
cout << endl;
}

void timVitriMax(int arr[], int n) {
int max = arr[0];
for (int i = 1; i < n; i++)
{
if (arr[i] > max) {
max = arr[i];
}
}
cout << "Vi tri co gia tri lon nhat trong mang la:";
for (int i = 0; i < n; i++)
{
if (arr[i] == max) {
cout << i << " ";
}
}
cout << endl;
}
int main() {
int num;
int Arr[MAX];
nhapMang(Arr, num);
xuatMang(Arr, num);
timVitriMax(Arr, num);
system("pause");
return 0;
}
reply
posted by luongphongnhan on Oct 25
#include <iostream>
using namespace std;
#define MAX 100
void nhapmang(int *arr, int &n) {
do
{
cout << "Moi nhap so phan tu cua mang: ";
cin >> n;
if (0 >= n > 100) {
cout << "Xin moi nhap lai, so phan tu cua mang khong hop le!";
}
} while (0 >= n > 100);
for (int i = 0; i < n; i++)
{
cout << "Moi nhap phan tu thu " << i << "cua mang: ";
cin >> arr[i];
}
}
void xuatmang(int *arr, int n) {
for (int i = 0; i < n; i++)
{
cout << arr[i] << " ";
}
cout << endl;
}

int demNguyenToo(int *arr, int n) {
int dem = 0;
int checkNguyento;
for (int i = 0; i < n; i++)
{
checkNguyento = 0;
for (int j = 1; j < arr[i]; j++)
{
if ((arr[i]) % j == 0) {
checkNguyento += 1;
}
}
if (checkNguyento == 1 && arr[i] <= 100) {
dem += 1;
}
}
return dem;
}

int main() {
int num;
int *Arr= new int[MAX];
nhapmang(Arr, num);
xuatmang(Arr, num);
cout << "So phan tu trong mang la so nguyen to va nho hon 100 la: " << demNguyenToo(Arr, num) << endl;
system("pause");
return 0;
}
reply
posted by lehoangan01 on Feb 25
#include <iostream>
#include <math.h>
#define Max 100
using namespace std;

void get_the_array(int a[], int n){
do{
if (n <= 0 || n > Max){
cout << " invalid valued return";
}
}while (n <= 0 || n > Max);
for(int i = 0; i <= n; i++){
printf("input the value of a[%d]: ",i);
scanf("%i", &a[i]);
}
}

int find_smallest_number(int a[], int n){
int num = a[0];
for (int i = 0; i <= n; i++){
if (a[i] < a[0]){
num = a[i];
}
}
return num;
}

int main(){
int n;
printf("\nNhap so phan tu: ");
scanf("%d", &n);
int a[n];
get_the_array(a, n);
int integer = find_smallest_number(a, n);
int *ip = &integer;
cout << ip;

return 0;
}

reply