C code to sort array of integers in descending order?
#include
#include
#include
#include
void main()
{
clrscr();
int n,i,term,j;
int x[100];
printf("/nEnter no. of terms (N) " );
scanf("%d",&n);
for(i=0;i
{
printf("n/Enter %d element",i+1);
scanf("%d", &x[i]);
}
printf("/given arrary is");
for(i=0;i
printf("/n %d",x[i]);
for(i=0;i
for(j=i+1;j
if(x[i]
{
term = x[i];
x[i] = x[j];
x[j] = term;
}
printf("/nSorted array is given below");
for(i=0;i
printf("/n%d",x[i]);
getch();
}
A pointer is a programming tool that allows a value to be referenced. All data is allocated in memory and has a certain address attached to them. When you use a pointer, you are taking a value from an address called the reference. The original data is called the reference, and taking that value using a pointer is called dereferencing.
Example using Objective-C:
int anInt = 42; (anInt is stored in memory with the value of 42)
int *anIntPointer; (this is new datatype that wants to point to a certain address)
*anIntPointer = &anInt; (you are taking the pointer and dereferencing it to anInt. anytime you have a pointer [in this case denoted with an asterisk "*"], the reference will be noted with an ampersand "&")
Now there are also pointers to objects and structs that use an entirely different method, but same idea, the pointer grabs a referenced data value. This is especially valuable for referencing structures without having to reference every single member variable.
What are the benefits of using functions?
A static function in class scope (within a class) can access only static class members (for all instances of the class). A static function in file scope (not within a class) is visible only to code within that compilation unit, i.e. it cannot be linked from file to file.
What are the function of an interpreter and a compiler?
An interpreter is a computer program that translates a high-level computer program into machine code while it is executing. As a result of this runtime interpretation, an interpreted program executes more slowly and consumes more resources than an equivalent standalone machine code executable would. To create standalone machine executables from high-level language sources you require a compiler and linker. Alternatively, you can write the program in low-level assembly language and use an assembler to create the executable, however high-level languages are easier to work with and can more easily produce executable code that is as efficient if not more efficient than is possible with low-level assembly language.
Which one is better between structure and union?
Sub:- C programming class:- f.y.b.sc(cs) name:-sintu mehta Union:- all member of the union share is storage in the computer memory 2. Only one member can be active at a time 3. Only first union variable can be initialized 4. Conservation the memoy
How can you create a headerfile in a c?
Create the header file as a .h file in the same way you create a source file, .c and place it in the same directory as the .c files. To incorporate it, use the...
#include "my_header_file.h"
... directive. Note that there are double quotes instead of greater/less signs. This tells the compiler to look first in the source directory.
Why do you use of operator overloading in c?
Overloading, Overriding, Polymorphism, Information Hiding, Inheritance all these are CONCEPTS of C++ and Java. An Object Oriented Language and not of C language. Thats why Bjarne Stroustrup came up with C++ ...
int sumEvens = 0;
int sumOdds = 0;
int i;
for(i = 0; i <= n; ++i) {
}else {
sumOdds += i;
}
}
(This assumes all values are integer)
int num_odds = ((n - 1) >> 1) + 1; /* number of odd numbers from 1 to n */
int num_evens = n >> 1; /* number of even numbers from 1 to n */
int sum_odds = num_odds * num_odds;
int sum_evens = (num_evens * num_evens) + num_evens;
summing 10 numbers with variables
#include
main()
{
int a,b,c,d,e,f,g,h,i,j,add;
printf("Enter 10 numbers to sum:\t");
scanf("%d %d %d %d %d %d %d %d %d %d",&a,&b,&c,&d,&e,&f,&g,&h,&i,&j);
add = a+b+c+d+e+f+g+h+i+j;
printf("%dResult:\t",add);
}
Is the use of a header files absolutely necessary?
No. But in large programs it helps to split the code into logically organised modules (translation units). In order to ensure declarations remain consistent across all translation units, headers must be used.
Code of Round-robin scheduling in c?
#include<stdio.h>
#include<conio.h>
main()
{
int st[10],bt[10],wt[10],tat[10],n,tq;
int i,count=0,swt=0,stat=0,temp,sq=0;
float awt=0.0,atat=0.0;
clrscr();
printf("Enter number of processes:");
scanf("%d",&n);
printf("Enter burst time for sequences:");
for(i=0;i<n;i++)
{
scanf("%d",&bt[i]);
st[i]=bt[i];
}
printf("Enter time quantum:");
scanf("%d",&tq);
while(1)
{
for(i=0,count=0;i<n;i++)
{
temp=tq;
if(st[i]==0)
{
count++;
continue;
}
if(st[i]>tq)
st[i]=st[i]-tq;
else
if(st[i]>=0)
{
temp=st[i];
st[i]=0;
}
sq=sq+temp;
tat[i]=sq;
}
if(n==count)
break;
}
for(i=0;i<n;i++)
{
wt[i]=tat[i]-bt[i];
swt=swt+wt[i];
stat=stat+tat[i];
}
awt=(float)swt/n;
atat=(float)stat/n;
printf("Process_no Burst time Wait time Turn around time
");
for(i=0;i<n;i++)
printf("%d %d %d %d
",i+1,bt[i],wt[i],tat[i]);
printf("Avg wait time is %f
Avg turn around time is %f",awt,atat);
getch();
}
Can borland compiler perform the graphics in c?
No. But programs compiled with Borland compilers might be able, platform-dependent.
How do write a program to output prime numbers between 1-1000 using c?
main()
{
int i,n,p,v;
printf("enter the number of terms");
scanf("%d",&n);
for(i=2;i<=n;i++)
{
for(j=1;j<i;j++)
{
if(i%j==0)
v=v+1;
else
p=p+1;
}
}
printf("%d is a prime",i);
}
check this out
Write a C program to find volume of sphere?
double Pi = 3.1415...;//Pi number
double sphereRadius = 0;
double surfaceAreaOfSphere = 0;
...
cout << "Enter a radius of the sphere";
cin >> sphereRadius;
...
surfaceAreaOfSphere = 4*Pi*sphereRadius*sphereRadius;
//or using math.h
surfaceAreaOfSphere = 4*Pi*pow(sphereRadius, 2);
...
cout << "The surface area is: " << surfaceAreaOfSphere;
...
Is it possible to immediately run a program without compiling it?
Not in C++, unless you have an interpreter. Most C++ development systems, however, are based on the compiler idiom, so, the answer is no.
However, Java is very close to C++, except for the platform and libraries, so one might consider Java to be an interpreter, however, you still must "compile" Java to byte code, so the answer is still no.
Relation between array and pointer?
A pointer identifies the location of some data in memory, similarly to an envelope with a street address on it. An array is several values of the same type, stored next to each other in memory. A useful consequence is that all of an array's elements may be found by simply counting up from the address of the first element.
Note that, when an array value is made available outside of its original scope, it decays to a pointer to its first element. So, for example, sizeof returns a different size for an array depending on which scope you call it in. In the array's original scope, it returns the number of elements in the array; in any other scope it returns the number of bytes used to store the pointer.
Write a c program that interchanges the odd and even elements of an array?
#include<stdio.h>
int main()
{
int num[]={1,2,3,4,5,6};
int i,temp;
for(i=0;i<=5;i=i+2)
{
temp=num[i];
num[i]=num[i+1];
num[i+1]=temp;
}
for(i=0;i<=5;i=i+2)
printf(''%d",num[i]);
return 0;
}
Can break statement be used without any loop?
The Break statement should generally get executed in some loop or switch statement.
The below code will give compiler error.
void main()
{
printf("12");
break;
printf("14");
}
What is built-in function in c?
There are no built-in functions in C++. The definition of a built-in function is a function that does not need to be declared before it is used, but every function in C++ is user-defined and must be declared before it can be used. This includes functions provided by the C++ standard library which we declare by including the appropriate headers.
Some articles mistakenly describe keywords such as while, switch and if as being built-in functions, however these are statements, not functions.
C++ does provide several built-in operators, some of which look and behave very much like functions. For example, the built-in sizeof() operator can be used without any declaration and looks very much like a function, but its argument is not a value, it is a type name, and we cannot (easily) define a function that accepts a type name as an argument.
The built-in typeid() operator also takes a type name argument, but it is often mistakenly regarded as being a user-defined function because we must include the C++ standard library
Unlike sizeof() and typeid(), the default global new and delete operators can be overridden with user-defined function operators, thus these are also mistakenly regarded as being built-in functions. However, only the overrides are functions because that's the only way to define an operator overload; the default global operators are built-in operators, not built-in functions.
The semantic difference between a built-in operator and a built-in function may seem insignificant, however a real built-in function would be no different to a user-defined function other than the fact that it need not be declared before using it. But a user-defined function also has identity (a memory address) and we can pass that identity to other functions using a function pointer argument. But we cannot pass a built-in operator to a user-defined function because it has no identity, thus it cannot be regarded as being a built-in function.
Write a c program to find vowels in a character array?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
main (int argc,char **argv)
{
char *a,*b,c;
int t,e;
if (argc<2) return(0);
a=argv[1];
b=a;
e=strlen(b);
for (t=0;t<=e;t++)
{
c = *b;
if (c>='A'&&c<='Z') c -= 'A'-'a';
if (c=='a'c=='e'c=='i'c=='o'c=='u') b++;
else *a++ = *b++;
}
printf ("%s\n",argv[1]);
return(0);
}
What is the algorithm n flowchart for calculating factorial of number using recursion?
A flowchart for factorial of number can be made using different software's. Microsoft Word is the most popular software for beginners to make simple flowcharts.
In order to draw the flowchart write the number at the top of the paper and then draw two lines under it going slightly to the sides. Decide what two numbers can be multiplied to equal that number. Keep going until you can no longer get to smaller numbers.
Print prime numbers between 1 to 100?
#include <stdio.h>
int main (int argc, char **argv) {
int i, j, prime;
for (i=51; i<=99; i+=2) {
prime=1;
for (j=3; j<=i-2; j+=2) {
if (i%j == 0) {
prime=0;
break;
}
}
if (prime) printf ("%d ", i);
}
printf ("\n");
return 0;
}
The standard library provides a complex number type that encapsulates both the real and imaginary parts of a complex number. All arithmetic operators are overloaded to cater for the complex type:
#include<iostream>
#include<complex>
int main()
{
std::complex<double> c {3.14, 4.2}, d {2.1, -1.2};
std::cout << c + d << std::endl;
}
All object-oriented programming languages must have the 3 following features?
Abstraction, encapsulation and polymorphismare the three fundamental features of an object oriented programming language.
Example program arrays in turbo c plus plus?
Yes, you can use for-loop in a C program compiled by Turbo C.
Programme to swap two arrays in C programming?
#include <iostream>
int main()
{
// Declare and initialise an array with two elements.
int A[2]={1,2};
// Output the array values:
std::cout<<"Before swap:\t"<<"A[0]="<<A[0]<<", A[1]="<<A[1]<<std::endl;
// Swap the array values.
A[0]^=A[1]^=A[0]^=A[1];
// Output the array values:
std::cout<<"After swap:\t"<<"A[0]="<<A[0]<<", A[1]="<<A[1]<<std::endl;
return(0);
}
Output:
Before swap: A[0]=1, A[1]=2
After swap: A[0]=2, A[1]=1