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)
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.
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();
}
C program to swap two variables without using third variable?
you can do it in the following manner
Supposing your two variables are x and y:
int x=3;
int y=5;
x=x+y; [x becomes 8]
y=x-y; [y assumes the original value of x i.e. 3]
x=x-y; [x assumes the original value of y i.e. 5]
or... you can use the unary XOR (exclusive or) operator, '^=' .
Same values, int x=3, y=5
x ^= y; // x becomes 6
y ^= x; // y becomes 5
x ^= y; // x becomes 3.
The second method has more advantages :
- Its assembler operations never use the processor's ALU carry.
- Without use of the aforementioned carry, no overflow will ever occur.
- Performing this with 32-bits values 8-bits processors will be more efficient, in terms of program space AND execution speed.
- You can even use this in Visual Basic an other languages which implements boundaries on values, while the first method is guaranteed to fail when overflows occurs.
In both case, do not EVER try to factorize these 3 lines into two, as the operations order in multiple-operators lines depends on the compiler's way to parse your code.
Thus , typing
x = x ^ y ^x;
y = y ^ x;
Will surely give you garbage.
programming syntax is defined as a predefined pattern in which the program is written. for example:-
the programming syntax in c is as:
#include<headerfile or prototype> as per need.
global declaration.
main function or(void main)
{
body of coding; //comments
}
user defined functions()
{
coding; //comments
}
Why you use colon in C language?
In C (and C++ and Java), the semicolon is used to mark the end of a statement. It is also used the separate the expressions in a for loop.
What is class in oops concept?
Classes are the integral part of the all-important programming paradigm known as Object-Oriented Programming(OOP). In OOP, a programming problem is perceived as a problem in a real-life scenario, as an interaction between objects. The problem is tackled by having a system of interacting objects, that interact among themselves to solve the programming problem. Objects in OOP bear semblance to real-life objects. Classes serve as templates for the creation of objects of the same type. For instance, students may be thought to be objects of the human-being class, cars may be thought to be objects of the Automobile class. Classes are defined as collection of methods(functions) and data members(variables), additionally defined by scope rules. In addition, classes also achieve the OOP principles of encapsulation, abstraction, polymorphism and inheritance. Encapsulation refers to binding data and code together, with data controlling access to code. Abstraction refers to the hiding the implementation details of a class from outside functions and exposing only necessary details. Polymorphism refers to the scenario when a class can play more than one role. Inheritance is used when one or more classes must include properties of another set of classes, and also have properties of their own.
Which operator is called ternary operator?
A ternary operator is an operator that requires three operands, as opposed to a binary operator that requires two operands and a unary operator that requires just one operand.
C++ has just one ternary operator, the conditional ternary operator:
<boolean expression> ? <expression #1> : <expression #2>;
If the boolean expression evaluates true, the first expression is evaluated, otherwise the second expression is evaluated.
A typical usage of this operator is to return the larger (or smaller) of two values of type T:
template<typename T>
T max (T a, T b) {return a<b ? b : a};
template<typename T>
T min (T a, T b) {return a<b ? a : b};
These are really nothing more than notational shorthand for the following:
template<typename T>
T max (T a, T b) {if (a<b) return b; else return a; };
template<typename T>
T min (T a, T b) {if (a<b) return a; else return b;};
However, because ternary expressions are evaluated, the return value of the expression can be used in more complex expressions:
int a=42, b=0;
// ...
int c = ((a>b ? a : b) = 1);
In the above expression, whichever is the larger of a and b will be assigned the value 1 which will also be assigned to c. Thus a and c become 1 while b remains 0.
Count the number of nodes of a binary tree having depth n?
Use the following formula: (2^n)-1. E.g., if the depth is 3, the number of nodes is (2^3)-1 = 8-1 = 7. Note that 7 is the maximum number of nodes, not the actual number of nodes. To count the actual nodes you must traverse the tree, updating an accumulator as you go.
How do you sort names alphabetically using pointers?
#include
#include
int main(void)
{
int item[100];
int a, b, t;
int count;
printf("How many numbers? ");
scanf("%d", &count);
for(a = 0; a < count; a++)
scanf("%d", &item[a]);
for(a = 1; a < count; ++a)
for(b = count-1; b >= a; --b) {
if(item[ b - 1] > item[ b ]) {
t = item[ b - 1];
item[ b - 1] = item[ b ];
item[ b ] = t;
}
}
return 0;
for(t=0; t
}
Basic operation of stack and Queue?
A stack is a data structure in which last item inserted is taken out first . That's why they are known as LIFO (last in first out). Inserting an item in stack is termed as push and taking an item out from stack I s termed as pop. Some applications of stack are : Polish notation, reversing string, backtracking , quick sort algorithm etc. The queue is a linear data structure where operations od insertion and deletion are performed at separate ends also known as front and rear. Queue is a FIFO structure that is first in first out. Whenever a new item is added to queue, rear pointer is used. and the front pointer is used when an item is deleted from the queue.
Data types in c primitive and non primitive?
Primitive types are the data types provided by a programming language as basic building blocks. Primitive types are also known as built-in types or basic types.
Depending on the language and its implementation, primitive types may or may not have a one-to-one correspondence with objects in the computer's memory. However, one usually expects operations on primitive types to be the fastest language constructs there are. Integer addition, for example, can be performed as a single machine instruction
You are having Problem in c c plus plus assignment Who can help you?
Get Expert C Assignment Help at ProgrammingHomeworkHelp. 📢
Struggling with your C assignments? 🤔 Don't worry, we've got your back! 🎯
🔍 Need quick solutions for complex C programming problems?
📚 Looking for expert guidance to enhance your coding skills?
🎓 Seeking affordable and reliable C assignment help?
🌟 Your search ends here! 🌟
🎉 Introducing Programming Homework Help, your one-stop destination for top-notch C assignment assistance. Our team of experienced programmers is ready to tackle any challenge and provide you with tailor-made solutions. 🎓💼
Why choose us? 🤔
✅ Expert Programmers: Our skilled C programmers are well-versed in handling diverse assignments, ensuring you receive accurate and efficient solutions.
✅ Timely Delivery: No more missing deadlines! We value your time and guarantee timely delivery of your completed assignments.
✅ 24/7 Support: Got a last-minute query? Our customer support is available round-the-clock to address all your concerns.
✅ Plagiarism-Free Work: We take academic integrity seriously, and all our solutions are 100% original and plagiarism-free.
✅ Affordable Prices: Quality assistance doesn't have to be expensive! Our services are priced competitively to fit your budget.
Don't let C assignments stress you out! 🤯 Let our experts handle the technicalities while you focus on excelling in your studies. 📚📈
💡 Excelling in C programming is just a click away! 💡
SQL Training courses are invaluable to those who want to pursue a career in database administration and for those who work in the general field of IT.
There a number of ways to participate in SQL training , from self teaching SQL books to online SQL training courses and of course, IT courses in educational institutes such as colleges or universities. Online courses and self teaching books offer way to learn SQL when you are in full time employment. The only real requirement with this way of SQL training is that you have some prior programming knowledge as the technical language on these courses can be quite hard to understand if you have never used it before. With this type of SQL training there is set format to lessons and you work at your own pace. There is a risk that you will have days where you do not feel motivated to study thus, slowing your SQL training progress, however, if you do not have the time or financial aid to begin a college or university course this may be the best option.
Other SQL training courses on offer can be taken at a variety of universities and community colleges, with many of them offering part time and evening courses to those in full time employment. These are more structured learning environments and are suitable for full time IT students, professionals who have the right amount of free time and for those who know their limitations to teach themselves. With institute based SQL training there is the benefit of having a tutor who specializes in the subject matter so that you will be able to seek advice on the SQL training when needed rather than having to research yourself.
Overall there a number of SQL training courses available for all differing levels of ability from the first steps into database maintenance to refresher courses for IT professionals. Whether you are looking for a career in IT or just the basic knowledge to enable you to know how to move around a database, SQL training is a useful tool to have.