Programme to find the count of each digit in a number using while loop?
Implement this method in Java:
public static int[] countNums(int n) {
int x = n;
int[] nums = new int[10];
while(x != 0) {
nums[x % 10]++;
x /= 10;
}
return nums;
}
That will return an array of the counts of the digits from 0 to 9.
How do you convert octal to binary with 2 decimal nos?
The conversion of octal number to binary can be obtained by using two methods. First, it can be converted into decimal and then obtained decimal is converted into binary. In the second method
What do you mean by a mod function?
A modulo function finds the remainder term when you divide one number by another number.
For example, if you divide 20 by 3 you're left with a remainder term of 2.
So 20 mod 3 = 2.
If you divide 21 by 3 you're left with no remainder term.
So 21 mod 3 = 0.
Write a program in C to print 1 to10 as 1 2 3 4 5 6?
int main() { for(int i = 1; i <= 10; i++)
printf("%d ", i);
return 0;
}
How do you convert Binary-to-Decimal and Decimal-to-Binary?
You can use a table to convert binary to decimal & back:
MSBBinary DigitLSB2827262524232221202561286432168421
Figure out the greatest power that will fit into the number you want to convert to binary. Move to the next lower power of two. If you can fit into the next lower number write down a "1", if it can't put down "0". Put together the binary answer.
How do you find the largest of 3 numbers in computer programming?
To find the largest of three numbers you must first find the largest of two numbers:
int max (int a, int b) { return a>b?a:b; // or, equivalently: if (a>b) return a; else return b;
}
Now we can use this function to find the maximum of three:
int max3 (int a, int b, int c) {
return max (max (a,b), c);
}
How do you calculate the volume of a circle?
Circles do not have volume because they are 2 dimensional. The area of a circle is PI*r2 . A sphere has volume and the volume of a sphere is 4/3*pi*r3 where r is the radius.
Hexadecimal B = Decimal 11. Otherwise, the question is too ambiguous.
What is the Program to find sum of first YT odd natural numbers in c?
Writing answers used to be enough.
Now we have to fix the questions too.
I think it's supposed to be 76, but who can really know.
ahhh, proofreading, it's such a lost art . . .
C program to find sum of two sparse matrices?
#include <stdio.h> #include <stdlib.h> typedef struct node { int column; int value; int row; struct node *next; } element; /* MENU */ void Menu() { printf("\n***\tADDING SPARSE MATRICES\t***\n"); printf("\n 1.) Insert in A"); printf("\n 2.) Insert in B"); printf("\n 3.) Printout both"); printf("\n 4.) A + B = "); printf("\n 0.) EXIT"); printf("\nChoose ---------> "); } /* Initialize*/ void Init (element *x[]) { int i; for (i=0; i<3; i++) x[i] = NULL; } /* Printout */ void Printout (element *x[]) { int i, test = 0; element *temp; for (i=0; i<3; i++) { temp = x[i]; while (temp != NULL) { printf("Element position (%d,%d) = %d\n", i, temp->column, temp->value); test = 1; temp = temp->next; } } if (test == 0) printf("This matrix is empty!!\n"); } /* INSERT */ void Insert(element *x[], int row, int column, int value) { int r = row; element *p; element *new = malloc(sizeof(element)); new->row = row; new->column = column; new->value = value; if (x[r] == NULL) { x[r] = new; new->next = NULL; } else { p = x[r]; if (new->column < p->column) { new->next = p; x[r] = new; } else if (new->column > p->column) { while (p->next != NULL && p->next->column < new->column) { p = p->next; } new->next = p->next; p->next = new; } else printf("An element already exists there!!\n"); } } /* A + B */ void Add (element *x[],element *y[],element *z[]) { int i; element *p, *q; for (i=0; i<3; i++) { /*row of x empty, row of y not*/ if (x[i] == NULL && y[i] != NULL) { q = y[i]; while (q != NULL) { Insert(z, i, q->column, q->value); q = q->next; } } /*row of y empty, row of x not*/ if (x[i] != NULL && y[i] == NULL) { q = x[i]; while (q != NULL) { Insert(z, i, q->column, q->value); q = q->next; } } /*row of x and y not empty*/ if (x[i] != NULL && y[i] != NULL) { p = x[i]; q = y[i]; /*stay in while loop until one row runs out*/ while (p != NULL q != NULL) { /*columns match*/ if (p->column == q->column && p != NULL && q != NULL) { Insert(z, i, p->column , p->value + q->value); p = p->next; q = q->next; } /*column of x is smaller than column of y*/ else if (p->column < q->column) { Insert(z, i, p->column , p->value); p = p->next; } /*column of x is bigger than column of y*/ else { Insert(z, i, q->column , q->value); q = q->next; } } /*if row of x had more elements and didn't run out*/ if (p != NULL) { while (p != NULL) { Insert(z, i, p->column , p->value); p = p->next; } } /*if row of x had more elements and didn't run out*/ if (q != NULL) { while (q != NULL) { Insert(z, i, q->column , q->value); q = q->next; } } } } Printout(z); } /* FREE MEMORY*/ void Freedom (element *x[]) { int i; element *p; for (i=0; i<3; i++) { if (x[i] != NULL) { p = x[i]; x[i] = x[i]->next; free(p); } } } /* MAIN */ int main (int argc, const char * argv[]) { int choice, column, row, value, number; element *a[3], *b[3], *sum[3]; Init(a); Init(b); Init(sum); do { Menu(); scanf("%d",&choice); switch (choice) { case 1: /*Insert in A */ do { printf("Enter row -> "); scanf("%d",&row); } while (row < 0 row > 3); do { printf("Enter column -> "); scanf("%d",&column); } while (column < 0); printf("Enter value -> "); scanf("%d",&value); Insert(a,row,column,value); break; case 2: /*Insert in B */ do { printf("Enter row -> "); scanf("%d",&row); } while (row < 0 row > 2); do { printf("Enter column -> "); scanf("%d",&column); } while (column < 0); printf("Enter value -> "); scanf("%d",&value); Insert(b,row,column,value); break; case 3: /* Printout A & B */ printf("\n::::::: MATRIX A :> \n\n"); Printout(a); printf("\n::::::: MATRIX B :> \n\n"); Printout(b); break; case 4: /* A + B */ Init(sum); printf("\n::::::: MATRIX A + B :> \n\n"); Add(a,b,sum); break; default: printf("\nWRONG CHOICE"); } } while (choice != 0); Freedom(a); Freedom(b); Freedom(sum); return 0;
}
Write a c program to find factors of given number?
#include<stdio.h>
void findfact(int num)
{
int i;
for(i=1;i<num;i++)
{
if(num%i==0)
printf("Factor for %d is %d\n",num,i);
}
}
main()
{
int a;
printf("\nEnter a number:");
scanf("%d",&a);
findfact(a);
}
Program in c finding average of two and three digits nos?
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k,a[10],n;
clrscr();
scanf("%d",&n);
for(i=0;i<3;i++)
{
n=n%10;
j=0;
a[j]=n;
j++;
}
for(j=0;j>3;j++)
{
a[k]=0;
a[k]=a[k]+a[j];
avg=(a[k]/3);
printf("the average value of digit will be %d",avg);
}
getch();
}
}
What type of application would you use if the data set is non-numerical?
Non-parametric statistical methods.
Program in c find the largest number out of ten with the help of for loop?
largestNum = 0;
for ( i = 0; i < 10 ; i++)
{
if ( currentNum[i] > largestNum)
largestNum = currentNum[i];
}
How do you check whether the given number is Armstrong or not?
First, review the definition of an Armstrong, or narcissistic, number:
"...is a number that is the sum of its own digits each raised to the power of the number of digits."
So, you need to count the digits (to know what power to use), and extract the individual digits. This can be done in several ways; for example, you might convert the number to a string. In Java:
String numberAsString = "" + number;
Now it should be easy to figure out the length of the String (use the .length() method), and to extract the individual digits - check the methods available for strings. Then you need to convert the digits back to numeric data.
Another way is to get one digit at a time, starting from the right, using the "%" operator.
For example, 153 % 10 is equal to 3. Divide the number, 153, by 10 (integer division), then repeat to get the remaining digits. You might store the digits to an array.
First, review the definition of an Armstrong, or narcissistic, number:
"...is a number that is the sum of its own digits each raised to the power of the number of digits."
So, you need to count the digits (to know what power to use), and extract the individual digits. This can be done in several ways; for example, you might convert the number to a string. In Java:
String numberAsString = "" + number;
Now it should be easy to figure out the length of the String (use the .length() method), and to extract the individual digits - check the methods available for strings. Then you need to convert the digits back to numeric data.
Another way is to get one digit at a time, starting from the right, using the "%" operator.
For example, 153 % 10 is equal to 3. Divide the number, 153, by 10 (integer division), then repeat to get the remaining digits. You might store the digits to an array.
First, review the definition of an Armstrong, or narcissistic, number:
"...is a number that is the sum of its own digits each raised to the power of the number of digits."
So, you need to count the digits (to know what power to use), and extract the individual digits. This can be done in several ways; for example, you might convert the number to a string. In Java:
String numberAsString = "" + number;
Now it should be easy to figure out the length of the String (use the .length() method), and to extract the individual digits - check the methods available for strings. Then you need to convert the digits back to numeric data.
Another way is to get one digit at a time, starting from the right, using the "%" operator.
For example, 153 % 10 is equal to 3. Divide the number, 153, by 10 (integer division), then repeat to get the remaining digits. You might store the digits to an array.
First, review the definition of an Armstrong, or narcissistic, number:
"...is a number that is the sum of its own digits each raised to the power of the number of digits."
So, you need to count the digits (to know what power to use), and extract the individual digits. This can be done in several ways; for example, you might convert the number to a string. In Java:
String numberAsString = "" + number;
Now it should be easy to figure out the length of the String (use the .length() method), and to extract the individual digits - check the methods available for strings. Then you need to convert the digits back to numeric data.
Another way is to get one digit at a time, starting from the right, using the "%" operator.
For example, 153 % 10 is equal to 3. Divide the number, 153, by 10 (integer division), then repeat to get the remaining digits. You might store the digits to an array.
Explain how to use an array to find 3 x 19?
printf ("3*19 is %d\n", sizeof (char [19][3]));
Warning: never do this in an actual program!
Write a c program to find the sum of numbers between given limits?
int sum (int min, int max) {
return (max-min+1)*(max+min)/2;
}
How do i write An equation that shows the number 3 is a function of number 18?
There are many ways that the number 3 can be written as a function of the number 18. A function of any number (x) is often called f(x).
Let's say that f(x)=k.
So, in this case, x=18 and k=3. In other words, f(18)=3.
Now, you have to think of an equation that could relate the two numbers. For example, the easiest way to show how 3 is related to 18 is to show that 3 times 6 equals 18. Therefore, you could write that 3 = 18/6. And this equation proves that the number 3 is a function of the number 18.