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

What is traverse technique used in chain survey?

1. pre-order b-tree traversal.

2. in-order b-tree traversal.

3. post-order b-tree traversal

How many different versions of the Bantu language are there?

Answer

Other Bantu languages include

* in Central and Eastern Africa o Swahili o Lingala o Luganda o Gĩkũyũ o Bukusu o Lusoga o Kikongo o Chichewa o Chiyao o Kihaya o Kichagga o Kinyarwanda o Kirundi * in Southern Africa o Shona o Ndebele (Sindebele) o Tswana (Setswana) o Sesotho o Zulu (isiZulu) o Xhosa o Sepedi o Swazi * in West Africa o Ngumba (Cameroon) o Kako (Cameroon) o Basaa (Cameroon)

Some are usually known in English without the class prefix (Swahili instead of Kiswahili, etc.), and some others vary (Setswana or Tswana, Sindebele or Ndebele, etc.). The bare form typically does not occur in the language: in the country of Botswana the people are the Batswana, one person is a Motswana, and the language is Setswana.

Today most linguists see the center of the Bantu expansion, that started about 2000 years before present in eastern Nigeria and Cameroon.[edit]

(Narrow) Bantu languages

* Bemba * Songa * Northwest o Zone A o Zone B o Zone C * Central o Zone D (Lengola, Enya, Mbole, Mituku, Bembe, Buyu, Nyanga, Bhele (Piri), Bila, Bodo, Bera (Bira), Budu, Homa, Kaiku, Komo, Kango, Ndaka, Nyali, Amba, Vanuma, Mbo, Kare, Bali, Beeke, Hamba, Holoholo, Kanu, Kwami, Shabunda-Lega, Mwenga-Lega, Lika, Songoora (Dialects: Gengele, North Binja, South Binja), Zimba) o Zone E (Gweno, Kahe, Chaga (Chaga languages: Machame Mochi, Rombo, Vunjo), Rusa, Malakote, Chonyi, Digo, Duruma, Giryama (Nyika), Segeju, Pokomo (Upper and Lower), Taita, Sagalia, Logoli, Kabwa, Gusii, Ikizu, Kuria, Ngurimi, Ikoma (Nata), Temi (Sonjo), Suba, Sizaki, Ware, Zanaki, Dhaiso, Embu, Gikuyu, Chuka, Meru, Tharaka, Mwimbi, Muthambi) o Zone F (Bende, Fipa, Mambwe, Lungu, Pimbwe, Rungwa, Tongwe, Konongo, Kimbu, Nyamwezi, Sukuma, Sumbwa, Bungu, Langi, Mbugwe, Nilamba, Nyaturu (Rimi), Mbugu) o Zone G o Zone H o Zone J o Zone K o Zone L (Bwile, Kaonde, Nkoya, Mbwera, Bangubangu, Binji, Kete, Luna, Songe, Mbagani, Budya, Hemba, Kanyok, Luba-Kasai, Luba-Katanga, Lwalu, Sanga) o Zone M o Zone N (Manda, Mantengo, Ngoni, Tonga, Mpoto, Nyanja, Tumbuka, Nsenga, Barwe, Kunda, Nyungwe, Phimbi, Sena, Malawi Sena, Podzo, Rue) o Zone P (Yao, Mwera, Makonde, Machinga, Nyasa, Mabiha, Ndonde Hamba, Ndendeule, Matumbi, Mbunga, Ndengereko, Ngindo, Nindi, Rufiji, Chuwabu, Maindo, Koti, Kokola, Lolo, Manyawa, Lomwe, Ngulu, Marenje, Takwane, Makua, Makhuwa-Meetto, Makhuwa-Moniga, Makhuwa-Shirima, Makhuwa-Marrevone, Makhuwa-Saka) o Zone R (Herero, Zemba, Yeyi, Umbundu (South Mbundu), Ndombe, Nyaneka, Nkhumbi, Kwanyama, Ndonga, Kwambi, Ngandyera, Mbalanhu) o Zone S (Dema, Kalanga, Manyika, Ndau, Nambya, Shona, Zezuru, Tawara, Tewe, Chopi, Tonga-Inhambane, Ronga Tsonga, Tonga, Tswa, Venda, Swati (Swazi), Xhosa, Zulu, Zimbabwe Ndebele, North Transvaal Ndebele, South Transvaal Ndebele, Northern Sotho, Southern Sotho, Birwa, Kgalagadi, Lozi, Tswana, Tswapong) o Unclassified (Boguru, Gbati-ri, Isanzu, Ngbee, Kari, Mayeka, Ngbinda, Nyanga-li, Songo)

[edit]

Some Bantu words in popular Western culture

* Samba * Banjo * Rumba * Conga * Mambo * Zombie * Bongos * Gumbo * Jumbo * La Bamba * Marimba

What is the meaning of code has no effect in function main in c language?

When the compiler says "code has no effect", it is saying that it does not matter if the code is executed or not - the end result will be the same. The compiler, if in optimizing mode, can and should delete the code. An example of code that has no effect is a = a;

Program to display multiplication table for given number?

#include<stdio.h>

main()

{

int i,n;

clrscr();

printf("enter the value");

scanf("%d", &n);

while(i<=10)

{

printf("\n %d*%d=%d",n,i,(i*n));

i++;

}

getch();

}

How do you write a program that asks the user to enter their favouite tv programme and display the result 15 times?

#include <iostream>

#include <string>

using std::cin;

using std::cout;

using std::endl;

using std::string;

int main()

{

cout << "Enter name of your favorite TV show: \n";

string tvShow = "";

cin >> tvShow;

for (int i = 0; i < 15; i++)

{

cout << endl << tvShow;

}

cout << endl << endl;

system("PAUSE");

return 0;

}

What is the C plus plus Algorithm for Knapsack Problem?

#include<iostream>

#include<vector>

#include<cassert>

template<typename _Ty>

class subset

{

public:

using value_type = typename _Ty::const_iterator;

using container_type = std::vector<value_type>;

using iterator = typename container_type::iterator;

using const_iterator = typename container_type::const_iterator;

using reverse_iterator = typename container_type::reverse_iterator;

using const_reverse_iterator = typename container_type::const_reverse_iterator;

using size_type = typename container_type::size_type;

~subset (void) {};

explicit subset (const _Ty&);

subset (const subset&) = delete;

subset (subset&&) = delete;

subset& operator= (const subset&) = delete;

subset& operator= (subset&&) = delete;

const container_type& first (size_type);

const container_type& next (void);

private:

size_type m_size; // desired size of the subset

container_type m_set; // iterators to the full set

container_type m_subset; // subset of the full set of iterators

const_iterator find (const value_type&) const;

const bool get_next (const bool = true);

};

template<typename _Ty>

inline subset<_Ty>::subset (const _Ty& set):

m_size {set.size()}, m_set {}, m_subset {}

{

for (value_type it=set.begin(); it!=set.end(); ++it)

m_set.push_back (it);

m_set.shrink_to_fit();

}

template<typename _Ty>

inline typename subset<_Ty>::const_iterator subset<_Ty>::find (

const value_type& value) const

{

const_iterator it=m_set.begin();

while (it!=m_set.end() && *it!=value) ++it;

return it;

}

template<typename _Ty>

inline const typename subset<_Ty>::container_type& subset<_Ty>::first (

size_type count)

{

assert (count <= m_set.size());

m_size = count;

m_subset.clear();

for (const_iterator it=m_set.begin(); count--; ++it)

m_subset.push_back (*it);

return m_subset;

}

template<typename _Ty>

inline const bool subset<_Ty>::get_next (

const bool pop /* = true */)

{

const_reverse_iterator sub_it = m_subset.rbegin();

const_iterator set_it = find (*sub_it);

if (pop)

m_subset.pop_back();

if (++set_it != m_set.end())

m_subset.push_back (*set_it);

return m_subset.size() 1U)

return m_subset;

const value_type value = m_set.back();

m_set.pop_back();

--m_size;

next();

m_set.push_back (value);

if (m_size++ != m_subset.size())

return m_subset;

get_next (false);

return m_subset;

}

struct item

{

size_t value {0};

size_t weight {0};

item (size_t v=0, size_t w=0): value{v}, weight{w} {}

};

using vector = std::vector<item>;

item sum (vector& v)

{

item result;

for( auto i : v)

{

result.weight += i.weight;

result.value += i.value;

}

return result;

}

vector knapsack (vector items, size_t capacity)

{

vector v;

subset<vector> set {items};

for (size_t n=items.size(); n; --n)

{

subset<vector>::container_type selection {set.first (n)};

for (; selection.size(); selection=set.next())

{

vector t;

for (auto i : selection)

{

t.push_back (*i);

}

item s = sum (t);

if (s.weight <= capacity && sum(v).value < s.value)

v = t;

}

}

return v;

}

int main()

{

size_t capacity {4};

vector items {{1,8},{2,4},{3,1},{2,5},{2,3}};

vector rucksack = knapsack (items, capacity);

std::cout << "Items:\n" << std::endl;

for (auto i : items)

std::cout << '£' << i.value << '\t' << i.weight << "kg" << std::endl;

std::cout << std::endl;

std::cout << "Optimal selection for capacity " << capacity << "kg\n" << std::endl;

for (auto r : rucksack)

std::cout << '£' << r.value << '\t' << r.weight << "kg" << std::endl;

std::cout << std::endl;

item s = sum (rucksack);

std::cout << "Total value and weight:\n" << std::endl;

std::cout << '£' << s.value << '\t' << s.weight << "kg" << std::endl;

std::cout << std::endl;

}

What is the algorithm for finding the number of binary digits required to represent a positive decimal integer?

Algorithm bit_count is:

Input: an integer n, such that n >= 0

Output: the minimum number of binary digits (bits) required to represent n

let count := 0;

repeat {

n := n / 2; // integer division: ignore any remainder

count := count + 1;

} until n = 0;

return count;

This works because each binary digit represents an increasing power of 2, starting from 2^0. Thus if we repeatedly divide a value by 2 until the result is 0, the total number of divisions tells us the minimum number of bits required to represent the value.

Take the value 42 as an example:

42 / 2 = 21

21 / 2 = 10 (r 1)

10 / 2 = 5

5 / 2 = 2 (r 1)

2 / 2 = 1

1 / 2 = 0 (r 1)

That's 6 divisions in total so we need at least 6 binary digits to represent 42 in binary. Given that 42 is 101010 in binary, this is correct.

Let's try 31:

31 / 2 = 15 (r 1)

15 / 2 = 7 (r 1)

7 / 2 = 3 (r 1)

3 / 2 = 1 (r 1)

1 / 2 = 0 (r 1)

5 divisions so 5 bits. 31 in binary is 11111, so that's also correct. 11111 is also the maximum value we can represent with just 5 bits so it follows that 32 would need 6 bits:

32 / 2 = 16

16 / 2 = 8

8 / 2 = 4

4 / 2 = 2

2 / 2 = 1

1 / 2 = 0 (r 1)

QED

What do you mean by searching technique?

"Searching technique" defines the way in which we look for a given value within a set of values. We define these techniques using algorithms.

Searching is always quicker when the data is in sorted order. We start in the middle of the set. If that's our value, we're done. Otherwise, we compare the middle value with the value we seek to determine which side of the set contains our value. We then discard the other half and repeat the process with the remaining half. If the remaining half is empty, the value does not exist.

This technique is known as a binary search and can be performed efficiently on any container that permits constant-time random-access, such as an array. Balanced binary trees can also be used. Lists do not support constant-time random-access so the benefit of binary search is often outweighed by added complexity of identifying the middle element of a range.

If the data is unsorted, we must use a linear search. Typically we start at the first element and work our way through to the last element, stopping when we find the value or reach the end of the sequence. Linear search can be performed on any container that allows forward traversal, including arrays and lists.

The return value of a search algorithm is typically an iterator; a pointer to the element or node that holds the value. If the value does not exist, we typically return an iterator to the one-past-the-end of the sequence. In the case of arrays we could return the zero-based index of the value, returning the count of elements when the value does not exist, however it is better to use iterators as this allows us to generalise our algorithms to cater for all container types.

What is the language for zalig kerstfeest?

It is Dutch, the language spoken in The Netherlands. A dialect of Dutch is also used in the northern (Flemish) part of Belgium.

What does mindstorming mean?

Mind storming is basically the same thing as brain storming. It sets the stage for letting your creative juices call forth suggestions for your writing as well as ways to improve your fortune and productivity.

Evaluate the expression sine 30 degree cosecant 30 degree?

Sin(30) + cosec(30) = sin(30) + 1/sin(30) = 0.5 + 1/0.5 = 0.5 + 2 = 2.5

Write a program in c to implement scan-line polygon filling algorithm?

#include<GL/glut.h>

float x1,x2,x3,x4,y1,y2,y3,y4;

void draw_pixel(int x,int y)

{

glColor3f(0.5,0.0,1.0);

glPointSize(0.5);

glBegin(GL_POINTS);

glVertex2i(x,y);

glEnd();

}

void edgedetect(float x1,float y1,float x2,float y2,int *le,int *re)

{

float temp,x,mx;

int i;

if(y1>y2)

{

temp=x1,x1=x2,x2=temp;

temp=y1,y1=y2,y2=temp;

}

if(y1==y2)

mx=x2-x1;

else

mx=(x2-x1)/(y2-y1);

x=x1;

for(i=int(y1);i<=(int)y2;i++)

{

if(x<(float)le[i]) le[i]=(int)x;

if(x>(float)re[i]) re[i]=(int)x;

x+=mx;

}

}

void scanfill(float x1,float y1,float x2,float y2,float x3,float y3,float x4,float y4)

{

int le[500],re[500],i,j;

for(i=0;i<500;i++)

le[i]=500,re[i]=0;

edgedetect(x1,y1,x2,y2,le,re);

edgedetect(x2,y2,x3,y3,le,re);

edgedetect(x3,y3,x4,y4,le,re);

edgedetect(x4,y4,x1,y1,le,re);

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

{

if(le[j]<=re[j])

for(i=le[j];i<re[j];i++)

draw_pixel(i,j);

}

}

void display()

{

x1=250.0;y1=200.0;x2=150.0;y2=300.0;x3=250.0;

y3=400.0;x4=350.0;y4=300.0;

glBegin(GL_TRIANGLES);

glVertex2f(x1,y1);

glVertex2f(x2,y2);

glVertex2f(x3,y3);

glVertex2f(x4,y4);

glEnd();

scanfill(x1,y1,x2,y2,x3,y3,x4,y4);

glFlush();

}

void init()

{

glClearColor(1.0,1.0,1.0,1.0);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

gluOrtho2D(0.0,499.0,0.0,499.0);

}

void main(int argc,char **argv)

{

glutInit(&argc,argv);

glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);

glutInitWindowSize(500,500);

glutCreateWindow("scanline");

glutDisplayFunc(display);

init();

glutMainLoop();

}

SIC assembler pass 1 C program?

#include<stdio.h>

#include<string.h>

#include<stdlib.h>

void chk_label();

void chk_opcode();

void READ_LINE();

struct optab

{

char code[10],objcode[10];

}myoptab[3]={

{"LDA","00"},

{"JMP","01"},

{"STA","02"}

};

struct symtab{

char symbol[10];

int addr;

}mysymtab[10];

int startaddr,locctr,symcount=0,length;

char line[20],label[8],opcode[8],operand[8],programname[10];

void PASS1()

{

FILE *input,*inter;

input=fopen("input.txt","r");

inter=fopen("inter.txt","w");

printf("LOCATION LABEL\tOPERAND\tOPCODE\n");

printf("_____________________________________");

fgets(line,20,input);

READ_LINE();

if(!strcmp(opcode,"START"))

{

startaddr=atoi(operand);

locctr=startaddr;

strcpy(programname,label);

fprintf(inter,"%s",line);

fgets(line,20,input);

}

else

{

programname[0]='\0';

startaddr=0;

locctr=0;

}

printf("\n %d\t %s\t%s\t %s",locctr,label,opcode,operand);

while(strcmp(line,"END")!=0)

{

READ_LINE();

printf("\n %d\t %s \t%s\t %s",locctr,label,opcode,operand);

if(label[0]!='\0')

chk_label();

chk_opcode();

fprintf(inter,"%s %s %s\n",label,opcode,operand);

fgets(line,20,input);

}

printf("\n %d\t\t%s",locctr,line);

fprintf(inter,"%s",line);

fclose(inter);

fclose(input);

}

void READ_LINE()

{

char buff[8],word1[8],word2[8],word3[8];

int i,j=0,count=0;

label[0]=opcode[0]=operand[0]=word1[0]=word2[0]=word3[0]='\0';

for(i=0;line[i]!='\0';i++)

{

if(line[i]!=' ')

buff[j++]=line[i];

else

{

buff[j]='\0';

strcpy(word3,word2);

strcpy(word2,word1);

strcpy(word1,buff);

j=0;

count++;

}

}

buff[j-1]='\0';

strcpy(word3,word2);

strcpy(word2,word1);

strcpy(word1,buff);

switch(count)

{

case 0:strcpy(opcode,word1);

break;

case 1:strcpy(opcode,word2);

strcpy(operand,word1);

break;

case 2:strcpy(label,word3);

strcpy(opcode,word2);

strcpy(operand,word1);

break;

}

}

void chk_label()

{

int k,dupsym=0;

for(k=0;k<symcount;k++)

if(!strcmp(label,mysymtab[k].symbol))

{

mysymtab[k].addr=-1;

dupsym=1;

break;

}

if(!dupsym)

{

strcpy(mysymtab[symcount].symbol,label);

mysymtab[symcount++].addr=locctr;

}

}

void chk_opcode()

{

int k=0,found=0;

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

if(!strcmp(opcode,myoptab[k].code))

{

locctr+=3;

found=1;

break;

}

if(!found)

{

if(!strcmp( opcode,"WORD"))

locctr+=3;

else if (!strcmp(opcode,"RESW"))

locctr+=(3*atoi(operand));

else if(!strcmp(opcode,"RESB"))

locctr+=atoi(operand);

}

}

int main()

{

PASS1();

length=locctr-startaddr;

}

What mechanism would you implement in the process scheduler to automate the termination of a job that is in an infinite loop?

put a counter in. set it to zero before the loop. add 1 to it inside the loop pick a realistic number for how many times it could possibly go through legitamately and have it exit the loop if the counter goes above that.

or if you do not have duplicate data each time through the loop save the data compare it the next time through and if it is the same 2 or 3 times in a row abort the loop.

What converts high level language to machine language?

Converting machine language to a high-level language is very difficult. It is not possible to convert machine language back to the original high-level source code because there are an infinite number of source code files that can produce any given machine language output. For example, machine language uses memory addresses or stack locations to store variables, so all variable names used in the source code are lost and cannot be regenerated.

There are some reverse compiler tools that can produce a probable high level language file from machine language. And some machine code file formats store information about source code for debugging or tracing, and when available, that information can be very useful to reverse-compile machine code.

It is also possible to generate an assembly language file that is close to the machine code, and although that is not high-level it is more human readable.

What is deference operator in c?

There is no deference operator in C or C++.

However, the language supports references, and supports accessing values through pointers. The latter is sometimes called dereferencing.

Consider P to be a pointer to V. The asterisk is used to dereference V through P, that is, to access V: *P = 5 assigns value 5 to V (again, provided P points to V).

Note that the asterisk has different meanings in the C language, depending on the context in which it is used.

Now consider P to be a pointer to a structure S with members S.A and S.B. The right arrow operator can be used to dereference members S.A and S.B through P: P->A = 5; P->B = 13; assigns 5 and 13 to S.A and S.B, respectively.

The C++ language also knows a construct called references, which supports passing of arguments by reference rather than by value, without the complication and risk of pointer operations.

To declare a function argument as a reference, use the ampersand:

void example(int& v) {

v *= 2;

}

int i = 3;

void test(void) {

example(i);

}

After calling the test() function, variable i has value 6. Notice how no "referencing" operator was required in the all to the example function, and notice how the example function used the ampersand in the prototype declaration, but did not require a dedicated dereferencing operator when modifying the argument v.

How do you reverse a 6 digit number in C plus plus?

The number of digits is immaterial, the principal is exactly the same. The key to reversing any number is in the following user-defined function:

uint reverse(uint num)

{

uint rev=0;

while(num)

{

rev*=10;

rev+=num%10;

num/=10;

}

return(rev);

}

The following code demonstrates how to reverse a 6 digit number entered from the console.

#include<iostream>

#include<string>

#include<sstream>

typedef unsigned int uint;

uint reverse(uint num)

{

uint rev=0;

while(num)

{

rev*=10;

rev+=num%10;

num/=10;

}

return(rev);

}

int getrange(uint digits,uint& min,uint&max)

{

if(!digits)

return(-1);

min=1;

while(--digits)

min*=10;

max=min*10-1;

return(0);

}

uint inputnumber(const std::string prompt,const uint min,const uint max)

{

using namespace std;

uint result=0;

while(1)

{

cout<<prompt;

string s;

getline(cin,s);

if(s.size())

result=stoul(s,0,10);

if(result<min result>max)

cout<<"The number must be in the range "

<<min<<".."<<max<<"\n"

<<"Please enter another number.\n"<<endl;

else

break;

}

return(result);

}

uint inputnumber(const uint digitcount)

{

using namespace std;

uint min=0, max=0;

if(getrange(digitcount,min,max)==-1)

return(0);

std::stringstream prompt;

prompt<<"Enter a "<<digitcount<<" digit number: ";

return(inputnumber(prompt.str(),min,max));

}

int main()

{

using namespace std;

uint num=inputnumber(6); // 6 digits.

if(num)

{

uint rev=reverse(num);

cout<<"Reverse: "<<rev<<"\n"<<endl;

}

return(0);

}

Output:

Enter a 6 digit number: 123456

Reverse: 654321

How can we write program in c on secant method explain with example?

#include<iostream>

#include<cmath>

#include<fstream>

using namespace std;

double f(double x);

int main()

{

double dX0, dX1, dX2, dInterations = 0, dTolerance;

cout << "What is the first root guess? ";

cin >> dX0;

cout << "What is the second root guess";

cin >> dX1;

do {

dX2 = dX1 - ((f(dX1) * (dX1 -dX0)) / (f(dX1) - f(dX0)));

dX0 = dX1;

dX1 = dX2;

dTolerance = fabs(dX2 - dX1);

dInterations++;

}

while (dInterations <= 100 dTolerance >= .000001);

cout << "One of the roots is " << dX2 << endl;

}

double f(double x)

{

double dReturn;

dReturn = (3 * x * x) + (2 * x) -2;

return dReturn;

}

Input a list of employee names and salaries and determine the mean average salary as well as the number of salaries above and below the mean?

Declare Names[100], Salaries[100]

Set Sum = 0

Set Count1 = 0

Set K = 1

Write "Enter Employees Name and Salary."

Write "Enter *,0 when done."

Input Name, Salary

While Salary <> "0"

Set Count1 = Count1 + 1

Set Sum = Sum + Salary

Write "Enter another Employee Name and Salary (enter *,0 when done)"

Input Name, Salary

End While

Set Average = Sum / Count1

Set Count2 = 0

Set Count3 = 0

For K = 1 Step 1 to Count1

If Salary[K] > Average Then

Set Count2 = Count2 + 1

End If

If Salary[K] < Average Then

Set Count3 = Count3 + 1

End If

End For

Write "The Average Salary is: $", Average

Write "The number of Salaries Above theAverage Salary is:", Count2

Write "The number of Salaries Below theAverage Salary is:", Count3

How to create user define function of my name in c?

You need to declare it first. A function declaration is made of three parts:

The kind of data the function returns, I.E. void, int, etc.

The name of the function, I.E. helloWorld.

The list of parameters in parentheses, I.E. (A as int, B as char)

For an example, here it is:

void helloWorld();

Now, to put something inside the function, you can write the following:

void helloWorld()

{

printf("Hello world!");

}