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 program to subtract two 3x3 matrices?

The value of a static global variable can never be changed whereas the value of a simple global variable can be changed.

how to create a 3x3 matrix written in c++:

#include

#include//this is only for if you want a string matrix

using namespace.std;

int main()

{

string yourstinghere[3][3];

}

Is the C Plus Plus language good for making software?

C++ is one of the most flexible programming-languages there is. So, my first answer would be 'Yes'. However the question is, if C++ is the most suited language for the software that you want to make. There may be a alternative, easier language, in wich you can develop your software. Jahewi :-)

What is an abstract data structure?

Abstract Data Type in computing is a set of data along with a set of predefined operations.

The actual data inside the ADT is protected from direct manipulation. The exposed operations is the only way to manipulate the data.

In easier terms, it is very much like (though not limited) to the objects in object oriented programming.

What does putting your pointer finger to your lips?

word: seducing yourself

action of it crossing pointer fingers over your lips: you are going to make out with yourself and look at hot girls kissing each other on youtube!

SO EVERYONE CROSS YOUR POINTER FINGERS OVER YOUR LIPS!!!

call me baby

HOW can a program that outputs the days of the week using switch statement be created?

#include<stdio.h>

#include<conio.h>

void main()

{

int n;

printf("enter the value of n");

scanf("%d",&n);

switch(n)

{

case1:printf("monday");

break;

case2:printf("tueday");

break;

case3:printf("wednesday");

break;

case4:printf("thursday");

break;

case5:printf("friday");

break;

case6:printf("saturday");

break;

case7:printf("sunday");

break;

default:printf("invalid number");

}

}

What are queues?

A queue is a first-in, first-out data structure. We use queues when one thread needs to communicate with another but they operate at different frequencies (asynchronously), such that the first thread may produce input for the second thread faster than the second thread can actually process each input. Thus the first thread will place each input on a shared queue and the second thread can deal with each in turn as and when it is ready. To avoid data races, all operations that modify the queue must be mutually exclusive, such that only one thread can gain access to these operations at any given moment. This can be implemented using a lock, such that only one thread can "own" the lock while all others must wait until the lock is released.

Example of formatted functions in C?

formatted functions::: Follows a fixed format like scanf,printf

Unformatted functions:::Do not have fixed format like gets,getchar

What is char data types?

The char data types holds a single ASCII (or unicode) value, so it holds any character, for example: '2', 'r', or '~'. The problem is it only holds one character, not a whole string. That is why the string was developed; it holds a whole bunch of characters in a row. But strings cant be compared with < and >, so for alphabetical ordering, use char.

What is the difference between array and enum?

Array is collection of data items of same data type.
Enum is collection of data items of different data type.

What are the factors that determine the choice of programming language when developing an application?

It's more often than not, not a programmers choice, but when it is, typically:

Platform (e.g. if you are writing something for Android, or iOS, your choices are somewhat limited, same goes for cross OS compatibility) Objective (e.g. are you writing a kernel module or a website)

Familiarity (e.g. if i know Ruby and don't know PHP)

Performance needs (e.g. am i writing a network stack or a text editor)

Libraries (e.g. PHP built-in database libraries, Java does not)

Language specifics/purpose (e.g. it's a good idea to write a protocol in more functional programming language like Scala than in Perl or Java)

What is the difference btween compilation and execution?

They are similar
make = create something
compile = implies you are using other things and putting them together to create something eg. lists for reference something made can have been compiled, but might not
something compiled is also made

Algorithm to count the digits in a given number?

def digits(x):
""" Return amount of digits of x. """
y = math.log10(x)
if y % 1 0:
return int(y)
else:
return int(math.floor(y) + 1)

How do you write a program in C that will captures details The details to be captured are student name mark and age The program should calculate and display the average marks for all the students?

Create a data structure to store the details for each student:

typedef struct student_t {

char name[30];

unsigned age;

unsigned mark;

} student;

Establish an array to store the student data:

size_t max = 100; // replace 100 with the actual number of students

student students[max];

Use a loop to enter the data:

for (size_t i=0; i<max; ++i) {

printf ("Student name: ");

scanf ("%s", students[i].name);

printf ("Student age: ");

scanf ("%u", students[i].age);

printf ("Student mark: "); scanf ("%u", students[i].mark);

}

Calculate and display the average mark:

unsigned sum = 0;

for (size_t i=0; i<max; ++i) sum += student[i].mark;

printf ("Average mark: %d\n", sum / max_students);

The meaning of if in C language?

if is a like a choice

e.g.

if (x==1) if x is equal to 1 then it will print "x=1"

{

printf("x=1);

}

else

{

printf("x does not =1")

}

Answer: If is an identifier, if is a statement.

How do you accept values of array of structure from user in c?

How do you accept total no of array elements and values from the user in c?

What is iteration in c programming?

Iteration means what it says: the act of repeating a process. Each repetition of the process is itself an iteration, and the results of one iteration can be applied in the next iteration. Counting from 1 to 10 is an example of an iterative process because each iteration increments the counter by 1.

Iteration should not be confused with recursion. Although similar, a recursion occurs when a function calls itself. Such functions are known as recursive functions and these make use of the call stack to remember the "state" of each function prior to the next call, thus allowing those states to be restored when the recursive calls return (known as "unwinding"). Since the call stack must be maintained regardless of the depth of calls, recursive routines that do not need to remember the state of each recursion are inefficient, and are often better implemented as iterative loops. However, this may require nested iterations and, if the depth is too variable or complex to be calculated at compile time, or the maximum depth would be greater than 16 then the cost of recursion will often be preferred to the increased code size iteration would incur. Even so, recursive functions can often be inline expanded by the compiler as iterative functions, thus simplifying the source code without sacrificing the performance.

What is bubble sort?

Bubble sort is a sorting algorithm that compares 2 adjacent items at a time, starting from the beginning of a list, and swapping them if they are out of sequence. Each comparison gradually moves the largest item to the end of the list (likened to a bubble making its way to the surface of water). After n*n passes, all the items will be sorted. The big O for a standard bubble sort is therefore O(n*n).

The algorithm can be improved somewhat. Since it is clear that the last item is sorted on each pass, the unsorted set can be reduced by 1 element on each pass. Moreover, since the final swap on each pass indicates that everything from that point on is already sorted, the unsorted set can often be reduced by more than 1 element on each pass. For an already sorted list, the worst case is reduced to O(n), constant time.

For small sets of data, perhaps 10 to 20 items, the bubble sort is reasonably efficient, especially on partially sorted lists. However the insert sort algorithm offers similar or better performance on average. With larger sets, the quick sort algorithm is hard to beat, but is let down by inefficiencies when dealing with partially sorted lists. Hybrid sorts can improve things a little, however, there is no efficient way to check the state of a list to determine the most efficient algorithm to use at any given point.

Write a c program to print squares of all numbers from 1 to 100 inclusive?

#include
int main()

{

int i,sum=0;

for(i=1;i<=100;i++)

sum=sum+i;

printf("Sum

of first 100 natural number is %d\n",sum);

return(1);


}

What is an expanded data processing cycle?

The data processing cycle is used anywhere data has to be input and processed in order to achieve a desired output. That output may be then used as input for additional processing, repeating the cycle. During processing, data is also stored for later use, whether to be processed along with new input or to provide input for other processes, thus creating new output.

The expanded cycle is the same, the only difference being that data has to be originated before being input, while the output has to be distributed. The originated data is known as the source document, which could be something as simple as an appointment booking form that you fill in. The data from that document is then input and processed (and stored), and the output is distributed in the form of report documents, which could be as simple as a letter telling you when your appointment is, a copy of which will be kept on file along with the source document. When you come to attend your appointment, your report document becomes the source document, which is then input and processed, and the output distributed, confirming your attendance for the appointment. During the appointment, new data is originated, thus starting the cycle all over again.

Design a fish and give movement with suitable animation function in C programming?

: #include<graphics.h> #include<stdio.h> #include<conio.h> #include<alloc.h> #include<math.h>

#include<dos.h> const pi=3.14; void main() {int gd=DETECT, gm,i,x,y; int size; void *buf; initgraph(&gd,&gm,"c:\\tc\\bgi"); ellipse(240,210,0,160,90,45); ellipse(240,190,180,360,90,45);

circle(170,195,3); ellipse(100,230,10,400,100,80); ellipse(232,207,0,365,100,150); arc(265,170,0,160,15); arc(225,233,180,350,20); arc(265,233,180,380,10); size=imagesize(150,150,350,350); buf=(char *)malloc(size); getimage(150,150,350,350,buf);

for(i=0;i<=360;i+=2) {delay(10); cleardevice(); x=150*cos(i*pi/180); y=150*sin(i*pi/180);

putimage(200+x,100+y,buf,0); } getch(); restorecrtmode();}

Explain virtual functions in C plus plus?

A virtual function in C++ is a function that can have multiple definitions.

For example:

If you have a class which contains a virtual function:

class Virtual

{

virtual void makesomething();

};

That function can be implemented when you inherit that class an implement the function. So:

class Inherit : public Virtual

{

//this is the same function, but can be implemented to do something different

void makesomething() { //do something else }

};

How many constructors can c have?

A class can have any number of constructors, as far as they are having different parameters or different number of parameters. For example, a class A can have following constructors & even more:

A() -the default constructor

A(A objectA) -the copy constructor

A(int p)

A(int p1, int p2)

A(int[] p1, float p2)

A(double p1, double p2, int p3)

A(A objA, int[] p)

A(B objB)

Write a program that ask for a user name and age and must print out the information?

#include
#include
void main()
{
int age;
clrscr();
printf("Enter the Age:");
scanf("%d",&age);
printf("Your age is %d",age);
getch();
}