[ create a new paste ] login | about

Link: http://codepad.org/roqJ8OYq    [ raw code | output | fork | 11 comments ]

C, pasted on Aug 21:
#include<stdio.h>
#include<conio.h>

int main()
{
	int i, n;
	float S;
	i = 0;
	S = 0;
	do
	{
	printf("\nNhap n: ");
	scanf("%d", &n);
	}while(n < 0 && printf("Error: (n >= 0)\n"));
	while(S + i < n)
	{
		i++;         //
		S = S + i;  // tương đương 1 dòng S += ++i;
	}
		printf("\nGia tri k lon nhat de S(k) = 1 + 2 + ... + k < n la %d", i);
	getch();
	return 0;
}


Output:
1
Line 17: error: conio.h: No such file or directory


Create a new paste based on this one


Comments:
posted by maiphu.2510@gmail.com on Aug 13
#include<stdio.h>
#include<conio.h>
int main()
{
int n,max;
int s=0;
printf("\nNhap n = ");
scanf("%d",&n);
for(int i=1;s<=n;i++)
{
s=s+i;
if(s<n)
{
max=i;
}
}
printf("\ngia tri cua k la : %d",max);
getch();
return 0;
}
reply
posted by mouto9k on Nov 15
//cua ban thi de
for(int i=1;s<=n;i++) hay
for(int i=1;s<n;i++) deu duoc vi gia tri max chi gan cho phan tu i cuoi cung thoa man dieu kien s(k)<n

reply
posted by kid_banz on Sep 29
#include <stdio.h>
#include <conio.h>
int main()
{
int n, i, k, s,m,l=0;
printf("nhap n:");
scanf_s("%d", &n);
for (i = n; i >= 1; i--)
{
for (m = 0; m <= i; m++)
{
l = l + m;
if (l < n)
{
s = l;
k = m;
}

}
printf("ket qua: %d", k);
break;
}

_getch();

}
reply
posted by mouto9k on Nov 15
thuat toan co nhung cho rat khong can thiet
sua lai:
#include <stdio.h>
#include <conio.h>
int main()
{
int n, k,m,l=0;
printf("nhap n:");
scanf("%d", &n);

for (m = 1; m <= n; m++)
{

if(n==1)
return 0;
else
{
l = l + m;
if (l < n)
k = m;
}

}

printf("ket qua: %d", k);

getch();
return 0;
}
reply
posted by freshman on Apr 15
Bai lam sai roi

reply
posted by freshman27 on Apr 15
Bai lam sai roi

reply
posted by freshman27 on Apr 15
Bai lam sai roi

reply
posted by dat160701 on Oct 30
ac có thể giải thích cho e tại sao while(S+i<n) mà while(S<n) lại không được v ạ ??
reply
posted by 19120463 on Dec 8
nếu n=1 thì sao
reply
posted by 19120463 on Dec 8
nếu n=1 thì sao nhỉ
reply
posted by dangtiendat86@gmail.com on Feb 5
#include<iostream>
using namespace std;
main(){
int n;
cout<<"n="; cin>>n;
while (n<1){
cout<<"Nhap lai n="; cin>>n;
}
int t=n,kq;
for (int i=1; i<n; i++){
if(t==i){
kq=i;
break;
}
if(t<i){
kq=i-1;
break;
}
else
t=t-i;
}
cout<<"kq="<<kq<<endl;
}
reply