Polynomial multiplication in link list using c language?
#include
#include
struct polynode
{
float coeff;
int exp;
struct polynode *link;
};
void poly_append(struct polynode **,float,int);
void display_poly(struct polynode *);
void poly_multiply(struct polynode *, struct polynode *, struct polynode **);
void padd(float, int, struct polynode **);
main()
{
struct polynode *first, *second, *mult;
int i,coeff,exp,high;
first = second = mult = NULL;
printf("Enter the highest power of polynomial 1: \n");
scanf("%d",&high);
for(i=high;i>0;i--)
{
printf("Enter value for coeff for X^%d : ",i);
scanf("%d",&coeff);
poly_append(&first, coeff,i);
}
printf("\nEnter the highest power of polynomial 2: \n");
scanf("%d",&high);
for(i=high;i>0;i--)
{
printf("Enter value for coeff for X^%d : ",i);
scanf("%d",&coeff);
poly_append(&second, coeff,i);
}
printf("\n\n");
display_poly(&first);
printf("\n");
display_poly(second);
printf("\n");
for(i=1;i<=79;i++)
printf("-");
poly_multiply(first, second, &mult);
printf("\n");
display_poly(mult);
}
/* adds a term to a polynomial */
poly_append(struct polynode **q, float x, int y)
{
struct polynode *temp;
temp = *q;
/* create a new node if the list is empty */
if(*q NULL ) )
{
r = malloc ( sizeof ( struct polynode ) );
r -> coeff = c;
r -> exp = e;
r -> link = temp -> link;
temp -> link = r;
return;
}
temp = temp -> link; /* go to next node */
}
r -> link = NULL;
temp -> link = r;
}
}
How do you clear a character in screen in c language?
this is a tricky one... press alt + f4 and see if that works.
Write your own printf and scanf functions?
just include #define next to #include
or
/*just follow the pattern below*/ example:
#include
#include
#define pf printf
#define sf scanf
void main
{
int number
pf("Enter a value:");
sf("%i",&number);
getch();
}
Write a c program the extracts and prints the rightmost digit of the integral portion of the float?
#include<stdio.h>
int main (void)
{
float x,y;
int z,w;
printf("enter a number:");
scanf("%6.2f",&x);
y=x/10.0;
z=x-y;
w=z%10;
printf("the rightmost digit is %d\n",w);
return 0;
}//main
What is the middle item in binary search algorithm?
Binary search functions by taking a sorted linear list of items, then starting at the middle of the list testing "is it equal?", "is it less?" and "is it more?"
If it is equal, then you've found your item.
It it's less than what you're looking for, then you should skip to half way between the end of the list and where you currently are positioned and try again there.
If it it's more, skip to half way to the start of the list.
As you progress, you'll narrow in on your target.
The middle item is the item located between the two points of searching. To start it's the first and last item in the list. Following, it's the midpoint between the current item and the previous item checked.
Can you change the name of main function in C programming please explain me?
c:\>type 1.cpp
int my_main(int argc, char* argv[]) { printf("my_main\n"); return 0; }
c:\>cl 1.cpp /MD /link /SUBSYSTEM:CONSOLE /ENTRY:my_main Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.42 for 80x86 Copyright (C) Microsoft Corporation. All rights reserved.
1.cpp Microsoft (R) Incremental Linker Version 8.00.50727.42 Copyright (C) Microsoft Corporation. All rights reserved.
/out:1.exe /SUBSYSTEM:CONSOLE /ENTRY:my_main 1.obj
c:\>1 my_main
c:\>
With any text-editor, but be warned: if you don't have a function by name main, your program won't build (right, if in Windows, then it is WinMain).
I suppose a crate full of them could fall on your head ...
Or someone could shine one in your eyes when you were driving ...
But barring something like that, laser pointers do not have enough power to harm skin. You shouldn't look directly at them (as the sign on more than one research laser I've seen says, "Do not stare directly into beam with remaining eye"), but you can shine it at your hand for as long as you like.
Disadvantages of enumeration in c?
The big disadvantage I've found is that you might mistake it for a user-defined type. It's not; you still have to use int for your variable type and compilers will not do anything to help restricted assignment to values from the enumeration.
A "callback URL" is the web address an API needs to send information for use in a different web site.
For example, a web developer is building a web application for use in conjunction with another web service's API (such as Facebook or Last.fm). The application is hosted on the web developer's server, and the other web service stores the callback URL so that it knows where to send information when it is requested by the developer's application.
See Also: http://en.wikipedia.org/wiki/Callback_(computer_science)
Write a c program whether a given word is palindrome do using function?
int main(int argc, char* argv[])
{
char a[10],b[10];
printf("enter any string\n");
scanf("%s",a);
printf("a=%s",a);
strcpy(b,a);
strrev(b);
printf("\nb=%s",b);
if(strcmp(a,b)==0)
printf("\nstring is palindrome");
else
printf("\nnot pelindrome");
return 0;
}
How do you convert ASCII to BCD?
void main ()
{
unsigned char hrs,mins,secs;
char ch1, ch2;
puts("\nEnter the hours to update: ");
ch1=getche();
ch2=getch();
hrs = ASCIItoBCD(ch1, ch2);
puts("\nEnter the minutes to update: ");
ch1=getche();
ch2=getch();
mins = ASCIItoBCD(ch1, ch2);
puts("\nEnter the seconds to update: ");
ch1=getche();
ch2=getch();
secs = ASCIItoBCD(ch1, ch2);
*tm = 0;
_CH = hrs;
_CL=mins;
_DH= secs;
_DL=0;
_AH =3;
geninterrupt(0x1a);
puts("Time Updated");
}
How do you avoid garbage values in c plus plus programs?
Initialization. Hint: your compiler might warn you, neverignore warnings if you aren't absolutely sure what they mean.
How do you use arrays in biginteger?
In Java, you would create an array of type BigInteger, then initialize each object (each array element) with the newoperator. I believe it would be something like this: BigInteger[] myArray = new BigInteger[5]; for (int i = 0; i
An array is nothing more than a block of contiguous memory addresses divided into one or more units of equal length. We call these units elements. As a result, all elements of an array must be allocated contiguously.
Other than padding for memory alignment purposes, an array offers the most compact storage for multiple elements of the same type. And because the elements are allocated contiguously, it is trivial to traverse the array from one element to the next using nothing more than a pointer variable of the same type as the array. Each increment or decrement of the pointer increases or decreases the address by 1 element. The array suffix operator [] does the same thing, except the index is a zero-based offset from the start of the array. The first element is index 0 because it is 0 elements from the start of the array while the nth element is found at index n-1.
When we create an array we have the choice of storing the objects themselves in the array or storing a pointer to the objects. With the latter, the objects need not be allocated contiguously, however we consume more memory because the array of pointers consumes additional memory that we wouldn't need to consume were all the objects allocated in the array itself. We also have the additional cost of dereferencing those pointers in order to access the objects being referred to. However, arrays of pointers are advantageous when the objects are larger than a pointer (in bytes) or are of polymorphic type. Copying or moving a large object in memory is more expensive than copying or moving a pointer, so if we need to sort an array of large objects, an array of pointers is generally more efficient despite the indirection. But with polymorphic types we have to use pointers because polymorphic types are not guaranteed to be the same length so we must store a pointer to the common base type if we wish to retain polymorphic behaviour.
Which data types can be thrown as exceptions in a c program?
C does not provide native support for exception handling.
There are basically three error handling strategies in C. The first is to design all functions such that the return value indicates success or failure. The second is to use an output parameter to indicate success or failure. The third is to set a global variable to indicate success or failure.
Integer values are usually used to indicate success or failure. Typically, the all-zeros bit-pattern indicates success while the all-ones bit pattern indicates failure (equating to 0 and -1, respectively, on a twos-complement system). However, any non-zero value can be used to indicate an error because all non-zero values implicitly convert to true (an error has occurred). Thus the error code can be used to indicate a specific type of error.
The problem with this is that there is often a lot of code between the point where an error is detected and the point where it can be handled. With global error codes this can be extremely problematic (particularly in multi-threaded applications) because the error code could easily change if other errors occur en-route to the error-handling code. But even for "local" return values and output parameters, this usually means storing the error code somewhere that the error-handling code can easily retrieve it. The only alternative is to deal with every error as and when it occurs, which is often impractical, but also leads to error handling code being duplicated and widely-dispersed.
In C++ we do not have these problems. If we invoke a C library function that returns or sets an error code that cannot be handled there and then, we can simply convert that code into an exception object and throw the object for a suitable handler to deal with. Once an exception is thrown by a thread, the call stack unwinds, immediately terminating functions (without returning a value) until a suitable handler is found. Unhandled exceptions that make it all the way back to the main function can be caught with a catch-all exception handler. By making consistent use of resource handles and "smart" pointer objects rather than "naked" pointers, all resources consumed between the error handling code and the point where the error was initially detected are automatically released, thus minimising the amount of manual housekeeping operations required en-route to the exception handling code. This technique is known by the unwieldy term Resource Acquisition Is Initialisation (RAII) but all this means is that named objects that utilise RAII will release their acquired resources automatically when they fall from scope.
As with exception-handling, RAII is not supported in C because objects in C have no constructors or destructors. When a "naked" pointer falls from scope, the object it was pointing at is not automatically released; it is up to the programmer to manually release the resource at the appropriate time. With multiple pointers referring to the same object (a shared resource), it can be difficult to determine which pointer actually "owns" the resource. With smart pointers we do not have this problem.
What is the difference between the put and the mput?
Both will operate same but i recommend you that if there is only single file use "PUT" and if there are multiple files then you can use "MPUT"...... if there is only single file and if we use MPUT command thgen it will bit slower than PUT command.
Can Header file be called in main function or not?
No, main.c does not require a header file. When you have a ".c" and ".h" pair, the ".h" file is to declare the existence of functions that are defined in the ".c" files so that these functions can be called in other files. since "main.c" needs the headers of the other modules (to access their data types and functions) but usually doesn't have a header file itself.
Header files aren't "called", they are "included",but usually not inside any function.
printf(\n "ENTER THE NUMBER\t");
scanf{"%d",&a);
while(a!=0);
{
r=a%2;
if(r==0)
printf("\n\n THE NUMBER IS EVEN \t");
else
printf("\n\n THE NUMBER IS ODD \t");
printf ("\n ENTER THE NUMBER \t");
scanf("%d",&a);
}
getch();
}
Probability search in data structure and algorithm?
manu_del In Probability Search , the list is ordered with most probable search element at the beginning of the list and least probable at the end.
Useful when a relatively small number of elements are the targets for most of the searches. To ensure that the probability ordering is correct over time, in each search we exchange the located element with the element immediately before it in the list.
This is a sample ProbabilitySearch program for a list of integers
INPUT:
list[] : reference of integer array
last : index of last item
target: target to be found
ref_locn: reference to the location of target
OUT:
If target is found
location of target is stored in ref_locn
found = 1 is returned
target is moved up in priority
Else
last is stored in ref_locn
found = 0 is returned
int ProbabilitySearch (int list[],int last, int target, int *ref_locn)
{
int looker = 1;
int found = 0;
int temp;
while(looker <= last && target != list[looker])
{
looker = looker + 1;
}
if(target == list[looker])
{
found = 1;
if(looker > 1)
{
temp = list[looker -1];
list[looker -1] = list[looker];
list[looker] = temp;
looker = looker -1;
}
}
else
found = 0;
*ref_locn = looker;
return found;
}
C program to find addition of two long integer numbers?
#include<stdio.h>
main()
{
long int num1, num2;
long int sum=0;
printf("Enter Value=");
scanf("%ld", &num1);
printf("Enter Value=");
scanf("%ld", &num2);
sum=num1+num2;
printf("The Result is=%ld", sum);
}
C plus plus program that display an employees name by entering an id?
Ideally you'd want to use a DBMS to store and retrieve the employee data, but we'll keep it simple and use some static data instead.
#include
#include
#include
#include
struct employee
{
std::string m_name;
unsigned m_id;
employee(std::string name, unsigned id): m_name(name), m_id(id) {}
};
std::vector
void load_data ()
{
employees.push_back (employee ("Alan", 1));
employees.push_back (employee ("Brian", 2));
employees.push_back (employee ("Charles", 3));
employees.push_back (employee ("David", 4));
employees.push_back (employee ("Eric", 5));
}
unsigned input_id (std::string prompt)
{
unsigned id = 0;
while (1)
{
std::cout< std::string input=""; getline (std::cin, input); std::stringstream ss (input); if (ss>>id) break; std::cout<<"Invalid input.\n"; } return (id); } employee* locate (unsigned id) { for (unsigned i=0; i { if (employees[i].m_id == id) return (&employees[i]); } return (NULL); } int main() { load_data (); unsigned id=0; do { if( id=input_id("Enter an employee ID (0 to exit)")) { if (employee* emp = locate( id )) std::cout< else std::cout<<"There is no employee with that ID.\n"< } } while( id ); std::cout< } Example output Enter an employee ID (0 to exit): 6 There is no employee with that ID. Enter an employee ID (0 to exit): 5 Eric Enter an employee ID (0 to exit): 2 Brian Enter an employee ID (0 to exit): 0
A list can contain any number of items, including no items (an empty list).
How many types of logical operators in c only?
There are three logical operators in C; AND (&), OR (|), and NOT (^). These are the bitwise versions. The combinatorial versions are &&, , and !.
input price
calc tip = price*0.15
print tip