[ create a new paste ] login | about

Link: http://codepad.org/fMVAYHiN    [ raw code | output | fork | 3 comments ]

C, pasted on Sep 6:
#include<stdio.h>
#include<conio.h>

int main()
{
	/*int S, i, n;
	printf("\nNhap n: ");
	scanf("%d", &n);

	for(i = 1, S = 0; i < n; i+=2)
	{
		S = S + i;
	}
	printf("\nTong = %d", S);*/

	int S, i, n;
	S = 0;
	i = 1;
	printf("\nNhap n: ");
	scanf("%d", &n);
	for(;;)
	{
		S = S + i;
		i = i + 2;
		if(i >= n)
			break;
	}
	printf("\nTong = %d", S);
	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 manhha on Feb 24
#include<stdio.h>
#include<conio.h>
int main(){
int n;
int S = 0;
printf("Nhap vao n\n", n);
scanf("%d", &n);
for (int i = 1 ; i < n; i++)
{
if(i % 2 != 0)
S = S + i;
}
printf("S = %d", S);
getch();
return 0;
}
reply
posted by yonnon on Jul 12
#include<bits/stdc++.h>

using namespace std;
int main(){
int n;
cout <<"Enter your sentence: ";
cin >> n;
int S=0;
for(int i=1; i<n; ++i){
if( i%2 != 0){
S+=i;
}
}
cout<<"Sum= "<<S<<
endl;
return 0;
}
reply
posted by 20223768 on Sep 25
#include <iostream>
using namespace std;
int main()
{
int n; cin >>n;
if (n<=0) cout <<"Nhap lai";
else
{
int sum=0;
for (int i=0; i<=n; i++)
{
if (i%2!=0)
sum+=i;
}
cout << sum;
}
return 0;
}
reply