Write a c program to Calculate the average of five entered number from keyboard?
Sample code is as follows:
#include <stdio.h>
void main()
{
int i = 0;
int final_number = 0;
int array[] = {1,2,3,4,5};
for(i = 0; i < (sizeof(array)/sizeof(array[0])); i++)
{
final_number += array[i];
}
printf("Sum = %d and average = %d", final_number, (final_number / i));
}
A c comma c plus plus program that can accept first name surname and display it?
int main()
{
std::string first, last;
std::cout << "Enter your first name: ";
std::cin >> first;
std::cout << "Enter your last name: ";
std::cin >> last;
}
Can you use extern and static together?
Storage classes are used to indicate duration and scope of a variable or identifier. Duration indicates the life span of a variable. Scope indicates the visibility of the variable. The static storage class is used to declare an identifier that is a local variable either to a function or a file and that exists and retains its value after control passes from where it was declared. This storage class has a duration that is permanent. A variable declared of this class retains its value from one call of the function to the next. The scope is local. A variable is known only by the function it is declared within or if declared globally in a file, it is known or seen only by the functions within that file. This storage class guarantees that declaration of the variable also initializes the variable to zero or all bits off. The extern storage class is used to declare a global variable that will be known to the functions in a file and capable of being known to all functions in a program. This storage class has a duration that is permanent. Any variable of this class retains its value until changed by another assignment. The scope is global. A variable can be known or seen by all functions within a program.
Enqueue and dequeue in data structures?
The queue insert operation is known is enqueue.
A queue has two ends namely REAR & FRONT. After the data has been inserted in a queue ,the new element becomes REAR.The queue deletion operation is known as dequeue.
The data at the front of the queue is removed .
Abstract data type that store a whole numbers?
All data types can be used to store a whole number, even the data types that can store a decimal number.
How do you write a C program to print all combinations of a 3-digit number?
Mathematically-speaking there is only one combination of a 3-digit number. When dealing with a combination of digits, the order of those digits does not matter, thus 123 and 321 are the exact same combination. If the order of the digits is important then it is a permutation, not a combination. That is, 123 and 321 are completely different permutations of the same combination of digits.
The confusion is understandable given that we commonly refer to a combination lock instead of a permutation lock. Mathematically speaking, a combination lock that unlocks with the code 123 would also unlock with the codes 132, 213, 231, 312 and 321, because all six permutations of the digits 1, 2 and 3 are in fact the same combination. Some combination locks really do work this way, however the vast majority are actually permutation locks; we call them combination locks simply because we don't normally use the term "combination" in the much stricter mathematical sense.
To restate the question: How do you write a C program to print all permutations of a 3-digit number?
A 3-digit number has 6 permutations, thus we can print all six by treating the number as an array, and printing all 6 permutations of the array:
void print_permutations (int num) { char set[3];
int index;
if (num<100 num > 999) return; // not a 3-digit number
index = 0;
while (num>0) {
set[index] = num % 10; // least-significant digit
num /= 10; // shift all digits one position to the right
}
// sort the array in ascending order
if (set[0]>set[1]) set[0]^=set[1]^=set[0]^=set[1];
if (set[1]>set[2]) set[1]^=set[2]^=set[1]^=set[2];
if (set[0]>set[1]) set[0]^=set[1]^=set[0]^=set[1];
// print the permutations
printf ("%d%d%d\n", set[0], set[1], set[2]); printf ("%d%d%d\n", set[0], set[2], set[1]); printf ("%d%d%d\n", set[1], set[0], set[2]);
printf ("%d%d%d\n", set[1], set[2], set[0]);
printf ("%d%d%d\n", set[2], set[0], set[1]);
printf ("%d%d%d\n", set[2], set[1], set[0]);
}
The problem with this is when the 3-digit number contains duplicate digits. This would treat 100 as if it had 6 permutations when it really only has 3 {100, 010 and 001}, while 111 only has one permutation {111}. These must be treated as being special cases:
void print_permutations (int num) {
char set[3];
int index;
if (num<100 num > 999) return; // not a 3-digit number
index = 0;
while (num>0) {
set[index] = num % 10; // least-significant digit
num /= 10; // shift all digits one position to the right
}
// sort the array in ascending order
if (set[0]>set[1]) set[0]^=set[1]^=set[0]^=set[1]; // move larger of 1st and 2nd digit to middle
if (set[1]>set[2]) set[1]^=set[2]^=set[1]^=set[2]; // move larger of 2nd and 3rd digit to end
if (set[0]>set[1]) set[0]^=set[1]^=set[0]^=set[1]; // move larger of 1st and 2nd digit to middle
// print the permutations (handle special cases where digits are duplicated)
if (set[0]==set[1] && set[0]==set[2]]) { // same three digits (one permutation)
printf ("%d%d%d\n", set[0], set[1], set[2]);
} else if (set[0]==set[1]) { // first two digits are the same (three permutations)
printf ("%d%d%d\n", set[0], set[1], set[2]); // same as 1, 0, 2
printf ("%d%d%d\n", set[0], set[2], set[1]); // same as 1, 2, 0
printf ("%d%d%d\n", set[2], set[0], set[1]); // same as 2, 1, 0
} else if (set[1]==set[2]) { // last two digits are the same (three permutations)
printf ("%d%d%d\n", set[0], set[1], set[2]); // same as 0, 2, 1
printf ("%d%d%d\n", set[1], set[0], set[2]); // same as 2, 0, 1
printf ("%d%d%d\n", set[2], set[1], set[0]); // same as 1, 2, 0
} else { // all three digits are unique (6 permutations)
printf ("%d%d%d\n", set[0], set[1], set[2]);
printf ("%d%d%d\n", set[0], set[2], set[1]);
printf ("%d%d%d\n", set[1], set[0], set[2]);
printf ("%d%d%d\n", set[1], set[2], set[0]);
printf ("%d%d%d\n", set[2], set[0], set[1]);
printf ("%d%d%d\n", set[2], set[1], set[0]);
}
}
How does a natural arch change into a stack?
the sea erodes the stack to such a point until the wasn't enough suport and the roof colapsed making the arch become a stack.
Write a c program to print the following output using for loop 1 2 2 333 4444 55555?
int main()
{
int i,j,sum,k;
for(i=1;i<=5;i++)
{
k=1;
sum =0;
for(j=1;j<=i;j++)
{
sum = sum+(i*k);
k=k*10;
}
cout<< sum;
cout<< "\n";
}
}
What is the difference between nodes and inter node?
The node is the part of the stem of the plant from which leaves, branches, and aerial roots emerge.
There are many nodes on a plant stem. The distance between each node is called the inter node.
What are the Various compilers of different language?
A program that translates source code into object code. The compiler derives its name from the way it works, looking at the entire piece of source code and collecting and reorganizing the instructions. Thus, a compiler differs from an interpreter, which analyzes and executes each line of source code in succession, without looking at the entire program. The advantage of interpreters is that they can execute a program immediately. Compilers require some time before an executable program emerges. However, programs produced by compilers run much faster than the same programs executed by an interpreter.
Every high-level programming language (except strictly interpretive languages) comes with a compiler. In effect, the compiler is the language, because it defines which instructions are acceptable.
Because compilers translate source code into object code, which is unique for each type of computer, many compilers are available for the same language. For example, there is a FORTRAN compiler for PCs and another for Apple Macintosh computers. In addition, the compiler industry is quite competitive, so there are actually many compilers for each language on each type of computer. More than a dozen companies develop and sell C compilers for the PC.
Write a c program to generate student mark details using union and find total and average and grade?
write a c program to display marks,total,average,grade using union
auto break case char const continue default do double else enum extern float for goto if int long register return short signed sizeof static struct switch typedef union unsigned void volatile while
Why is quick sort and merge sort called stable algorithms?
Quick sort is not stable, but stable versions do exist. This comes at a cost in performance, however.
A stable sort maintains the order of equal elements. That is, equal elements remain in the same order they were input. An unstable sort may change the order. In some cases, the order of equal elements is of no consequence, but when two elements with different values have the same sort key, then order can be important.
What is the difference between argument and parameter?
The term parameter refers to any declaration within the parentheses following the function name in a function declaration or definition; the term argument refers to any expression within the parentheses of a function call.
1.parameter used in procedure defination
2.arguments used in procedure call
This example demonstrates the difference between a parameter and an argument:
void foo(int a, char b); //a and b are parameters,
here procedure is define
int main()
{
foo(5, 'a'); //5 and 'a' are arguments,
here procedure is called
return 0;
}
Different types of sorting techniques in c language?
types of sorting in c language are:
insertion sort
selection sort
bubble sort
merge sort
two way merge sort
heap sort
quick sort
How do you run c program in dos prompt?
Compile it, link it to an executable, then just enter its name and it starts running.
Wap to merge two arrays using c?
#include<stdio.h>
void main()
{
int a[5],b[5];
int c[10];
int i,j,temp,k;
printf("\n enter the elements of array A:=\n");
for(i=0;i<5;i++)
scanf("%d",&a[i]);
printf("\n enter the elements of array B:=\n");
for(i=0;i<5;i++)
scanf("%d",&b[i]);
for(i=1;i<5;i++)
{
for(j=0;j<5-i;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
for(j=0;j<5-i;j++)
{
if(b[j]>b[j+1])
{
temp=b[j];
b[j]=b[j+1];
b[j+1]=temp;
}
}
}
printf("\n the elements of the array A:=\n");
for(i=0;i<5;i++)
printf("%d\t",a[i]);
printf("\n the elements of the array B:=\n");
for(i=0;i<5;i++)
printf("%d\t",b[i]);
i=0,j=0,k=0;
while(i<5&&j<5)
{
if(a[i]>b[j])
c[k++]=b[j++];
if(a[i]<b[j])
c[k++]=a[i++];
}
if(i<5&&j==5)
while(i<5)
c[k++]=a[i++];
if(i==5&&j<5)
while(j<5)
c[k++]=b[j++];
printf("\n the elements of the sorted merged array C:=\n");
for(i=0;i<10;i++)
printf("%d\t",c[i]);
}
How will you Write a c program to find the kth smallest element in an array in c?
//This is for kth largest element. (So this is for n-k smallest element) //Sudipta Kundu [Wipro Technologies] #include <stdio.h> //Input: array with index range [first, last)
//Output: new index of the pivot. An element in the middle is chosen to be a pivot. Then the array's elements are
//placed in such way that all elements <= pivot are to the left and all elements >= pivot are to the right.
int positionPivot(int* array, int first, int last); //Input: array with index range [first, last) and integer K (first <= K < last)
//Output: array whose Kth element (i.e. array[K]) has the "correct" position. More precisely,
//array[first ... K - 1] <= array[K] <= array[K + 1 ... last - 1]
void positionKthElement(int* array, int first, int last, int k); int main() {
int array[] = {7,1,8,3,1,9,4,8};
int i;
for (i = 0; i < 8; i++) {
positionKthElement(array, 0, sizeof(array) / sizeof(array[0]),i);
printf("%d is at position %d\n", array[i], i);
}
return 0;
}
int positionPivot(int* array, int first, int last) {
if (first last)
return first; int tmp = (first + last) / 2;
int pivot = array[tmp];
int movingUp = first + 1;
int movingDown = last - 1;
array[tmp] = array[first];
array[first] = pivot;
while (movingUp <= movingDown) {
while (movingUp <= movingDown && array[movingUp] < pivot)
++movingUp;
while (pivot < array[movingDown])
--movingDown;
if (movingUp <= movingDown) {
tmp = array[movingUp];
array[movingUp] = array[movingDown];
array[movingDown] = tmp;
++movingUp;
--movingDown;
}
}
array[first] = array[movingDown];
array[movingDown] = pivot;
return movingDown;
} void positionKthElement(int* array, int first, int last, int k) {
int index;
while ((index = positionPivot(array, first, last)) != k) {
if (k < index)
last = index;
else
first = index + 1;
}
}
Types of data in reseach methodology?
experimental, survey,non creative and secondary analysis research, last analysis of quantitative data.
C program to calculate percentage of 3 subject marks?
#include
#include
void main()
{
float avg(int m1,int m2,int m3);
clrscr();
printf("\nAverage of 3 Subjects: %.2f",avg(78,85,95));
getch();
}
float avg(int m1,int m2,int m3)
{
return (m1+m2+m3)/3;
}
Implementation of stack using recursion?
public void reverse(Stack st)
{
int m = (int)st.Pop();
if (st.Count != 1)
reverse(st);
Push(st , m);
}
public void Push(Stack st , int a)
{
int m = (int)st.Pop();
if (st.Count != 0)
Push(st , a);
else
st.Push(a);
st.Push(m);
}
What are the Advantages of files in C language?
data files are permanent storage. where as normal data types are volatile, they will save the values as long as the program runs. saving a file will provide us the flexibility to recover the saved data whenever required.
What is the maximum number of nodes that you can have on a stack linked list?
You can have as many as you can fit in memory, which is dependent on size of each node, OS, amount of RAM, etc.
Two linked list in a array is possible?
Like this:
#define MAXLIST 100
int first, next [MAXLIST];
/* let the list be: #0 ---> #2 ---> #1 */
first= 0;
next[0]= 2;
next[2]= 1;
next[1]= -1; /* means end of list */
Note: you should track which elements are unused,
in the beginning every elements are unused:
int first_unused= 0;
for (i= 0; i<MAXLIST; ++i) next[i]= i+1;
next[MAXLIST-1]= -1; /* means end of list */