Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as C++ by Majed ( 5 years ago )
//first question=All Possible Values
#include<iostream>
using namespace std;
int main() {
int s,max=0;
cin>>s;
for(int i=0;i<=s;i++)
for(int j=0;j<=s;j++)
for(int k=0;k<=s;k++)
if((i+j+k)==s)
max++;
cout<<max;
return 0;
}
...................................................
2=guessing game 3
#include<iostream>
using namespace std;
int main() {
int t,g1,g2,g;
cin>>t;
while(t--){
cin>>g1>>g2;
for(int i=1; ; i++){
cin>>g;
if(g1-g2==g){
cout<<"Well guessed! the number of tries = "<<i<<endl;
break;
}
else if((g1-g2)>g)
cout<<"Sorry, the number is low. Try again."<<endl;
else
cout<<"Sorry, the number is high. Try again."<<endl;
}
cout<<endl;
}
return 0;
}
..............................................................
third question
#include <iostream>
using namespace std;
bool prime(int n){
for(int i=2;i*i<=n;i++){
if(n%i==0)
return false;
}
return true;
}
int thirdnum(int a,int b){
int sum=0,temp=0;
sum=a+b;
temp=1;
if(sum&1){
temp=2;
}
while(!prime(sum+temp)){
temp+=2;
}
return temp;
}
int main() {
int test;
cin>>test;
for(int i=0;i<test;i++){
int x,y;
cin>>x>>y;
cout<<thirdnum(x,y)<<"\n";
}
return 0;
}
........................................................
last question.....
#include <iostream>
using namespace std;
// nor=normal
int main() {
int g,n,age,d;
cin>>g;
for(int i=1;i<=g;i++){
int risk=0,nor=0;
cin>>n>>d;
for(int j=1;j<=n;j++){
cin>>age;
if(age>=80 || age<=9)
risk++;
}
nor=n-risk;
int tot=risk/d +nor/d;
if(nor%d !=0) tot++;
if(risk%d !=0)tot++;
cout<<"Require days in governorate "<<i<<" is: "<<tot;
if(i!=g)
cout<<endl;
}
return 0;
}
Revise this Paste