vickybat
I am the night...I am...
codechef gives this as a runtime error too
Just use float instead of long mate.
The value is getting rounded as long datatype doesn't support decimal values, just like int.
codechef gives this as a runtime error too
what does the thing in bold mean?int main() {
ifstream f("Words.cpp");
int nwords = 0;
string word;
while (f >> word)
++nwords;
cout << "Number of words = " << nwords << endl;
}
what does the thing in bold mean?
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
fstream file;
string line;
file.open("E:\\abc.txt", ios::in);
while(getline(file, line))
cout << line << endl;
return 0;
}
Yes you can do it using string.
PHP:#include <iostream> #include <fstream> using namespace std; int main() { fstream file; string line; file.open("E:\\abc.txt", [B]ios::in[/B]); while(getline(file, line)) cout << line << endl; return 0; }
why php? what is ios::in??
tag. Edited it :wink:
ios::in is the file opening mode. When you open a file, you have to specify the opening mode. It can be read only, white only, append with in, out, app being their specifiers. These file openning specifiers reside in ios class (not sure if its a class), hence, the use of ios::in. If the file were to be apened for writing only, then it would be ios::out.
please suggest a C/C++ software for ubuntu (linux).
I am new to ubuntu.
So please suggest a good software with compiler with download links.
also tell me some good softwares for linux.
please suggest a C/C++ software for ubuntu (linux).
I am new to ubuntu.
So please suggest a good software with compiler with download links.
also tell me some good softwares for linux.
/*
Fourth problem
input -> num year
output -> if leap year -> true , else -> false (write proper interface)
conditions of leap year : divisible by 4 !by 100 but by 400
*/
#include<iostream>
using namespace std;
int main()
{
int year,limb1,limb10,limb40;
cout<<"Program to tell whether a given year is a leap year or not.\nPlease enter the year to be checked.\n\t";
cin>>year;
limb1=year%4;
if (limb1 == 0)
{
limb10 = year%100;
limb40 = year%400;
if (limb40 == 0)
{
if (limb10 > 0)
{
cout<<year<<" is a leap year.\n";
}
else if (limb10 == 0)
{
cout<<year<<" is not a leap year.\n";
}
}
else
{
cout<<year<<" is not a leap year.\n";
}
}
else
{
cout<<year<<" is not a leap year.\n";
}
return 0;
}
Can anyone tell me why this program only prints "<year> is not a leap year." ?
Code:cin>>year; limb1=year%4; if (limb1 == 0) { [B]limb10 = year%100; limb40 = year%400;[/B] if (limb40 == 0)
It was a logical error on my part. Corrected here : C/C++ Thread
how is it solved by a single statement ?
condition of a leap year are specified in the program comments.
conditions of leap year : divisible by 4 !by 100 but by 400
int main(){
int T;
long int R;
long int x1,y1;
long int x2,y2;
long int x3,y3;
long int d1,d2,d3;
scanf("%d",&T);
while(T > 0) {
scanf("%d",&R);
scanf("%d %d",&x1,&y1);
scanf("%d %d",&x2,&y2);
scanf("%d %d",&x3,&y3);
R = pow(R,2);
d1 = pow((x1-x2),2) + pow((y1-y2),2);
d2 = pow((x1-x3),2) + pow((y1-y3),2);
d3 = pow((x2-x3),2) + pow((y2-y3),2);
if((d1 <= R && d2 <= R) || (d2 <= R && d3 <= R) || (d1 <= R && d3 <= R)) {
printf("yes\n");
} else {
printf("no\n");
}
T--;
} /* while */
return 0;
}
int main(){ int test;
float x1,x2,x3,y1,y2,y3,r;
float dis1,dis2,dis3;
cout<<"enter test cases";
cin>>test;
while(test--)
{
cin>>r>>x1>>y1>>x2>>y2>>x3>>y3;
dis1= pow((x1-x2),2) + pow((y1-y2),2);
dis2=pow((x2-x3),2)+ pow((y2-y3),2);
dis3=pow((x1-x3),2)+pow((y1-y3),2);
r=pow(r,2);
if((dis1<=r && dis2<=r)||(dis1<=r && dis3<=r)||(dis3<=r && dis2<=r))
cout<<"yes";
else
cout<<"no";
}
return 0;
}