answersLogoWhite

0

📱

Computer Programming

A category for questions about computer programming and programming languages.

10,506 Questions

When would you use a count controlled loop vs. a flag controlled loop?

Counter Loop:

Counter loop is a loop which executes statement up to a fixed number of time.

In GW FOR ... NEXT loop is used as counter loop.

Controlled Loop:

Controlled loop is used to extend the statements till a specific condition is satisfied. In GW WHILE ... WEND is used as controlled loop.

What is main function of printf in a C program?

The syntax for printf is:

int printf(const char *format, ...);

Simple usage examples:

1. Print character literal: printf("%c", 'a');

2. Print character variable: printf("%c", my_char);

3. Print string literal: printf("%s", "hello world");

4. Print string variable: printf("%s", my_string);

5. Print integer variable: printf("%d", my_integer);

6. Print floating-point variable: printf("%f", my_float);

What is recursive algorithm to find the height of a binary search tree with n numbers of nodes?

Really the best way to traverse any binary tree is recursion. In this case we are going to be some node defined as having 3 values, a pointer to a left node, a pointer to a right node, and a value.

then in psudocode we can do it as:

int height(node n, int depth){

int leftDepth;

int rightDepth;

if(n.left != NULL)

leftDepth = height(n.left, depth+1)

else

leftDepth = depth;

if(n.right != NULL)

rightDepth = height(n.right, depth+1)

else

rightDepth = depth;

if(leftDepth > rightDepth) return leftDepth;

return rightDepth;

}

Essentially what you are doing is calling the algorithm on both the left and right nodes which in turn will call it on their left and right nodes, down to where all the nodes are null. Then what is returned is the greater depth of the two; because it will traverse before returning a depth, and only traverses if there is a deeper node, it will return the depth of the deepest node, or the height of the binary tree.

Difference between data and program?

well program is a set of instructions that are given to computer to perform perticular task as we want.

And data is any information that is stored in computer hard disc. it can not make any control on computer of computer related process.

What do you understand by complexity of sorting algorithms?

By understanding the time and space complexities of sorting algorithms, you will better understand how a particular algorithm will scale with increased data to sort.

* Bubble sort is O(N2). The number of Ops should come out <= 512 * 512 = 262144 * Quicksort is O(2N log N) on the average but can degenerate to (N2)/2 in the worst case (try the ordered data set on quicksort). Quicksort is recursive and needs a lot of stack space. * Shell sort (named for Mr. Shell) is less than O(N4/3) for this implementation. Shell sort is iterative and doesn't require much extra memory. * Merge sort is O( N log N) for all data sets, so while it is slower than the best case for quicksort, it doesn't have degenerate cases. It needs additional storage equal to the size of the input array and it is recursive so it needs stack space. * Heap sort is guaranteed to be O(N log N), doesn't degenerate like quicksort and doesn't use extra memory like mergesort, but its implementation has more operations so on average its not as good as quicksort.

Must a computer algorithm contain a loop?

No. An algorithm is a procedure or formula for solving a problem: a finite series of computation steps to produce a result. Some algorithms require one or more loops, but it is not true that every algorithm requires a loop.

Why calculations in computer systems are performed in binary and not ASCII?

Everything has to be binary encoded since it's the only language natively understood by a binary computer. Even ASCII character codes must be binary encoded. However, it's not clear how you would use ASCII to perform a calculation since the American Standard Code for Information Interchange is a character encoding scheme that maps 7-bit binary codes to glyph bitmaps according to the current ASCII code page. You can certainly use the encodings in calculations, but not the characters themselves, because the digits '0' through '9' in the ASCII table do not map to the values 0 through 9. In order to translate an ASCII digit to the value it represents, you first have to subtract 48 from the ASCII character value. From the computer's perspective, determining the actual value represented by the character '7' requires the binary calculation 00110111 - 00110000 = 00001110. In hexadecimal, this equates to 0x37 - 0x30 = 0x07, because 0x37 maps to character '7' in the ASCII table, while 0x30 maps to '0'. Thus you could also say '7' - '0' = 7.

What is low level programing languages?

The programs written in Machine codes (like hexadecimal codes) are the Low level programs. These are understood only by the Microprocessor they are written for and written on.

Whereas the High level programs are written in English like languages which are human redable.

How to save output in separate file for c programs?

You can have more than one output-file opened in the same time, see manuals of functions fopen, fclose, fwrite, fprintf, ...

How do you destroy a hacker?

you find his ip address and you type this in your command prompt window.. format *.*

it will format his hard drive, make his monitor catch fire, and his computer will start laughing at him in a evil Satan voice

seriously thou... DONT DO THAT.. its a joke

you don't destroy a hacker, you just protect yourself from one.. its called a firewall or antivirus

How many languages in OOP?

Thousands! Programming languages number in the thousands, from general purpose programming languages such as C++, Java, and others, to special purpose languages which are used in one application. They can be ordered by type (structured, object-oriented, functional, etc.) or by history, or syntax. See the related list of programming languages.

A program in c that identifies the longest word in a sentence?

#include<stdio.h>

#include<string.h>

#include<conio.h>

void main()

{

int i,max=0,count=0,j;

char str[100]; /* ={"INDIA IS DEMOCRATIC COUNTRY"}; u can use a string inside,in place of user input */

printf("\nEnter the string\n:");

gets(str);

for(i=0;i<strlen(str);i++)

{

if(!(str[i]==32))

{

count++;

}

else

{

if(max<count)

{

j=i-count;

max=count;

}

count=0;

}

}

for(i=j;i<(j+max);i++)

printf("%c",str[i]);

getch();

}

When was the fifth generation programming language developed?

The only decent attempt at a 5th generation programming language was done by japan in the 90's and it was based on prolog. It was deemed too slow and inefficient to be of viable use, and as such there has been no marketable 5gl to date, so the question would have been better posed as 'Is there a fifth generation programming language?' - also note that the idea of 5gl is just that, an idea. Even if we succeed in creating a 5gl, it will be 'A' 5gl language, not 'THE' 5gl language

What is the difference between integer and floating point data?

Actually float and double are both numeric data types that are used to store large numbers. They can have a lot of digits after the decimal point in the number. The actual difference between them is in size. According to the Java Language Specification, a float is a 32-bit value, while a double is a 64-bit value. Otherwise they work in the same way with respect to one another.

What is basic terminology for data structure?

Transversing

Accessing each record exactly once so that certain items in the record may be processed.(This accessing or processing is sometimes called 'visiting" the records.)

Searching

Finding the location of the record with a given key value, or finding the locations of all records, which satisfy one or more conditions.

Inserting

Adding new records to the structure.

Deleting

Removing a record from the structure.

Sometimes two or more data structure of operations may be used in a given situation; e.g., we may want to delete the record with a given key, which may mean we first need to search for the location of the record.

Give 10 example of close loop control system?

1. lightswitch --> light

2. Toaster --> toast (For timer-based toasters, only -- see below)

3. Water faucet --> water flow amount

4. Water faucets (hot/cold) --> water temperature in the sink or shower.

5. Temperature setting for the stovetop --> heat to cook food

6. TV remote control

7. Clothes dryer (timer based)

8. Volume on a stereo / home entertainment system

9. shades / blinds on a window --> 'regulating' the amount of light coming in from the outside.

10.

Closed loop:

1. Thermostat --> furnace (constant temperature)

2. Toaster setting (light/dark) --> toast (IF the toaster has heat sensors)

3. Refrigerator cold/hot setting --> refrigerator inside temperature (constant)

4. Temperatue setting for oven (not stovetop) --> oven temperature constant

5. Clothes dryer with moisture sensor

6. Washing machine water level

Which of these computer languages was designed to teach mathematical concepts?

AMPL: A Modeling Language for Mathematical Programming (Hardcover)
A Mathematical Programming Language

What are Static variables in c?

A static variable in C is a variable whose value and memory allocation persists throughout the execution of the program. If the variable is declared at file scope (outside of any blocks) the static attribute means the variable is visible only to the file containing it, i.e. it can not be referenced through an extern reference in a different file.

What are the attributes of good programming languages?

There are many attributes that make up a good programming language. Here are some of the most important ones:

Readability: A good programming language should be easy to read and understand. This makes it easier for developers to write and maintain code, and reduces the likelihood of errors.

Maintainability: A good programming language should be easy to maintain and update. This includes having clear and concise syntax, as well as tools for debugging and testing.

Performance: A good programming language should be efficient and fast. This includes having a low memory footprint, minimal overhead, and fast execution times.

Portability: A good programming language should be portable, meaning it can run on different platforms and operating systems without significant changes.

Flexibility: A good programming language should be flexible enough to accommodate different programming styles and paradigms, as well as be extensible with libraries and frameworks.

Safety: A good programming language should prioritize safety and prevent common programming errors, such as null pointer dereferences or buffer overflows.

Community: A good programming language should have a supportive and active community of developers who contribute to its development, documentation, and maintenance.

Tooling: A good programming language should have a robust ecosystem of tools, such as editors, IDEs, and build systems, that make development and deployment easier and more efficient.

Scalability: A good programming language should be able to scale with the needs of the project, whether it be a small script or a large-scale enterprise application.

Future-proofing: A good programming language should be designed with a long-term vision, taking into account future developments in hardware, software, and technology trends.

Why do you need signed and unsigned integer?

We need signed integers in order to represent both negative and positive values. However, some numbers can never be negative. For instance, the size of a file must always be greater than or equal to zero so we use unsigned integers to represent file sizes. Also, natural numbers must be greater than 0 so there's no point in using a signed value to represent a natural number. Signed integers also use one bit to denote the sign, but unsigned integers do not thus unsigned integers can effectively represent twice the range of positive values than an unsigned integer can. For instance, an 8-bit signed value can represent values in the range -128 to +127 using twos complement notation, but an 8-bit signed value can represent values in the range 0 to 255.

Write a C program to print numbers from 1 to 999 in words?

write a c program which reads an integer value from the keyboard then it displays the number in words?

#include<stdio.h>

#include<conio.h>

void main(void)

{

int rev,n,

clrscr();

printf("\n enter any number");

scanf("%d",&n);

temp=n;

while(n>0)

{

rem=temp%10;

rev+=rem*10;

temp=temp/10;

choice=rev%10;

switch(choice)

{

case 1:

printf("one");

break;

case 2:

printf("two");

break;

case 3:

printf("three");

break;

case 4:

printf("four");

break;

case 5:

print("five");

break;

case 6:

printf("six");

break;

case 7:

printf("seven");

break:

case 8:

printf("eight");

break:

case 9:

printf("nine");

}

getch();

}

What are the unique advantages of object oriented programming paradigm?

a. OOP provides a clear modular structure for programs which makes it good for defining abstract datatypes where implementation details are hidden and the unit has a clearly defined interface.


b. OOP makes it easy to maintain and modify existing code as new objects can be created with small differences to existing ones.


c. OOP provides a good framework for code libraries where supplied software components can be easily adapted and modified by the programmer. This is particularly useful for developing graphical user interfaces.