[ create a new paste ] login | about

Link: http://codepad.org/jeeB4NtP    [ raw code | output | fork | 4 comments ]

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

void nhap (int 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("%d", &a[i]);
	}
}

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

int kiemtra(int a[], int n)
{
	int flag = 0;
	for(int i = 0; i < n; i++)
	{
		if(a[i] % 2 == 0 && a[i] < 2004)
		{
			flag = 1;
		}
	}
	return flag;
}
int main()
{
	int n;
	int a[MAX];
	nhap(a, n);
	xuat(a, n);

	int flag = kiemtra(a, n);
	if(flag == 1)
	{
		printf("\nTim thay !");
	}
	else
	{
		printf("\nKhong tim thay con me gi");
	}

	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 'kiemtra':
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
Clm =)) coi cái dòng printf cuối kìa =))

reply
posted by yonnon on Aug 2
#include<bits/stdc++.h>
#define MAX 100
using namespace std;
struct number
{
int arr;
int maintemp;

void getinfomation()
{
cout << "arr = ";
cin >> arr;
}
};
int main()
{
int n;
int k=0;
cout <<"Enter your sentence: ";
cin >> n;
number *temp= new number[n];
for(int i=0; i < n; ++i)
{
temp[i].getinfomation();
}
for(int i=0; i< n; ++i)
{
if(temp[i].arr < 2004 && temp[i].arr % 2 == 0)
{
temp[i].maintemp = temp[i].arr;
k++;
}
}
if (temp[0].maintemp != NULL )
{
for(int i=0; i < k; ++i)
{
cout<<temp[i].maintemp<<" ";
}
}
else if(temp[0].maintemp == NULL)
{
cout <<"Khong tim thay con me gi";
}
delete[] temp;
return 0;

}
reply
posted by cuong.luucb8921 on Sep 6
#include<stdio.h>
#include<stdbool.h>
int i;

void nhap(int a[], int n)
{
for(i=0;i<n;i++)
{
printf("Nhap vao a[%d] : ", i);
scanf("%d", &a[i]);
}
}

void kiemtra(int a[], int n)
{
bool check = false;
for(i=0;i<n;i++)
{
if(a[i]%2==0 && a[i] < 2004)
{
check = true;
break;
}
}
if(check)
{
printf("Ton tai");
}
else
{
printf("Khong ton tai");
}
}

int main(){
int a [1000];
int n;
printf("Nhap vao n :");
scanf("%d",&n);
nhap(a,n);
kiemtra(a,n);
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 = 1; i <= n; i++){
printf("input the value of a[%d]: ",i);
scanf("%i", &a[i]);
}
}

bool kiem_tra_phan_tu(int a[], int n){
bool num;
for (int i = 1; i <= n; i++ ){
if (a[i] < 2004){
if ( a[i] % 2 == 0){
num = true;
}
else{
num = false;
}
}
else{
break;
}
}
return num;
}

int main(){
int n;
printf("\nNhap so phan tu: ");
scanf("%d", &n);
int a[n];
get_the_array(a, n);

if (kiem_tra_phan_tu(a, n) == true){
cout << "there exist at leat one element that less than 2004";
}
else {
cout << "there's no element less than 2004";
}

return 0;
}

reply