answersLogoWhite

0

📱

Computer Programming

A category for questions about computer programming and programming languages.

10,506 Questions

How do you write a program in C to swap two variables using a function?

#include<iostream>

void swap(int* x, int* x){

(*x)^=(*y)^=(*x)^=(*y);

}

int main()

{

int a, b;

a=10;

b=20;

std::cout<<"Before swap: a="<<a<<", b="<<b<<std::endl;

swap(&a,&b);

std::cout<<"After swap: a="<<a<<", b="<<b<<std::endl;

return(0);

}

Write a c program to determine the size of an array?

using sizeof operator the size of whole array can be calculated, then divide it with the zise of the datatype(E.g. for int =4, char =2....etc.)

Example:

#define Narray (sizeof(array)/sizeof(array[0]))

What is the definition of open source software?

Open source software (OSS) is defined as computer software for which the source code and certain other rights normally reserved for copyright holders are provided under a software license that meets the Open Source Definition or that is in the public domain. This permits users to use, change, and improve the software, and to redistribute it in modified or unmodified forms. It is very often developed in a public, collaborative manner. Open source software is the most prominent example of open source development and often compared to user-generated content. The term open source software originated as part of a marketing campaign for free software. A report by Standish Group states that adoption of open source software models has resulted in savings of about $60 billion per year to consumers.


The term open source ("OS") describes a type of production, dissemination and exploitation of software opposed to the so-called "proprietary" way of distribution. OS-software is usually produced in a collaborative process by a web-based community. The ultimate aim is to create stable, compatible and free software. In order to achieve this, the source code is "open" for anyone to see and distributed along with the software and the according license. By these means, any user of the software has access to the code, can learn about it and develop it further Free use, modification and distribution is the core concept of OS. Many, but not all OS-licenses are distributed with a so-called copyleft-clause. Copyleft licenses do not only license the aforementioned types of exploitation, they do so only under the condition of re-distribution under the same license. The Open Source Initiative awards a cachet to all licenses that are in compliance with its Open Source Definition, which is a worldwide acknowledged standard. OS-licenses have been successfully tested in courts.

How to write a program in C programming language to multiply two polynomials?

#include <stdio.h>

#include <conio.h>

#define MAX 10

struct term

{

int coeff ;

int exp ;

} ;

struct poly

{

struct term t [10] ;

int noofterms ;

} ;

void initpoly ( struct poly *) ;

void polyappend ( struct poly *, int, int ) ;

struct poly polyadd ( struct poly, struct poly ) ;

void display ( struct poly ) ;

void main( )

{

struct poly p1, p2, p3 ;

clrscr( ) ;

initpoly ( &p1 ) ;

initpoly ( &p2 ) ;

initpoly ( &p3 ) ;

polyappend ( &p1, 1, 4 ) ;

polyappend ( &p1, 2, 3 ) ;

polyappend ( &p1, 2, 2 ) ;

polyappend ( &p1, 2, 1 ) ;

polyappend ( &p2, 2, 3 ) ;

polyappend ( &p2, 3, 2 ) ;

polyappend ( &p2, 4, 1 ) ;

p3 = polymul ( p1, p2 ) ;

printf ( "\nFirst polynomial:\n" ) ;

display ( p1 ) ;

printf ( "\n\nSecond polynomial:\n" ) ;

display ( p2 ) ;

printf ( "\n\nResultant polynomial:\n" ) ;

display ( p3 ) ;

getch( ) ;

}

/* initializes elements of struct poly */

void initpoly ( struct poly *p )

{

int i ;

p -> noofterms = 0 ;

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

{

p -> t[i].coeff = 0 ;

p -> t[i].exp = 0 ;

}

}

/* adds the term of polynomial to the array t */

void polyappend ( struct poly *p, int c, int e )

{

p -> t[p -> noofterms].coeff = c ;

p -> t[p -> noofterms].exp = e ;

( p -> noofterms ) ++ ;

}

/* displays the polynomial equation */

void display ( struct poly p )

{

int flag = 0, i ;

for ( i = 0 ; i < p.noofterms ; i++ )

{

if ( p.t[i].exp != 0 )

printf ( "%d x^%d + ", p.t[i].coeff, p.t[i].exp ) ;

else

{

printf ( "%d", p.t[i].coeff ) ;

flag = 1 ;

}

}

if ( !flag )

printf ( "\b\b " ) ;

}

/* adds two polynomials p1 and p2 */

struct poly polyadd ( struct poly p1, struct poly p2 )

{

int i, j, c ;

struct poly p3 ;

initpoly ( &p3 ) ;

if ( p1.noofterms > p2.noofterms )

c = p1.noofterms ;

else

c = p2.noofterms ;

for ( i = 0, j = 0 ; i <= c ; p3.noofterms++ )

{

if ( p1.t[i].coeff p2.t[j].exp )

{

p3.t[p3.noofterms].coeff = p1.t[i].coeff + p2.t[j].coeff ;

p3.t[p3.noofterms].exp = p1.t[i].exp ;

i++ ;

j++ ;

}

else

{

p3.t[p3.noofterms].coeff = p1.t[i].coeff ;

p3.t[p3.noofterms].exp = p1.t[i].exp ;

i++ ;

}

}

else

{

p3.t[p3.noofterms].coeff = p2.t[j].coeff ;

p3.t[p3.noofterms].exp = p2.t[j].exp ;

j++ ;

}

}

return p3 ;

}

What is better turbo c or dev C?

Depends upon the personal opinion. They both are different IDE. Dev C used the MICGW compiler while Turbo C uses Borland compiler. Hence due to this, certain inbuilt functions will not work in Dev C. clrscr() is one such function. However Turbo C is outdated and does not use follow many of the programming standards.

Which of the following is not a computer programming language BCPL Algol Q92 Forth?

(A) Basic (b) Turing (c) Java

Of these three choices, (B) Turing is not a programming language. Turing was a mathematician that defined the rules for a "complete" computer/programming language/etc. His contributions to computer programming included the definition for a "complete" language (one that could possibly simulate any real-world condition/environment/etc, irrespective of being able to run in real-time, just being able to calculate the state thereof), and defining two "comparable" machines, such that one machine can simulate another machine, and the second machine can also simulate the first. BASIC and Java are both programming languages.

Write a program that accepts two numbers a and b and checks whether or not a is divisible by b?

#include<stdio.h>

#include<conio.h>

#include<string.h>

int main (void) {

char arry[100];

int i,count=0;

float a,b;

printf("Enter a 2 Number ");

scanf("%d %d",&a,&b);

if(a%b == 0){printf("its divisible");} else {printf("its not divisible"); }

getch();

return 1;

}

What does Lisp mean in computer language?

LISP programming refers to creating applications using LISP languages - a family of old high level programming languages that used Polish notation. LISP languages are the second oldest HLLs after FORTRAN.

What does modular program and non-modualr program mean?

Modular programming is the technique which divides the entire program into smaller modules, which perform a specific task. Even though the simple program structure works well for simple examples, it is counter-productive for longer programs, leading to lack of clarity and slowing code maintenance and modification.

The programmer designs the program in levels, where a level consists of one or more modules. The first level is a complete main program and modules at successive levels consist of sub modules referenced in the prior levels.

A module is a set of program statements which, when acting together complete a specific task. In practice a module can be a function and the main program can consist of a sequence of calls to the functions that represent the modules of the next levels down.

The order in which the modules are executed by the computer is controlled by the main program. This describes fully the procedures required in the solution to a problem. The procedures are written in the order of the machine execution.

Modules should be structured within themselves by incorporating the constructs of sequencing, selection and repetition. Every program can and should be written using only these constructs.

What is cui mode?

command user interface & graphic user interface

Computer sap 1 architecture?

SAP is Simple As Possible Computer. The type of computer is specially designed for the academic purpose and nothing has to do with the commercial use. The architecture is 8 bits and comprises of 16 X 8 memory i.e. 16 memory location with 8 bits in each location, therefore, need 4 address lines which either comes from the PC (Program Counter whish may be called instruction pointer) during computer run phase or may comes from the 4 address switches during the program phase. All intructions (5 only) stores in this memory. It means SAP cann't store program having more than 16 instructions.

SAP can only perform addition and subtraction and no logical operation. These arithematic operation are performed by an adder/subtractor unit.

There is one general purpose register (B register) used to hold one operand of the arithmatic operation while another is kept by the accumulator register of the SAP-1.

In addition there are 8 LEDs, work as output unit and connected with the 8 bit output register.

All timely moment of data or activities are performed by the controller/sequencer part of the SAP-1.

Further details can be found in the Malvino Brown book, Computer design fundamentals-or may confirm the name of the book.

SAP 1

1) Program counter

2) Input MAR

3) The RAM

4) Instruction Register

5) Controller Sequencer

6) Accumulator

7) The Adder-subtrector

8) B Register

9) Output Register

10) Binary Display

That tells the rest of computer system how to carry out a programs instructions?

the answer is the CPU ( central processing unit). if you open up a file the CPU retrieves the files from the hard drive and are temporarily sent to the RAM (random access memory) until you close it. the same process apply's for programs.

How many computers were made in 2009?

The answer to this is based on your definition of the word "computer". At it's most simple form - a thermometer can be considered a "computer", as it is a machine that is "programmable" to follow a set of instructions and display output data. A sundial or compass are probably other great examples of simple computers. So I am thinking possibly billions of types of computers. Maybe hundreds per household.

Pointer is a variable holding a memory address?

pointer is a derived datatype which contains memory addresses as their values.

program:-

#include<stdio.h>

#include<conio.h>

void main()

{

int m=5,*p;

clrscr();

p=&m;

printf("address of variable m is %p",(void *)p);

}

Is c a compiler?

No, it is a letter.

Had you asked: 'Is C language a single-pass compiler',the answer would be: 'No, it isn't a compiler, it is a programming language'.

Is a linked list a physical data structure?

Physical data structures are how data is organized on a hardware storage device, and therefore how they appear to the computer. Logical or virtual data structures are software-based objects, and how the user or program sees it.

Although many file systems use a type of linked list format for storing information, a linked list is used for both hardware and software purposes, and therefore it cannot fall under either the physical or virtual data structure classification.

What software do you need to make a website?

You do not need software to make a website, though it does come in handy if you don't want to learn HTML/XHTML, JavaScript, and CSS. You can learn these three main languages, but it will take time and practice to make a good website. There are many websites out there that let you create a free "website" under a subdomain, such as mycoolsite.wordpress.com. Do a web search for "free website" and you'll find plenty of websites to try. Many of these offer paid upgrades such as you own domain (mycoolsite.com) or more advanced layouts.

What is the difference between Light-weight process and heavyweight process?

Light weight process are the process are the processes which is considered for the os as less burden like thread.means the threads are executing inside a process which share the same code and data also memory space of a single process that's it has a less burden to the os and considered as a light weight process.also the communication between the threads are much more efficient.

where as in case of a heavy weight process for doing multiple task the os has to create multiple processes which have a multiple memory address space and for communication between them they have to use inter process communication using sockets and pipe and which has more burden on the os than the threads(ligt weight processes) and hence considered as a heavy weight process

Frame sorting technique used in buffers?

Basically the frame are sent from the sender side by assigning a frame id,which could be a number.During the transmission of frames across the link the frames can be transmitted out of order w.r.t the frame id assigned to each of the frame.

The frames need to be in order to maintain integrity.

Even though the frames are sent in order,during the transmission the frames may experience delay or routing or any other event which can shuffle the order.

Thus frame sorting is done at the receiver side at the buffer at the DATA Link layer

before sending it to the higher layers.

The sorting can be done in many sorting techniques like bubble sort,merge sort etc.

What are the advantages and disadvantages of data encryption algorithms?

Advantages of DES over other algorithms:

  • DES has been around a long time (since 1978) and has been studied to death. Even now no real weaknesses have been found: the most efficient attack is still brute force. Of course the 56-bit key size is a disadvantage - see below.
  • DES is an official United States Government standard; the Government is required to re-certifyDES every five years and ask it be replaced if necessary. DES has been re-certified in 1983, 1987, 1992. (What happens this year?)
  • DES is also an ANSI and ISO standard - anybody can learn the details and implement it.
  • Since DES was designed to run on 1978 hardware, it is fast in hardware and relatively fast in software.

Disadvantages of DES:

  • The 56-bit key size is the biggest defect of DES. Chips to perform one million of DES encrypt or decrypt operations a second are available (in 1993). A $1 million DES cracking machine can search the entire keyspace in about 7 hours.
  • Hardware implementations of DES are very fast; DES was not designed for software and hence runs relatively slowly.

What is the most easiest way to write a GUI programs?

Typically, language is not the determining factor in developing or programming a GUI. More importantly is the application that determines the development platform you are using. At that point, language is not so much of a factor. Depending on the application and development platform, certain languages are better suited though, so once you choose your application, then you pick from the languages that are available. Still though, ease should not be a factor, but servicibility and reliability are way more important than ease of programming. If you can eliminate all other factors, than you can pick the simplest platform available, usually the highest level programming language that has everything you need is a good choice.

That said, some programmers will just go for the simplest platforms every time and try to shoehorn it into the problem they are trying to solve. Java's as popular choice for some apps, WinForms on .NET are also really simple for Windows apps, you can use various languages for that though, C# is pretty easy if you have the tools. Really depends on what you want to do for your GUI though, so there's not really one answer. You have to answer questions like, Is it a Web app, Phone app, Windows app, Apple App, or what? That really determines your programming language.

How can you determine the address of a two dimensional array element in c?

If the array is a local fixed-length array, use the address-of operator (&).

Example:

int x[3][4]; // local fixed-length array

int* p = &x[2][1]; // obtain the address of element x[2][1]

//...

For variable-length arrays we need to use a pointer and separate variables to keep track of the dimensions. C uses row-major semantics so the first dimension specifies the number of rows. However, the type of element in each row is not int, it is int[4], as per the second dimension. In other words, it is one-dimensional array of 3 one-dimensional arrays each of length 4. However, we cannot have a pointer of type int[4] because int[4] also decays to a pointer. We could use a pointer to pointer to int (int**), however in order to allocate the array contiguously without having to maintain a separate array of pointers into the second dimension, it is simpler to treat the array as if it were one-dimensional using a pointer to int (int*). After all, the actual elements we wish to access are integers, so that's what we should really be referring to, rather than to rows of arrays of integers which adds an unnecessary level of indirection. This then means we must use pointer-arithmetic to determine the address of each element. The following demonstrates how to use pointer arithmetic to access each element of a two-dimensional array through a pointer given only the row and column of the element we wish to access:

const size_t rows = 3;

const size_t cols = 4;

int* array2d = malloc (rows * columns * sizeof (int)); // allocate memory to the array

for (int row=0; row<rows; ++row) {

for (int col=0; col<cols; ++col) {

int* p = array2d + (row * cols) + col;

// ...

}

}

free (array2d); // release allocated memory

Here, row * cols determines the offset address of the start of the given row. array2d refers to the start address, so adding array2d gives us the actual address of the row. Adding col then gives us the address of the element within the given row. Note that array2d, &array2d and &array2d[0] are equivalent; they all refer to the start address of the array.

The same technique can also be used when passing a two-dimensional array to a function:

void f (int* array2d, const size_t rows, const size_t cols) {

for (size_t row=0; row<rows; ++row) {

for (size_t col=0; col<cols; ++col) {

int* p = array2d + (row * cols) + col;

// ...

}

}

}

What is difference in operating threads or process threads?

A process is an instance of a computer program. Each process has its own address space and executes concurrently with other processes. If the system has multiple CPU cores, two or more processes may execute simultaneously.

Every process has at least one thread of execution, the main thread. Any thread within a process can instantiate a new thread of execution within that same process. Every thread shares the same address space as the process itself, however each thread has its own local stack. This makes it possible for two threads to call the same function concurrently. If the system has multiple CPU cores, two or more threads within the same processes may execute simultaneously.

Programmers use multiple thread to divide complex tasks into simpler tasks that can be executed concurrently. As a simple example, suppose we must search an unsorted array of 1 million elements. We could use a single thread and search the entire array from beginning to end but there's a 50/50 chance the element we are looking for resides in the second half of the array which means that we'd need to search through 500,000 elements on average. By dividing the array between two worker threads we should get a result twice as quickly because each thread now only searches an average of 250,000 elements. It therefore follows that the more threads we utilise, the quicker we should get a result, but that's only true up to a point because the number of threads we can physically execute simultaneously depends on the number of CPU cores available. If all threads execute upon the same core then there is no point in multi-threading this particular task. Nevertheless, the task is likely to take some time to complete so it would still be beneficial to delegate the task to at least one worker thread.

For example, if the main thread manages a message queue, the worker thread can post messages to the queue to keep the main thread abreast of its progress. Meanwhile, the user can continue to interact with the process, posting messages to the queue to perhaps initiate another search (in another thread). In this way the main thread's task is reduced to nothing more than processing messages and delegating tasks to worker threads. This is clearly an over-simplification, however it's this type of multi-threading that makes it possible for a graphical user interface to remain responsive to user interactions while time-consuming tasks are being carried out in the background by worker threads.

What is a compiler and an interpreter?

a compiler translates an entire program and then executes it while an interpreter translates and executes one line of a program at time