#include<iostream>
#include<time.h>
// return a reference to the largest of two objects of the same type
template<typename T>T& largest (T& a, T& b) {
return a<b?b:a;
}
int main() {
// seed the random number generator
srand ((unsigned) time (0));
// repeat 10 times
for (size_t loop=0; loop<10; ++loop)
{
// select two random integers
int x = rand()%10;
int y = rand()%10;
// print the result
if (x==y)
cout << x << " & " << y << " are equal" << endl;
else
cout << "The largest of " << x << " & " << y << " is " << largest (x,y) << endl;
} // end for loop
}
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("Enter the 1st No.: ");
scanf("\n%d",&a);
printf("Enter the 2nd No.: ");
scanf("\n%d",&b);
if (a=b)
{
printf("The numbers are equal");
}
else if (a>b)
{
printf("The 1st No. is big");
}
else
{
printf("The 2nd No. is big");
}
getch();
}
\\This is the program to find whether the entered no.s are same, greater or smaller.
#include<stdio.h>
void main()
{
int a,b;
printf("enter two numbers");
scanf("%d %d",&a,&b);
if(a==b)
{
printf("2 numbers are equal");
}
else
{
printf("not equal");
}
}
Accept 3 natural numbers and check whether it firms pythagorean triplet
/* c program for how many of the numbers from 1 to 10 is greater than 4? */#includevoid main(){int i ,j=0; /* j is used for counting the nos greater than 4 from 1 to 10*/for(i=1;i4)j++;printf("\n The numbers greater than 4 , from 1 to 10 is %d",j);}Algorithmstep 1:startstep 2 :initialize j=0step 3 :Initialize i=1,check whether i < 10 ,if true increment i else go to step 6step 4: check whether i >4 If true go to step5 ,else go to step 3step 5 :Increment j and then go to step 3step 6:print the value of jstep 7 :Stop
Loop through some numbers - for example, 2 through 100 - and check each one whether it is a prime number (write a second loop to test whether it is divisible by any number between 2 and the number minus 1). If, in this second loop, you find a factor that is greater than 1 and less than the number, it is not a prime, and you can print it out.
Active Time spent online
To write a C program to determine if something is odd or even you need to be a programmer. To write a program in C is complicate and only done by programmers.
Accept 3 natural numbers and check whether it firms pythagorean triplet
Check whether the largest of the numbers is greater than or equal to the sum of the other two. If it is, then you can't make a triangle; otherwise you can.
Pick out the largest number, and check whether it is less than the sum of the other two numbers. If it is less, then you can. If it is greater or equal, then you can't.
write a c++program by using if statement to read a number and check whether it is positive or negative
/* c program for how many of the numbers from 1 to 10 is greater than 4? */#includevoid main(){int i ,j=0; /* j is used for counting the nos greater than 4 from 1 to 10*/for(i=1;i4)j++;printf("\n The numbers greater than 4 , from 1 to 10 is %d",j);}Algorithmstep 1:startstep 2 :initialize j=0step 3 :Initialize i=1,check whether i < 10 ,if true increment i else go to step 6step 4: check whether i >4 If true go to step5 ,else go to step 3step 5 :Increment j and then go to step 3step 6:print the value of jstep 7 :Stop
Going through a program on paper to check whether it has errors.
samsung
You need to check whether they have a common factor. You can simply factor each of the numbers; for numbers that are much larger, using Euclid's algorithm is much faster.If the common factor of two numbers is greater than 1, then they are NOT relatively prime.
To check whether it is an arithmetic sequence, verify whether the difference between two consecutive numbers is always the same.To check whether it is a geometric sequence, verify whether the ratio between two consecutive numbers is always the same.
You can check each individual number, whether it is a prime number. For numbers below 100, it is enough to check whether they are divisible by 2, by 3, by 5, and by 7. If a number is divisible by none of these, it is a prime number.
write a shell program for finding out gcd of three given numbers? write a shell program for finding out gcd of three given numbers? write a shell program for finding out gcd of three given numbers? check bellow link http://bashscript.blogspot.com/2009/08/gcd-of-more-than-two-numbers.html
Use the Exception class and type converters.