answersLogoWhite

0

📱

C Programming

Questions related to the C Computer Programming Language. This ranges all the way from K&R to the most recent ANSI incarnations. C has become one of the most popular languages today, and has been used to write all sorts of things for nearly all of the modern operating systems and applications. It it a good compromise between speed, power, and complexity.

9,649 Questions

How do you program a robot?

Many ways, depending on the robot complexity, how it is being ran and other factors. Conventional 'robots' have motors, sensors, and a computer. Usually the computer runs a program that does all the programming, this can be done in ANY language that the programmer fancies the most. There are some robots called BEAM robots that aren't programmed using code or programming, but instead react as a neural network (like an organic brain) or reactions from the pre built electronics in the robot. This is a VERY open question

What programming language should I learn if I want to program softwares?

There is a lot of different ones, so it really depends on what kind of software you want to design.

Write a C program to implement relocatable loader?

#include<stdio.h>

#include<conio.h>

#include<string.h>

#include<stdlib.h>

struct object_code

{

int locctr;

char add[10];

}obcode[300];

void main()

{

char input[100][16],output[100][16],binary[20],address[20],stloc[10];

int len,bitmask,loc,tlen=0,tloc,textloc,i=0,location,j,k,count=0,start,n,num=0,inc=0;

FILE *fp1,*fp2;

clrscr();

fp1=fopen("linput.dat","r");

fp2=fopen("reloadout.dat","w");

printf("Enter the location where the program has to be loaded:");

scanf("%s",stloc);

start=atoi(stloc);

location=start;

tloc=start;

fscanf(fp1,"%s",input[i]);

while(strcmp(input[i],"T")!=0)

{

strcpy(output[i],input[i]);

i++;

fscanf(fp1,"%s",input[i]);

strcpy(output[i],input[i]);

}

itoa(start,output[2],10);

while(strcmp(input[i],"E")!=0)

{

strcpy(output[i],input[i]);

if(strcmp(input[i],"T")==0)

{

for(j=0;j<3;j++)

{

i++;

fscanf(fp1,"%s",input[i]);

strcpy(output[i],input[i]);

}

bitmask=atoi(output[i]);

itoa(bitmask,binary,2);

strcpy(output[i],NULL);

textloc=atoi(output[i-2]);

textloc=textloc+start;

itoa(textloc,output[i-2],10);

for(n=0;n<(textloc-(tloc+tlen));n++)

{

strcpy(obcode[inc].add,"xx");

obcode[inc++].locctr=location++;

}

tlen=atoi(output[i-1]);

tloc=textloc;

k=0;

}

else

{

if(binary[k]==1)

{

num=0;

len=strlen(output[i]);

strcpy(address,NULL);

for(j=2;j<len;j++)

{

address[num]=output[i][j];

output[i][j]='\0';

num++;

}

loc=atoi(address);

loc=loc+start;

itoa(loc,address,10);

strcat(output[i],address);

}

k++;

len=strlen(output[i]);

num=0;

for(n=0;n<len;n++)

{

obcode[inc].add[num++]=output[i][n];

if(num>1)

{

obcode[inc++].locctr=location++;

num=0;

}

}

}

i++;

fscanf(fp1,"%s",input[i]);

}

strcpy(output[i],input[i]);

i++;

fscanf(fp1,"%s",input[i]);

loc=atoi(input[i]);

loc=loc+start;

strcpy(output[i],itoa(loc,address,10));

count=0;

i=0;

n=0;

fprintf(fp2,"%d\t",obcode[n].locctr);

for(n=0;n<inc;n++)

{

fprintf(fp2,"%s",obcode[n].add);

i++;

if(i>3)

{

fprintf(fp2,"\t");

i=0;

count++;

}

if(count>3)

{

fprintf(fp2,"\n%d\t",obcode[n+1].locctr);

count=0;

}

}

getch();

}

Can you use two main function?

AnswerYes, if they are in separate source-files, and one of them is static. Of course the execution will start with the non-static 'main' function.

Answer1. If it is a multithreaded operating system (and it probably is) then you can have the Main method start another thread on another method.
2. For C programs in a Win32 console project template, Visual Studios C++ does not allow static on a main method or two main methods in one application, but you can create two separate projects which will create two separate programs.

Using function create a program that will ask the user if he wants to compute the perimeter or the area of the triangle in your main program If the perimeter is wanted ask the measures of the three si?

//Perhaps this is what you want.

//@author Rosencrantz

import java.util.Scanner;

class TriangleFun

{

public static void main(String[] args)

{

Scanner scan = new Scanner(System.in);

boolean done = false;

while(true)

{

System.out.print("Calculate AREA or PERIMETER? Type DONE to quit.");

String input = scan.nextLine().trim();

if(input.equalsIgnoreCase("DONE"))

break;

if(input.equalsIgnoreCase("AREA"))

{

System.out.print("Enter the base length: ");

double base = scan.nextDouble();

System.out.print("Enter the height: ");

double height = scan.nextDouble();

System.out.println("Area is: " + (1/2.0) * base * height);

}

else

{

System.out.print("Enter length of side 1: ");

double length1 = scan.nextDouble();

System.out.print("Enter length of side 2: ");

double length2 = scan.nextDouble();

System.out.print("Enter length of side 3: ");

double length3 = scan.nextDouble();

System.out.println("Perimeter is: " + (length1 + length2 + length3));

}

scan.nextLine();

}

}

}

//A better edited version is in the links

What function that call themselves are called to c programme?

Functions in C language may call themselves (ie can be recursive) without restrictions.

What computer language java or C plus plus should you use to design an app for the ipod or should i use a software?

You would use neither Java nor C++, you would use Objective-C, in conjunction with the Apple iPod API (iPod Library Access).

How do you delete an ith element in singly linked list?

You will need to traverse the list i times to get to the element you want deleted. Each time you go thru the list you will need to remember the forward pointer from the previous element because when you get to the element you want to delete the previous forward pointer needs to be pointed to the I + 1 element of the list.

How do you determine a circular queue is full?

You could check the last element's next() node to see if it's null. If it's not null, then you've pointed your end pointer to the first element, and the queue is full.

Entry control loop example?

ENTRY - CONTROLLED LOOP EXAMPLE

Consider the following code fragment:

:

for(int a=1;a<=10;a++)

{

cout<<"\t"<

}

:

The code will print first 10 natural nos. as:

1 2 3 4 5 6 7 8 9 10

In the above example, first the value of a is determined, which is 1 initially; then the test expression is evaluated (which, in this example comes out to be true (1>10)); the body of the loop is then executed followed by the execution of update expression (here, a++).

This is an entry controlled loop because the body of the loop is executed only after the test expression evaluates to true.

How do you include Trigonometry in C?

You don't. You can include math.h though, and use its functions eg. sin, cos, tg, sqrt, etc.

What is a merchant statement?

A merchant statement is a written record prepared by the processor (usually once a month) which lists all the transactions for the account, including fees charged.

Difference between array and union?

All the members of the structure can be accessed at once,where as in an union only one member can be used at a time. Another important difference is in the size allocated to a structure and an union. for eg: struct example { int integer; float floating_numbers; } the size allocated here is sizeof(int)+sizeof(float); where as in an union union example { int integer; float floating_numbers; } size allocated is the size of the highest member. so size is=sizeof(float);

Why object is known as basic run-time entity?

coz at the run time object is provided memory , that's why object is called run time entity .

How do you write a program in c to print the first five prime numbers?

In order to print the first 10 prime numbers you need a function to determine if a given value is prime or not. The following algorithm is the standard method of doing so:

1. Let n be the value.

2. If n < 2 then return false.

3. If n is even then return true if n is 2, otherwise return false.

4. Let divisor = 3.

5. If divisor is greater than the square root of n then return true.

6. If divisor is a factor of value then return false.

7. Let divisor = divisor + 2.

8. Go to step 5.

This algorithm can be efficiently implemented in C++ as follows:

bool is_prime (const unsigned n)

{

if (n<2) return false;

if (!(n&1)) return n==2;

const unsigned m = static_cast<unsigned>(std::sqrt (static_cast<double>(n)));

for (unsigned d=3; d<=m; d+=2)

if (!(n%d)) return false;

return true;

}

With this function defined, we can now go ahead and write the complete program:

#include<iostream>

bool is_prime (const unsigned n) {/*as above*/}

int main()

{

std::cout << "First 10 primes:\n";

unsigned primes = 0;

unsigned num = 0;

while (primes < 10)

{

if (is_prime (num))

{

std::cout << num << std::endl;

++primes;

}

++num;

}

}

What is the algorithm to find largest node in a binary search tree?

Since a binary search tree is ordered to start with, to find the largest node simply traverse the tree from the root, choosing only the right node (assuming right is greater and left is less) until you reach a node with no right node. You will then be at the largest node.

for (node=root; node!= NULL&&node->right != NULL; node=node->right);

This loop will do this. There is no body because all the work is done in the control expressions.

What is the use of switch statement in java?

In java, a switch statement is used to simplify a long list of 'if' statements. A switch statement takes the form of:

switch (variableName){

case condition1; command1;

case condition2; command2;

...

}