Write a program to print binary equivalent of given integer value in c?
Inorder to display a binary value of a number in C language, 1st create an integer array of size n. Then inside a for loop divide that number by 2 repeatedly and store the remainder in that array from 0 to n. The remainder is always a 0 or 1. Finally when the number itself reaches 1, put this 1 also in your array. Then display it by printing the array from n-1 to 0.
What program do they use to make c plus plus compilers?
The first generation C++ compiler was written in C. Newer generations of C++ compilers are written using the previous generation of C++, however some implementations also use assembler, either in part or in whole.
Bear in mind that one of the first programs ever written for a computer was an assembler. Before assembler, all code had to be written in machine code, the native language of the computer, which was labour intensive and prone to error. But that was exactly how the first generation assembler had to be written. Thereafter, the assembler was used to create the next generation assembler, and the next, until high-level languages began to appear (again, written in assembler), until C finally appeared, which eventually led to C++.
Which translates c source code into object code before the program can be executed?
Question #1: Compiler.
Question #2: If you want to execute an external program in C, use function system.
A translator in computer programming is a piece of software that translates one programming language to another.
Therefore a C translator would translate either C source code into another language, let's say BASIC.
So if you had a C to BASIC translator, you would write a program in C and the translator would give you the equivalent source code in BASIC.
I have never used a translator, but at first glance, it doesn't sound very reliable for both security and memory management reasons.
In C programming a character variable can at a time store how many characters?
You can store one, however if you make a char array:
char[50];
You can make a string out of your array of characters.
Write a program to print n natural numbers using do-while loop?
//(this is just a function, call this as count(n) in your main loop)
void count(int n){
int i = 1;
do{
printf("%d", i);
i++;
} while(i<=n);
}
Write a vb program to find the simple interest?
n1=val(text1.text)
n2=val(text2.text)
n3=val(text3.text)
text4.text=(n1*n2*n3)/100
Advantage of flowchart in c language?
Pre-test loop in C#
bool condition = false; [NOTE: this line is not part of the loop it is the condition which must be met for the loop to occur. If it is not satisfied the loop does not happen.
while (condition == false)
{
Do stuff
condition = checkCondition();
}
To draw this as a flowchart you just have to show that your flowchart can repeat a step/steps indefinitely depending on a condition
Decision trees are used mainly in the business world to help strategize many business investments and planning. It would include things such as possible outcomes, costs, etc.
How to write algorithm in c program?
Algorithms are created using pseudocode, which is a combination of natural language (such as English) and commonly understood programming concepts. Pseudocode is a machine-independent language, but it is far too abstract for a machine to understand. It is intended for humans only. As programmers, our job is to translate these algorithms into a form the machine can process in order to produce the required machine-dependent code. For this we use programming languages, such as C, C++ and Java.
The more abstract the programming language, the easier it is to convert an algorithm into working code. Of all the high-level programming languages, C has the least amount of abstraction, however we can make use of third party libraries to increase the amount of abstraction, or we can use the language itself to create our own abstractions.
Write a C program for Sum of factors of a number?
#include<stdio.h>
#include<conio.h>
void factor(int num)
{
int i,sum=0;
for(i=1;i<num;i++)
{
if(num%i==0)
{
sum=sum+i;
}
}
printf("Sum of the factor of %d is %d",num,sum);
}
void main()
{ int num;
printf("Enter the number=");
scanf("%d",&num);
factor(num);
getch();
}
Why should you let inoculating loop cool first before using?
an innoculated loop shouln't be hot. it should be cooled before contact with the organism by touching it off the edge of the agar or dipped into the top of the broth. if its hot it will kill the organism!
// returns n!
int fact(final int n) {
// keep track of factorial calculation in f
// f starts at n, and we will multiply it by all integers less than n
int f = n;
// loop from n-1 down to 2
for(int i = (n - 1); i > 1; --i) {
// increase our total product
f *= i;
}
return f;
}
Program to check the presence of a substring in a given string?
#include<stdio.h>
#include<string.h>
main()
{
char a[24];
int i,count=0,j=0,stlen,k,substlen,sig=0;
gets(a);
for(i=0;i<strlen(a);i++)
{if(a[i]==' ')
break;
else j++;}
stlen=j;
substlen=strlen(a)-j-1;
for(i=0;i<=stlen-substlen;i++)
{count=0;
for(k=i+substlen-1;k>=i;k--)
{if(a[k]!=a[k+stlen-i+1])
break;
else count++;}
if(count==substlen)
{sig=1;
break;
}
}
printf("%d",sig);
}
input-
11100101 1001
110010 111
output-
1
0
note -give the main string and the substring(to be checked) seperated by a space.
C program to find the occurrence of an element in a number?
Let "n" is that number and "occ" is the no of occurrence of a element "el" in "n".
so,
<pre>
i = n;
occ = 0; // Initializing "occ" to zero.
while(i > 0){
rem = i % 10; // This gives a digit in the number.
if(rem == el) occ++; // If "rem" is same as "el" then increament "occ".
i = i / 10; //By this we are extracting rem from number i.
}
printf("No of Occurrence of %d element is : %d", el, occ); // Printing the number of occurences
</pre>
that's it.
What is linear search algorithm?
The linear search problem relates to searching an un-ordered sequence. Because the data is no ordered, we must start at one end of the sequence and inspect each element in turn tunil we find the value we are looking for. If we reach the one-past-the-end of the sequence, the value does not exist. From this we can see that for a set of n elements, the worst case (the element does not exist) is O(n) time while the best case is O(1) time (the element we seek is the first element). Given that there is a 50/50 chance the element we seek will be closer to the start of the sequence than the end, the average seek time is O(n/2).
When a set is ordered we can reduce search times by starting in the middle of the set. In this way, if the element is not found we can eliminate half of the set because we know which half contains the value (if it exists). We repeat the process until we find the value in the middle of the remaining set or the remaining set is empty. The end result is that search times are reduced to a worst case of O(log n), the binary logarithm of n.
Structures are a way of storing many different values in variables of potentially different types under the same name. This makes it a more modular program, which is easier to modify because its design makes things more compact. Structs are generally useful whenever a lot of data needs to be grouped together--for instance, they can be used to hold records from a database or to store information about contacts in an address book. In the contacts example, a struct could be used that would hold all of the information about a single contact--name, address, phone number, and so forth.
->A structure is a collection of related elements , possibly of different types , having a single name.
->"each element in a structure is called field".
->A FIELD is a smallest element of named data that has meaning. It has many characteristics of the variable .
->It exits in memory . it can be assigned values, which in turn can be accessed for selection or manipulation.
-> A field differs form variable primarily in that it is a part of structure.
ITS SYNTAX IS:
struct tag name
{
field list;
};
What is the purpose of using loop?
A loop is a section of code that is repeated over and over until some condition is met. There are different flavors:
A for loop:
for (a = 0; a < 25; a++)
{
//code
}
The //code will be executed with a=0, then a=1, etc., until a=25, when it will break out of the loop.
a = false
do
{
//code
} while (a == false)
Here, if there is nothing in //code to change the value of a to true, you will have an infinite loop.
C program to find weather given number is even or not?
Oh good old-fashioned C.
void main()
{
int variable_name = [Any number goes here];
if (variable_name % 2 == 0)
{
printf("%d is even.", variable_name);
} else
{
printf("%d is odd.", variable_name);
}
}
I think I've helped enough, so it's up to you to learn how to get input from the user, if that's what you're working on.
What are the 5 ways of writing an algorithm?
for the most part, programming is writing algorithms. An algorithm is just a sequence of instructions designed to get a desired result.
lets write an algorithm for finding the largest number in a list of numbers:
You have a list called numberList and it has a bunch of random numbers stored in it. The only way you can find the largest number is if you go through every element in numberList. Since we don't know anything about any of the numbers in numberList (they could all be the same) lets just call the first element in the list our currentLargest. As we traverse through numberList, if we come across a number larger than our currentLargest then we assign the new number as our currentLargest. Once we have looked at every element in the numberList, our currentLargest should be the largest number in numberList.
The code for the above program would look something like this [Pseudocode]:
numberList = {1, 39, 8, 109, ...}
currentLarget = numberList0
FOR every element in numberList
. . . IF element > currentLargest
. . . . . . currentLargest = element
PRINT currentLargest
What is difference between structural language and object oriented language?
I think there is no any difference between object oriented programming language. Because somebody have written that vb is object based language because there is no inheritance, but javascript has no classes and no inheritance but javascript is also object oriented scripting language and java is also object oriented language vb has no inheritance but classes is.So vb is object based language This is not clear that difference between object oriented and object based. if i am wrong than what should be your answer and if i am wright than no problem But first i am requesting to the developer of any programming language that please define the difference between object oriented and object based languages. Amit Sinha Dist-Gaya State-Bihar
Write a program in c language to subtract two numbers?
#include<stdio.h>
#include<conio.h>
int main(void)
{
int sum=0,n,i;
clrscr();
printf("\n Enter two no.");
scanf("%d%d",&n,&i);
sum=n+i;
printf("\n%d+%d=%d,n,i,sum);
getch();
return 0;
}
How do you get C programming to reduce a fraction?
#include "stdio.h"
int gcd(int a, int b);
void reduce(int* numerator, int* denominator);
int main(int argc, char* argv[]) {
int a, b;
fscanf(stdin, "%d/%d", &a, &b);
reduce(&a, &b);
fprintf(stdout, "%d/%d", a, b);
return 0;
}
int gcd(int a, int b) {
int c;
while (b) {
c = a % b;
a = b;
b = c;
}
return a;
}
void reduce(int* numerator, int* denominator) {
int g = gcd(*numerator, *denominator);
*numerator /= g;
*denominator /= g;
}
You get the greatest common divisor between the numerator and denominator and divide them by it.
Reduce uses integer pointers so that changes the numerator and denominator to their reduce form.
Characteristics of nonlinear data structure?
A database is a collection of data organized in a fashion that facilitates updating, retrieving, and managing the data. The data can consist of anything, including, but not limited to names, addresses, pictures, and numbers. Databases are commonplace and are used everyday. For example, an airline reservation system might maintain a database of available flights, customers, and tickets issued. A teacher might maintain a database of student names and grades. Because computers excel at quickly and accurately manipulating, storing, and retrieving data, databases are often maintained electronically using a database management system. Database management systems are essential components of many everyday business operations. Database products like Microsoft SQL Server, Sybase Adaptive Server, IBM DB2, and Oracle serve as a foundation for accounting systems, inventory systems, medical recordkeeping sytems, airline reservation systems, and countless other important aspects of modern businesses. It is not uncommon for a database to contain millions of records requiring many gigabytes of storage. For examples, TELSTRA, an Australian telecommunications company, maintains a customer billing database with 51 billion rows (yes, billion) and 4.2 terabytes of data. In order for a database to be useful and usable, it must support the desired operations, such as retrieval and storage, quickly. Because databases cannot typically be maintained entirely in memory, b-trees are often used to index the data and to provide fast access. For example, searching an unindexed and unsorted database containing n key values will have a worst case running time of O(n); if the same data is indexed with a b-tree, the same search operation will run in O(log n). To perform a search for a single key on a set of one million keys (1,000,000), a linear search will require at most 1,000,000 comparisons. If the same data is indexed with a b-tree of minimum degree 10, 114 comparisons will be required in the worst case. Clearly, indexing large amounts of data can significantly improve search performance. Although other balanced tree structures can be used, a b-tree also optimizes costly disk accesses that are of concern when dealing with large data sets. Databases typically run in multiuser environments where many users can concurrently perform operations on the database. Unfortunately, this common scenario introduces complications. For example, imagine a database storing bank account balances. Now assume that someone attempts to withdraw $40 from an account containing $60. First, the current balance is checked to ensure sufficent funds. After funds are disbursed, the balance of the account is reduced. This approach works flawlessly until concurrent transactions are considered. Suppose that another person simultaneously attempts to withdraw $30 from the same account. At the same time the account balance is checked by the first person, the account balance is also retrieved for the second person. Since neither person is requesting more funds than are currently available, both requests are satisfied for a total of $70. After the first person's transaction, $20 should remain ($60 - $40), so the new balance is recorded as $20. Next, the account balance after the second person's transaction, $30 ($60 - $30), is recorded overwriting the $20 balance. Unfortunately, $70 have been disbursed, but the account balance has only been decreased by $30. Clearly, this behavior is undesirable, and special precautions must be taken. A b-tree suffers from similar problems in a multiuser environment. If two or more processes are manipulating the same tree, it is possible for the tree to become corrupt and result in data loss or errors. The simplest solution is to serialize access to the data structure. In other words, if another process is using the tree, all other processes must wait. Although this is feasible in many cases, it can place an unecessary and costly limit on performance because many operations actually can be performed concurrently without risk. Locking, introduced by Gray and refined by many others, provides a mechanism for controlling concurrent operations on data structures in order to prevent undesirable side effects and to ensure consistency. For a detailed discussion of this and other concurrency control mechanisms, please refer to the references below. reference http://www.bluerwhite.org/btree/
What are the differences between Break Continue and Exit?
break - The break statement is used to jump out of loop. After the break statement control passes to the immediate statement after the loop.
continue - Using continue we can go to the next iteration in loop.
exit - it is used to exit the execution of program.
note: break and continue are statements, exit is function.
Write a programme to find simple interest?
int main()
{
int p,n,count;
float r,si;
count=1;
while(count<=3)
{
printf("\n enter values of p,n,andr");
scanf("%d %d %f",&p, &n, &r);
si=(float)p * (float)n * r / 100;
printf("simple interest =rs. %f",si);
count=count+1;
}
return(0);
}
Nishant:this will give S.I...
-----------------------------------------------------------------------------------------------------
//mycfiles.wordpress.com
//Program for Calculate Simple Interest
#include<stdio.h>
#include<conio.h>
void main()
{
float p,r,n,si;
clrscr();
printf("\nEnter the profit, rate & no of yr\n\n ");
scanf("f%f",&p,&r,&n);
si=(p*r*n)/100;
printf("\nSimple Intrest=%f",si);
getch();
}