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

Write a programm to check whether a matrix is upper triangular or lower trianglular?

#include<iostream.h> #include<conio.h> # define n 10 void main( ) { int mat[n][n]; int d; // Input elements cout<< "\n Enter dimension of square matrix:"; cin >> d; for(int i = 0; i < d ; i++) for( int j = 0; j < d ; j++) {cout<<"\n Enter elements for "<< i+1 << "," << +1<"location :"; cin >> mat[i][j]; } clrscr(); //Print the array cout<<"\n The Original matrix : \n\n"; for( i = 0; i < d ; i++) {for( j = 0; j < d ; j++) cout<< mat[i][j]<<"\t"; cout<< "\n"; } //upper half of left diagonal..... cout<<"\n The Upper half of the matrix : \n\n"; for( i = 0; i < d ; i++) { for( j = 0; j < d ; j++) { if(i < j) cout << mat [i][j] << " " ; else cout << " " << " "; } cout << "\n "; } //lower half of left diagonal..... cout<<"\n The Lower half of the matrix : \n\n"; for( i = 0; i < d ; i++) { for( j = 0; j < d ; j++) { if(i > j) cout << mat [i][j] << " " ; else cout << " " << " "; } cout << "\n "; } getch ( ); }

How do you convert octal digits into three binary digits?

C++ does not support octal encoding within source code (only decimal and hexadecimal are supported), so the octal must be represented with a string. The binary output must also be a string. Every octal digit represents three bits of binary, thus the binary output string will always be three times the length of the octal input string.

The loop will begin with the octal character at index 0 and work through each character from left to right. On each iteration, the binary output string will be appended with a 3-character string, as follows:

octal = binary

"0" = "000"

"1" = "001"

"2" = "010"

"3" = "011"

"4" = "100"

"5" = "101"

"6" = "110"

"7" = "111"

Thus octal input "437" will begin with the "4" producing an output of "100". On the next iteration, "3" will append "011" to produce "100011". On the final iteration, "7" will append "111" to produce "100011111".

What is the function of the instruction counter?

There is no such thing as an instruction counter. You are either referring to the instruction register (IR) or the program counter (PC), The PC is more commonly known as the instruction pointer (IP). The IR and IP work together.

The IR fetches the instruction currently pointed to by the IP which is then incremented to refer to the next instruction. The IR is then decoded and executed and the cycle repeats ad infinitum (known as the fetch-decode-execute cycle). However, if the fetched instruction is a control transfer instruction (such as JMP), its execution will cause the IP to refer to another address which, in turn, causes execution to "branch" to a new section of code on the next fetch-decode-execute cycle.

Note that a low-level JMP is equivalent to a goto statement in high-level code, however code can also branch through high-level if and switch statements as well as structured loops such as for, while and do-while statements.

What is the format specifier use with the data type double in c language?

double would be %e, %f or %g (depending on the format you want), long int would be %ld or %lu (signed or unsigned), long double would be %Le, %Lf or %Lg.

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 does GUI interfaces mean?

Graphic User Interface. One of the main uses is so that you can use a mouse to interact with your computer. The system lays out your screen as a grid and "knows" where the cursor is and where your icons are with respect to that grid. When you "click" your mouse button, the computer checks the cursor's location and compares it to the graphic objects(such as icons) and does whatever action it is programed to do. For example if you hover the cursor over the icon for Internet Explorer and double-click(in Windows), the computer starts your IE browser.

What is best and average case of binary search?

Merge sort is O(n log n) for both best case and average case scenarios.

How do you convert a character into its ascii value?

In C a character already is its ASCII value:

char c= 'A';

printf ("%c is %d (0x%x hexa)\n", c, c, c);

Write a c program using data structure to accept the details of employees from user and display it on the screen using dynamic memory allocation?

#include<stdio.h>

#include<conio.h>

#include<string.h>

#include<alloc.h>

void main()

{

int i=-1,j;

char ch='y';

struct emp

{

int eno;

char ename[30];

int salary;

};

struct emp *p;

clrscr();

p=(struct emp *)malloc(sizeof(struct emp));

while(ch=='y'ch=='Y')

{

i++;

printf("\nenter the employee id:-");

scanf("%d",&p[i].eno);

printf("\nenter the employee name:-");

scanf("%s",&p[i].ename);

printf("\nenter the salary:-");

scanf("%d",&p[i].salary);

printf("\ndo you want to continue(Y|N):-");

scanf("%s",&ch);

}

printf("\ninfromation about employees\n");

printf("employee id| employeename| salary");

printf("\n-----------|-------------|-------\n");

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

{

printf("\n%d | %s | \%d",p[j].eno,p[j].ename,p[j].salary);

}

getch();

}

/*--------------------OUTPUT--------------

enter the employee id:-101

enter the employee name:-peersaab

enter the salary:-12000

do you want to continue(Y|N):-y

enter the employee id:-102

enter the employee name:-santosh

enter the salary:-15000

do you want to continue(Y|N):-n

infromation about employees

employee id| employeename| salary

-----------|-------------|-------

101 | peersaab | 12000

102 | santosh | 15000

*/

Write an algorithm that reads 2 numbers from keyboard and displays their sum.?

#include<stdio.h>

int main(void) {

int a, b;

printf("Enter two numbers: ");

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

printf("%d + %d = %d\n", a, b, a+b);

return 0;

}

Write a program in c to print characters from A to z and Z to A?

Use this code:

#include <iostream>

using namespace std;

int main()

{int x;

for(x=0; x<27; x++)

if(x 26) cout<< "z" << endl;

return (0);

}

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 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.

Is PHP a compiler or interpreter?

It is normally interpreted by another computer program. However subsets of the language can be compiled.

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();

}

Where can you download MicroType pro for free?

yes you can but i am trying to find out where you can!!

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

How would you write a c program using nested loop that output the values are 1 22 333 4444 55555?

The solution is two use a nested for loop:

int startingNum = 1;

int maxNum = 10;

for(int currentNum = startingNum; currentNum <= maxNum; currentNum++)

{

for(int j = 0; j < currentNum; j++)

{

printf("%d", currentNum);

}

printf("\n");

}

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 type of loop is used to write a program that prompts the user for a value until the user enters -1?

Any type will do, here is an example:

for (leave= 0, nnum= 0; ! leave; ) {

rc= scanf ("%d", &number);

if (rc!=1 number==-1) { leave=1; continue; }

++nnum;

... do something with number ...

}

How the array has to be declared and initialized?

An example might help

int myarray [] = {2,0,1,3,1,1,2,9};

What Is The Difference Between Control and Uncontrolled statements?

ctrl statements ctrl the flow of pgrm execution with the given condisn but ctrl transfer statemens causes the change in pgrm flow without any condisn....

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.