Who are the ancestors of C programming language?
programming languages B and BCPL which was used to derive C
Write a program to swap any number?
Do write, but before you start, please explain what does swapping a number mean.
When one dimensional character array of unspecified length is assigned an initial value?
string[] str= new string[2]{"ss","gg"}
for(int i=0;i<str.length;i++)
{
Response.wrirte(str[i]);
}
How do you write a c plus plus program to calculate the sum of squares using a function?
/**recursive function to find square root of a double to a precision of
maxDepth = 10 decimal places
returns -1.0 when given a negative number*/
#define maxDepth 10
/*firstly find the rational part*/
double getSqrt(double numIn){
/*cant take the square root of a negitive,
and a square root should not be negative
so return -1*/
int candidate = 0;
if (numIn <0)
return -1.0;
/*try every integer until you get one whose square is higher than
the number required, and this clearly one more than the
integer part of your square root*/
do{
if (candidate *candidate *1.0 numIn)
return testVal;
if (testVal * testVal >numIn)
/*most square roots are irrational, and theirfore a maximum number of recursions
must be set, otherwise infinite recursion will occur*/
if (myDepth <maxDepth)
return getIrrational(numIn, testVal-1/10^myDepth, myDepth +1);
else
return testVal-1/10^myDepth;
}
//this can probably be improved on in terms of conciseness, but the logic is the only //way to find a sqrt without going into calculous
How can insert a data into file in c?
You insert data into a file by copying the file to a temporary file up to the point of insertion, then copying the data to be inserted, then copying the balance of the original file. After closing the temporary file you delete the original file and rename the temporary file back to the original file's name.
What is the Structure of Program in Assembly language?
Assembly language programs are the Low level programs. We write Assembly Language program in basically 8085 and 8086 microprocessors.
We can have several registers to do opreations with. Accumulator is one most important Register in a assembly program.
We use several instructions like..
Arithmetic:
INR - Increment Accumulator
ADD B - Add Content of Reg. B with Accumulator
SUB, etc.
Logical:
AND - Bitwise AND
Jump Instriction:
JZ label - Jump to label if ZERO flagged
JC Label - Jump on Carry
Etc..
Write a java program to print the following output using the for loop 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5?
12345
1234
123
12
1
What is overflow and underflow in queue?
In C Programming arrays are given a size, which is the number of elements in the array. Space is allocated for an array in memory. The is the only memory that the array is supposed to use. C is a programming language that has very little restrictions regarding what it will allow you to do. If you try to write to a memory location that is not supposed to be written over, C will let you, however sometimes the operating system will prevent this. When an array writes past where it is supposed to this is called array overflow. For example. If is an array is designed to hold 50 integers and the program adds 51 integers then the extra integer is written at the end of the array and had to be written in memory not designated for the array.
Write a C program to print Armstrong numbers in a given range?
Sorry. I had to delete the older version, for it was written in C++, while the questioner had asked one in C. So here it is. In fact, I will give the questioner a bonus, it will print not only Armstrong numbers but all Narcissistic numbers (here the power to which the individual digits should be raised before being added to each other can be any integer. Clearly Armstrong numbers form a subset of these numbers, with the power equal to three), and that too not only upto 10000, but upto the maximum number a C compiler can process. Enjoy!
#include
#include
main()
{
int m=1,b;
int a[200],i,j,k,l;
while (m<=2147483647)
{
b=m;
i=0;
while (b>=1)
{
a[i]=(b%10);
b=floor(b/10);
++i;
}
for (j=1;j<=9;++j)
{
k=0;
for (l=(i-1);l>=0;--l)
k+= pow(a[l],j);
if (k==m)
goto sexy;
}
goto label;
sexy: printf("%d (raise every digit to power of %d)\n",m,j);
label: ++m;
}
}
/* program without if statement */
#include<stdio.h>
#include<conio.h>
void main()
{
int a,c;
float b;
clrscr();
printf("Enter the value \n");
scanf("%f",&b);
a=c;
c=a%10;
printf("the right most digit is %d",c);
getch();
}
Who developed c language n when?
C was developed between 1969 and 1973 by Dennis Ritchie at Bell Labs.
#include<stdio.h>
#include<string.h>
void main()
{
char m_str[100],m_word[100],rep[100];
char str1[100];
int i,j,f,k;
int len1,len2,len3;
printf("\n enter the main string:=\n");
gets(m_str);
len1=strlen(m_str);
printf("\n enter the word that you want to replace:=\n");
gets(m_word);
len2=strlen(m_word);
printf("\n enter the word of same length you want to replace with:=\n");
gets(rep);
len3=strlen(rep);
for(i=0;i<len1;)
{
f=0;
for(j=0;j<len2;)
{
if(m_str[i]!=m_word[j])
{
while(m_str[i]!=m_word[j])
i++;
while(j<len2)
j++;
}
if(m_str[i]==m_word[j])
{
f=1;
j++;
i++;
}
}
if(f==1)
{
for(k=0,j=i-len2;k<len3;k++)
m_str[j+k]=rep[k];
}
}
printf("\nthe replaced string is :-");
puts(m_str);
}
What is meant by linked list in c programming?
Yes, a linked list can be implemented in an array. Instead of pointers (or references in JAVA) you can use element indexes in the "next" and "last" items.
This does not stop you from using pointers or references. They still work. You can take the address of an element of an array, such as &a[217], and place that in the .next or .last pointers, and manage the relationships in the normal way. Using an array is simply one way to manage memory.
What types of anthropometric data are there?
Haha Raymond 2 from I-NEWTON wlang sagot sa MAPEH
MANGHIRAM NA LNG KAU KAY RAUELL
Pare-pareho kau ng sagot..
What are the Circular singly linked list applications in real life?
best example is trains...where each coach is connected to next coach except the engine and the last coach..when we need to add a coach we need to move to the right position and adjust the connecting point suitably!!
The terminology, in regards to switches and relay contacts, stands for N.C. = normally closed and N.O. = normally open. When ever these designations are used in schematics or electrical prints the position is to be taken in the de-energized state. No power on the circuit.
What is an array of pointers to pointers?
A pointer is a variable that stores value of address of a variable. Since a pointer itself is a variable, it is allocated a memory location.
Pointer to pointer means a pointer which points to the address of a pointer. In other words a pointer to a pointer has the address of the address of a variable.
We can have pointers to int, and pointers to char, and pointers to any structures we've defined, and in fact pointers to any type in C, it shouldn't come as too much of a surprise that we can have pointers to other pointers. If we're used to thinking about simple pointers, and to keeping clear in our minds the distinction between the pointer itself and what it points to, we should be able to think about pointers to pointers, too, although we'll now have to distinguish between the pointer, what it points to, and what the pointer that it points to points.
What is the FORTRAN program for pascal's triangle?
the logic i have used is nCr => n!/(r!*(n-r)!) for example the outer loop counter is 'n' and the inner loop counter is 'r' , then the corresponding element of the pascal's triangle will be nCr. keep in mind that both the loops will have to start from zero. #include<stdio.h> main()
{
int num,i,j,k,space;
int difffact=1,diff,n,r,x,y,comb=0,nfact=1,rfact=1;
printf("please enter the number of lines\n");
scanf("%d",&num); k=num-1;
space=num-1;
for(i=0;i<num;i++)
{
k=space--;
for(;k>0;k--)
{
printf(" ");
}
for(j=0;j<=i;j++)
{
comb=0;
nfact=1;
rfact=1;
difffact=1; for(n=i;n>=1;n--)
nfact=nfact*n; for(r=j;r>=1;r--)
rfact=rfact*r; diff=i-j;
for(;diff>=1;diff--)
difffact=difffact*diff; comb=(nfact/(rfact*difffact));
printf("%d ",comb);
}
printf("\n");
}
}
Advantages of new operator over malloc function in c?
1: new operator automatically computes the size of the data object. You need not use the operator sizeof.
2: new operator automatically returns the correct pointer type, so that there is no need to use a type cast.
3: it is possible to initialize the object while creating the memory space.
4: Like any other operator, new and delete can be overloaded.
What can you do with c programming?
C language is used for creating computer applications and also used a lot in writing embedded software/firmware for various electronics, industrial and communications products which use micro-controllers. It is also used in developing verification software, test code, simulators etc. for various applications and hardware products.
How are arguments passed to a function?
Arguments are passed to functions via the thread's function call stack. Every thread has its own call stack, which is a small region of contiguous, fixed-size memory that extends downwards into lower addresses. The stack is allocated when the thread is instantiated and deallocated when the thread terminates thus there is minimal cost in using the stack. Data is pushed and popped from the stack while a stack pointer keeps track of the top of the stack (the lowest unused address).
Can you write a function similar to scanf?
//program for myprintf using variable arguments
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdarg.h>
int compare(const void * var1,const void * var2)
{
if(*(int *)var1 > *(int *)var2)
{
return(0);
}
else{
return(1);
}
}
int myPrintf(const char * output ,...)
{
va_list arguments;
int stringlength,stringIndx;
char *s;
int d;
char c;
stringlength = strlen(output);
va_start(arguments,output);
for(stringIndx = 0;stringIndx < stringlength;stringIndx++)
{
if(output[stringIndx] == '%')
{
stringIndx++;
switch(output[stringIndx])
{
case 's': /* string */
s = va_arg(arguments, char *);
printf("%s\n", s);
break;
case 'd': /* int */
d = va_arg(arguments, int);
printf("%d\n", d);
break;
case 'c': /* char */
default:
/* need a cast here since va_arg only
takes fully promoted types */
c = (char) va_arg(arguments, char);
printf("%c\n", c);
break;
}
}
else{
printf("%c",output[stringIndx]);
}
}
}
void main()
{
unsigned int au32Nos[10] = {32,44.,55,66,11,8,9,7,9,10};
qsort(au32Nos,10,4,compare);
myPrintf(" %d %d %d %d %d %d %d %d %d %d",au32Nos[0],au32Nos[1],au32Nos[2],au32Nos[3],au32Nos[4],au32Nos[5],au32Nos[6],au32Nos[7],au32Nos[8],au32Nos[9]);
}
Want program for magic square using c?
You have to create 9 empty labels on the gui, then randomize 9#'s. assign each random number to the labels in the 3x3 square. ( you have to keep in your head where each random number will be). Then create a loop that does not end until each row, (labels 1-3), each column (labels 1,4,7), and diagnal ( 1,5,9) are different unique numbers and they add to 15(or the magic number).
-----------
For magic squares with an odd number of rows/columns (i.e. 3x3, 5x5, etc.), there is a simple algorithm to fill the squares. Magic squares with even number of rows/columns do NOT follow this algorithm.
Start in the top row, middle square. Place the number 1 there. The rest of the squares are filled as follows.
Choose the next cell by moving up and to the right. If the square falls outside the squares, the next number goes in the first cell of the row above it. If there is no row above it, drop down to the bottom of the next column and place the number there. If there is no column to the right, drop immediately below and place the number there. If the cell is already filled, drop immediately below and place the number there. Continue until all cells are filled. The number in the middle of the sequence should fall in the middle column of the middle row. The formula for the total of each row/column is: total = n * ((( n * n ) / 2 ) + 0.5)
Samples:
Magic square of 3x3:
8 1 6
3 5 7
4 9 2
Each row/column adds up to: 3 * ((( 3 * 3 ) / 2 ) + 0.5) = 15
-----------------------
Magic square of 5x5:
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
Each row/column adds up to: 5 * ((( 5 * 5 ) / 2 ) + 0.5 ) = 65
This algorithm will work for ALL magic squares with an odd number of rows/columns (where number of rows is the same as the number of columns).
C program code for concatenation of string?
Here You Are :
void String_Concate(char *Arr1, char *Arr2)
{
int r=0;
int c = String_Length(Arr1);
int x,p;
for(int i=0;Arr1[i];i++)
{
if((Arr1[i]== 32)(Arr1[i]=='\0'))
{r= i;
break;}
}
for(x = r,p =0;x<=c + String_Length(Arr2);x++,p++)
{
*(Arr1 + x) = *(Arr2 + p);
}
}
Have A nice Day
When comparing programming languages what is commonly used by all software developers?
There are many factors when it comes to choosing a programming language, primarily dependant upon the expected performance, time and budget. Even before a language is chosen, much time must be spent designing the program and often the design will determine the best language to use. in some cases it may be beneficial to modify an existing language to suit the task at hand, particularly with embedded systems.
Where performance is critical, programmers typically choose assembler, however this is usually limited to a small number of key routines since assembly programming is tedious and error-prone. C is typically used for a lot of low-level programming as C instructions can be mapped 1:1 with assembly. C++ is often used as well, as it allows any combination of low-level programming (including inline assembly), C-style programming and high-level abstraction through object-oriented programming. Indeed, the majority of operating systems, embedded systems and all major application software are written in C++ to some degree. C++ can also be found in areas where it was never specifically intended, such as advanced mathematics and theoretical physics.
Although C++ is a cross-platform language, the source code must be recompiled upon each target platform. To achieve this the code needs to be as generic as possible. In particular, generic audio and graphic libraries can help minimise development costs, but where there are differences between platforms, preprocessor directives can be used to filter the appropriate code in the absence of a generic library.
Where performance is not critical, high-level generic languages such as Java can speed up development times and thus reduce costs. Although Java is a compiled language it compiles to byte code rather than machine code. While the byte code will execute on any machine with a suitable Java Virtual Machine (and is therefore extremely portable), the need for interpretation of the byte code to machine code impacts upon performance compared to an equivalent C++ implementation. This also precludes Java from all low-level software development, including operating system kernels, drivers and embedded systems; it is intended purely for applications development.
Although C++ and Java dominate the bulk of application development, areas such as artificial intelligence often require languages that are better suited to the task, such as Lisp.