Write a program to delete an array element in c?
Enter how many elements you want to enter: 4
Enter the array elements:
10
20
30
40
Enter the location, where you want to delete: 3
Deleted value : 30
The new element list: 10 20 40
What Library and linking of turbo c?
Technically speaking, you can create a useful, functional C program that consists solely of statements involving only the C keywords. However, this is quite rare because C does not provide keywords that perform such things as input/output (I/O) operations, high-level mathematical computations, or character handling.
for more details visit:
http://free4ebook.com/The%20Library%20and%20Linking.html
C program to calculate First and Follow?
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char t[5],nt[10],p[5][5],first[5][5],temp;
int i,j,not,nont,k=0,f=0;
clrscr();
printf("\nEnter the no. of Non-terminals in the grammer:");
scanf("%d",&nont);
printf("\nEnter the Non-terminals in the grammer:\n");
for(i=0;i<nont;i++)
{
scanf("\n%c",&nt[i]);
}
printf("\nEnter the no. of Terminals in the grammer: ( Enter e for absiline ) ");
scanf("%d",¬);
printf("\nEnter the Terminals in the grammer:\n");
for(i=0;i<nott[i]=='$';i++)
{
scanf("\n%c",&t[i]);
}
for(i=0;i<nont;i++)
{
p[i][0]=nt[i];
first[i][0]=nt[i];
}
printf("\nEnter the productions :\n");
for(i=0;i<nont;i++)
{
scanf("%c",&temp);
printf("\nEnter the production for %c ( End the production with '$' sign )
:",p[i][0]);
for(j=0;p[i][j]!='$';)
{
j+=1;
scanf("%c",&p[i][j]);
}
}
for(i=0;i<nont;i++)
{
printf("\nThe production for %c -> ",p[i][0]);
for(j=1;p[i][j]!='$';j++)
{
printf("%c",p[i][j]);
}
}
for(i=0;i<nont;i++)
{
f=0;
for(j=1;p[i][j]!='$';j++)
{
for(k=0;k<not;k++)
{
if(f==1)
break;
if(p[i][j]==t[k])
{
first[i][j]=t[k];
first[i][j+1]='$';
f=1;
break;
}
else if(p[i][j]==nt[k])
{
first[i][j]=first[k][j];
if(first[i][j]=='e')
continue;
first[i][j+1]='$';
f=1;
break;
}
}
}
}
for(i=0;i<nont;i++)
{
printf("\n\nThe first of %c -> ",first[i][0]);
for(j=1;first[i][j]!='$';j++)
{
printf("%c\t",first[i][j]);
}
}
getch();
}
Difference between malloc and alloc?
alloc is used as header file while using malloc and calloc functions in C prog.
The definition of malloc function is in the alloc.h file.
It's stdlib.h to be more precise
What is a difference between a high level programming language and a low level programming language?
The most basic difference is that the statements in a low level language can be directly mapped to processor instructions, while a single statement in a high level language may execute dozens of instructions.
Low level refers to the fact that this is a machine language, binary in form, generally meaning one low level command = one executed instruction.
The complexity arises when we need to enable a programmer to designate one high level instruction that performs several or many machine (low level) operations.
Low Level Languages: Assembler and Advanced Assembler - see Compiler Languages.
High Level Languages: RPG, COBOL, any that make machine level programming of a computer easier.
What is Chomsky's classification of languages?
I believe it has something to do with the articulatory aspect (as opposed to other's acoustic and perceptual classifications).
> No, it is not. This is a hierarchy of formal grammars that rule the production of (human, computer, nature, etc.) "assertions". This approach is focused on a generative view of the meaningful sentences: each one of those could be generated by rules defined by a grammar, or syntactical rules. The classification is ordered by levels of expressiveness and complexity. See the related link on Wikipedia for further information.
How can you make a turbo c program by using one for loop to sort 3 numbers in ascending order?
Use the insertion sort algorithm.
Insertion sort works on the premise that a set of 1 can always be regarded as a sorted set, thus in a set of n elements, we can divide the set in two, with a sorted set at the beginning (with 1 element) and an unsorted set at the end (with all other elements). We then take the first element of the unsorted set and insert it into the sorted set, repeating until the unsorted set is empty.
We take the first element out of the unsorted set by copying it to a temporary variable, thus creating a gap in its place. We then examine the element to the left of the gap and, if the value is greater than the temporary, we copy it into the gap, effectively moving the gap one place to the left. We stop moving the gap when we reach the start of the array or the element to the left of the gap is not greater than the temporary. We then copy the temporary into the gap, increasing the sorted set by one element and reducing the unsorted set by one element.
We can implement this algorithm using just one for loop:
void sort (int* a, unsigned s) { // assume a refers to an array of length s
for (int i=2; i<s; ++i) {
int t = a[i]; // temporarily store a[i] outside the array
int g = i; // index g is the "gap" in the array
while (0<g && t<a[g-1]) { a[g]=a[g-1]; --g; } // move the gap to the correct insertion point
a[g] = t; // insert the temporary
}
}
Thus, to sort 3 numbers:
int a[3] = {2, 3, 1}; // unsorted
sort (a, 3);
assert (a[0]==1);
assert (a[1]==2);
assert (a[2]==3);
What are the advantages of using functions to modularize a program?
Advantages of functions:
What is the slowest in sorting algorithm?
There are many sorting algorithms with worst case of complexity O(n2). These algorithms have different average and best cases. They are:
Best case
Average case
Worst case
1) Quick sort
O(n*log n)
O(n*log n)
O(n2)
2) Insertion sort
O(n)
O(n2)
O(n2)
3) Bubble sort
O(n)
O(n2)
O(n2)
4) Selection sort
O(n2)
O(n2)
O(n2)
How do you check given string is palindrome or not with out using string functions?
/*To check whether a string is palindrome*/
What is the difference between variable and identifier?
An identifier is simply the name of something, while a variable is an instance of something.
For example:
int x;
Here, the identifier is "x," but the variable is the object whose name is "x." A: An identifier is a name of something. Typically used in computer programming, the term "identifier" is frequently used to name a variable (see below), a subroutine, are in reality, any place in memory in which data or code reside where a name would be useful. "MyBirthDate" might be a good identifier, pointing to a memory location where the data contianing your date of birth is stored. The term variable comes to us from mathematics, but is frequently used in computer science too. It refers to a value that varies. For instance: a + b = 5 In this case, the value of a and b can change, so long as the sum of a and b equal 5. The opposite of the term variable is constant. In the equation, E=Mc2, c is a constant that is equal to the speed of light in a vacu -- +- 186,000 miles per second. In computer science, the term "variable" is used synonymously with "identifier" when they are both used to point to memory that contains data that may be changed and will not always be the same. In Microsoft BASIC, the statement: Tomorrow = Today + 1 Today and Tomorrow are variables, and 1 is a constant.
How do you write a floating point variable in c?
You declare a floating point variable using the float or double keyword for a single- or double-precision floating point variable, respectively:
float a;
double b;
You reference a floating-point variable just like any other scalar variable by using the variable's name in a compatible expression, e.g.
a += 2;
b /= a;
Floating point literals use a period for the decimal point, no "thousands separator," and use the letter 'e' to denote a power of ten, e.g.
a = 0.123;
b = 123e-3;
Both a and b now have the same value, 123 times 10 to the power of -3 (which equals 0.123).
What is a valid c plus plus identifier?
In C++ we provide names for the entities we create, the variables, functions and types in our programs. These names, or identifiers, are required to conform to some simple rules.
An identifier must start with a letter and is comprised of a sequence of letters and digits. Somewhat surprisingly, in this context the underscore _ is considered to be a letter (although there are conditions associated with its use). There's no restriction on the length of an identifier.
What is the difference between tree search and graph search?
A graph is a set of vertices which are connected to each other via a set of edges.
A tree is a special type of hierarchical graph in which each node may have exactly one "parent" node and any number of "child" nodes, where a parent node is one level closer to the root and a child node is one level further away from the root.
Write a C plus plus program that asks the user to enter five numbers?
When writing a program that expects to retrieve data from a user, you have to first know what kind of interface to use. Decide whether you wish to write a console or windowed (graphical) application.
For console applications, you would likely use the scanf() function to retrieve values. See the help system for your compiler or look up "scanf" on the Web for details on using this function.
Graphical applications depend upon the operating system you're using. For instance, under Win32, you have the following options:
- Design a dialog at runtime consisting of STATIC and EDIT controls, plus a BUTTON control for the user to tell your program to commit the data, created with the CreateWindow() or CreateWindowEx() functions;
- If you're using an IDE (i.e. VC), it probably came with a resource editor you can use to create a dialog that contains labels and edit controls.
If you're brave enough to attempt some X11 coding, you'll need to decide which window manager you're using, and read up on the API for that WM to know which functions you have at your disposal.
You will also need to store this data in variables and then act on those variables as desired.
Where the phased locked loop is used?
Phase lock loop is used in analog and digital communications to keep the phase of the output signal the same as the input signal.
What are the books to study C Plus Plus?
Smart-C: Complete Programming Book available on Flipkart (Rating - 5 Star)
The book deals with one such Great programming language “C”. The book is designed to help the reader program in C. Great care has been taken in making the content interesting and understandable. Each module is added with multiple graphic images to make content easily understandable
Rules in naming variables in programming?
there are various types of naming rule provide for function ,identifier,i.e variables.but naming rule for variable must meet certain condition..
1.you can easily idenfy what is variable for.for eg.you may use
int a;/to store no of student in your prog. but it is better instead of using "a",you can write any of the following definition
int stu; or int stu_no; or int studentno;
2.it must be abbreviated.because although modern compiler support 32 char variable but still where you use that variable you have to type that name again &again.
so for eg. in the above case int stu_no; is optimal.
when these precondition are met then here are some rules for naming a variable:
1.you use only English alphabet,numeric no,& _(underscore).
2.you must start with a alphabet. then you continue with alphabet or numeric or under score.for eg. you can define a variable like
int stu_comp_2009;//for no of student 2009 batch.
3.no variable can start with number or _.such naming may cause some compiler do the right job but maximum would not support this.
Reverse of a given string using recursion?
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
char str[10],temp;
int i,len;
printf("Enter String : ");
scanf("%s",str);
len=strlen(str)-1;
for(i=0;i<strlen(str)/2;i++)
{
temp=str[i];
str[i]=str[len];
str[len--]=temp;
}
printf("%s",str);
getch();
}
Please do give your views on this.
With Regards,
Sumit Ranjan.
Analyst at RMSI Company.
What is the purpose of program counter?
program counter is a register that has the address of next instruction that has to be executed after currently executing instruction. it is used for proper execution of functions of computer by providing address of next instruction to microprocessor.
How many essential functions are required to write a c program and write those?
One.
int main (void) { return 0; }
How do you write a program to sort an array using selection sort?
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n,i,j,temp,a[50];
printf("Enter how many elements=");
scanf("%d",&n);
printf("Enter %d elements",n);
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
for(i=1;i<=n-1;i++)
{
for(j=1;j<=n-1;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
printf("\nSorted Array:\n");
for(i=1;i<=n;i++)
{
printf("\n%d",a[i]);
}
getch();
}
What expression has a value of either true or false?
In C, any non-zero expression is true and any zero expression is false.
What are the benefits of enumeration types?
We use enumerations to identify a group of constants in a more meaningful way than would be possible with an integral type. Consider the following:
int toggle (int traffic_light)
{
if (traffic_light<0 traffic_light>3) return -1; // invalid argument!
traffic_light=traffic_light==3?0:traffic_light+1;
return traffic_light;
}
The int argument, traffic_light, gives us some indication as to its purpose, but the body of the function is difficult to read. It's difficult to digest the logic and the literal constant 3 looks suspiciously like a "magic number". Worse, the function returns errors through the return value.
Let's re-write the function with an enumerated type:
enum traffic_light {green, amber, red, red_amber};
traffic_light toggle (traffic_light current)
{
switch (current)
{
case green: current=amber; break;
case amber: current=red; break;
case red: current=red_amber; break;
default: current=green;
}
return current;
}
While the body of the function is more verbose, the logic is much clearer. We can see from the enumeration that a traffic_light object only has four possible states and that the function cycles from one state to the next, just as a real traffic light should.
Upon closer examination, we note that a traffic_light behaves exactly as if it we're a 2-bit unsigned integer and that all we're doing is incrementing the integer, cycling back to 0 when both bits are set. So we could effectively implement the toggle function with an operator overload:
traffic_light& operator++(traffic_light& lhs)
{
return lhs = (lhs==red_amber)?green:(traffic_light)(((int) lhs)+1);
}
Operator overloads are often difficult to read, however all operators must be intuitive; they should all work exactly as we expect them to work. The above actually replicates the middle line of the original function, casting to int to perform the increment.
With this in place, our toggle function becomes:
traffic_light toggle (traffic_light current)
{
return ++current;
}