Two digit number is three more than 7 times the sum of it's digits?
If there are two digits than the first one is ten times its value.
So as an algebraic equation we get
10A + B - 3 = 7(A x B)
This can be simplified to
10A + B - 3 = 7A + 7B
and this reduces to
10A - 7A = 7B - B +3
or
3A =6B +3
A solution to this is
3(3) = 6(2) +3
Which would make the original equation
32 = 7(3+2)-3
How do you write macro programs to calculate average of n numbers?
#include<stdio.h>
#define size 100
int main(){
int x[size], sum=0;
float average;
for(int i=0;i<size;i++){
scanf("%d",x[i]);
sum+=x[i];
}
average=sum/size;
printf("The Average is :\t%d",average);
return 0;
}
How can you print prime numbers uing turbo c?
A prime number is a number that has no factors other than 1 and itself. For instance, 1, 2 and 3 are prime numbers. However, 4 isn't because it can also be divided evenly by 2.
Although a complicated floating-point function can be written to test if the division of a number is even, the C modulus operator (%) is far quicker. If 'n' modulus 'm' is zero, then the division is even - there is no fractional component.
Using this rule, the pseudo-code for testing if a number is prime is as follows:
- if number is zero, return false
- if number is less than 4, return true since 1, 2 and 3 are primes
- iterate a variable 'c' from 2 until the number 'n' minus 1
- if n modulus c is zero, return false, since 'n' has 'c' as a factor
- return true
All that remains is converting the above code to C (or any other programming language) using inline code or a function.
How do you code to check whether the input is numeric value or not in C?
I don't know about C but in C++ I would have the compiler do a bool statement for return type (int, float, long, short, signed short, signed long) and have make them true and have it output. I'm still learning myself so this might not be accurate but it's what I would do.
What is the only integer that can be assigned to a string?
If you wanted to ask 'Which is the only numeric value that can be assigned to a pointer?', then the answer would be: 0.
Can someone right a pseudo code to find a gcd of 2 numbers?
while b is not equal to zero
... temp = b
... b = a mod b
... a = temp
return a
Knuth, Donald E. The Art of Computer Programming, Volume 1: Fundamental Algorithms (3rd ed.) (Section 1.2.1: Mathematical Induction, pp. 319-320.)
Convert binary octal 864BF into hexadecimal?
Okay, I'm pretty sure that 864 binary is 30 hexadecimal. - RG
11100011
C program to find whether the given number is prime or not?
int is_prime(int n){
int flag=1;
if(n==1)
return 0;
int root=(int)sqrt(n);
while(root!=1){
if(n%root==0){
flag=0;
break;
}
root--;
}
return flag;
}
How do you display the prime numbers upto n limit in the c program output?
#include<conio.h>
#include<stdio.h>
void main (void)
{
int a,b,c,d;
printf("enter the max limit : ");
scanf("%d",&a);
for(b=1;b<=a;b++)
{
for (c=2;c<b;c++)
{d=b%c;
if (d==0) break;}
if (d!=0) printf("%d\n",b);}
getch();
}
by WAli Ahsan
Ch-007
Prime factors a number using c language?
#include
#include
void main()
{
int n,i;
clrscr();
printf("Enter a Number:");
scanf("%d",&n);
printf("\n\nPrime Factors of %d is: ",n);
for(i=2;i<=n;i++)
{
if(n%i==0)
{
printf("%d,",i);
n=n/i;
i--;
if(n==1)
break;
}
}
getche();
}
this program will find the prime factors of a given number
any assistance
mail at :- devilllcreature@yahoo.com
thank you
This is typically done by importing math.h, and calling the sqrt function.
C program to find both the largest and smallest numbers in the given list without applying array?
I'll assume the list is supplied as arguments to the program:
#include <stdlib.h>
#include <stdio.h>
main (argc, argv)
int argc;
char **argv;
{
int c = 0, mn, mx, z;
while (--argc)
{
z = atoi(*(++argv));
if (!c++) mx = mn = z;
else if (z > mx) mx = z;
else if (z < mn) mn = z;
}
if (c) printf("%d numbers, min = %d, max = %d\n", c, mn, mx);
else printf("No arguments given: please supply a list of numbers as arguments\n");
}
Any error trapping is left as an exercise.
Write a C program to convert hexadecimal number into decimal number?
pongada punda vayanungala ..................
Not tested:
void printPrimes(int n) {
int a = 0, b = 0;
float c = 0.0f;
bool isp = true;
int primes = 0;
while(true) {
a++;
do {
b++;
if(b > 1) {
c = (float)a/(float)b;
if(c = (int)c)
if(b != a) {
isp = false;
break;
}
else
isp=true;
}
} while(b<a);
if(isp) {
primes++;
std::cout << a << endl;
}
if(primes > n)
break;
b = 0;
c = 0;
isp = true;
}
}
void main() {
printPrimes(10);
}
Wap to print prime factor of a number?
import java.io.*; public class p_factor
{
public static void main(String args[])throws IOException
{
int arr[]=new int[50];
int n,i,j=0,k,f=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a number");
n=Integer.parseInt(br.readLine());
for(i=2;i<n;i++)
{
if(n%i==0)
{
arr[j]=i;
j++;
}
}
for(i=0;i<j;i++)
{
for(k=2;k<arr[i];k++)
{
if(arr[i]%k==0)
{
f=1;
}
}
if(f==0)
{
System.out.println(arr[i]);
}
}
}
}
How do you convert binary number base2 to decimal base10?
Multiply the digit to the left of the "decimal" point by 2^0 = 1.
Multiply the digit to the left of it by 2^1 = 2
Multiply the digit to the left of that by 2^2 = 4 and so on.
Also
Multiply the digit to the right of the "decimal" point by 2^(-1) = 1/2.
Multiply the digit to the right of that by 2^(-2) = 1/4 and so on.
Add all these together.
Example:
Binary 1101.1011
1*2^3 = 1*8 = 8
1*2^2 = 1*4 = 4
0*2^1 = 0*2 =0
1*2^0 = 1*1 = 1
1*2^-1 = 1*1/2 = 0.5
0*2^-2 = 0*1/4 = 0
1*2^-3 = 1*1/8 = 0.125
1*2^-4 = 1*1/16 = 0.0625
Sum = 13.6875
Happiness
How can you generate a palindrome from a given number?
You write the number and then follow it with the digits in reverse order.
What is the value of 1928 series b serial g22292336a?
Please post a new question with the bill's denomination and condition. Note that the serial number is unimportant to its value.
C program to find LCMof three integers?
int LCM3 (int a, int b, int c)
{
return LCM2 (a, LCM2 (b, c));
}
int LCM2 (int a, int b)
{
return a*b/GCD2(a, b);
}