What is The statements written by the programmer?
In languages that use a C-style syntax (e.g., C, C++ and Java) all code is written using expressions. Expressions may be combined to produce more complex expressions, however an expression or group of expressions only becomes a statement when terminated by a semi-colon. A group of statements enclosed by braces {} is known as a compound statement or code block.
Write a program to obtain transpose of a 4 X 4 Matrix in c using functions?
void main()
{
int arr[4][4];
int i,j,a,b,f;
printf("\nInput numbers to 4*4 matrix");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
printf("\nKey in the [%d][%d]) value",i+1,j+1);
scanf("%d",&arr[i][j]);
}
}
for(i=0;i<4;i++)
{
for(j=0,f=0;j<4;j++)
{
if(i!=j&&f==0)
continue;
a=arr[i][j];
b=arr[j][i];
arr[i][j]=b;
arr[j][i]=a;
f=1;
}
}
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
printf("%d ",arr[j][i]);
printf("\n");
}
}
Why is it easier to convert numbers from binary to hexadecimal than decimal to hexadecimal?
A binary number system has two states '0' '1' for a long word in bits it can be as follows 101010101010101010101011 intimidating RIGHT? it can be represented in groups of 3 bits in octal 10/010/101/010/101/010/101/011= 22525253 digital or in group of 4 bits as 10/1010/1010/1010/1010/1010 = 2AAAAA
111 =7 octal 1111=f F in hexadecimal numbers 1000 =8 1010 =10 or A
WRITE A Program to convert integar to hexadecimal in c language?
Use the %X modifier of printf.
Code Example:#include int main(void) { unsigned int iMyNumber = 255; printf("The number %u interpreted as hexadecimal is %X.\n", iMyNumber, iMyNumber); return 0; }How many types of parameters passing techniques are there In c language?
There are only two methods: pass by value and pass by reference. The function itself determines how arguments are passed into the function, as defined by the function signature. If the function accepts a reference, then the argument is passed by reference, otherwise it is passed by value. Pointers are always passed by value but behave like references. The only real difference is that pointer values may be NULL but references can never be NULL.
How do you make C plus plus Program Autorun?
This is not a C++ question. It is an operating system question. Different operating systems have different ways of making programs run on startup. Most of them have several different ways to accomplish this. In MS Windows, one way is to place a shortcut for the program in the "{percent}userprofile{percent}\Start Menu\Programs\Startup" shell folder.
What is a useful way of finding the value of a variable?
Reading a table, drawing a graph, drawing a diagram, and writing a equation.
What is the role of the Compiler in a C program?
Why are computer languages used for problem solving?
A programming language is a systematic notation by which we describe computational process. Computational process means steps for solving a problem.
Understanding of computer software is imperfect without a basic knowledge of programming language. Programming language allow the programmers and end users to develop the programs that are executed by a computer. In today's world several computer languages exist. Some of these are created to serve a special purpose (like controlling a robot), while others are more flexible. General purpose tools that are suitable for many types of applications.
However, every computer language must have instructions that fall into following categories like:
1. Input/Output
2. Calculations/Text Manipulation
3. Logic/Comparison
4. Storage/Retrieval
Syntax is the discipline that examines the rules of a language that dictate how the various parts of sentences go together. While morphology looks at how the smallest linguistic unit (called morphemes) are formed into complete words, syntax looks at how those words are formed into complete sentences. Syntax is not prescriptivist - which is to say, it does not attempt to tell people what the objectively correct way to form a sentence is. Rather, it is descriptivist, in that it looks at how language is actually used and tries to come up with rules that successfully describe what various language communities consider to be grammatical or non-grammatical. Syntax deals with a number of things, all of which help to facilitate being understood and understanding language. Without rules of syntax, there would be no foundation from which to try to discern meaning from a bunch of words strung together, whereas with syntax, an infinite number of sentences are possible using a fairly small finite number of rules.
to put it simply syntax is the arrangement of words in a sentence or paragraph ect...
but the exact dictionary definition is:the study of the patterns of formation of sentences and phrases from words.
Syntax is the general rule that humans have to abide by which is that the composition of a coherent sentence using grammar and structure must be cognitively structured in the mind of someone's brain before they can communicate it to a receiver through means of making a series of small mouth noises. Syntax is the arrangement of words and phrases to create a message in a language.
Write the algorithm to find the largest number of three number?
To determine the largest of any group of numbers, we must first determine the largest of any two numbers. For that we use the following simple algorithm:
If number A is greater than number B, then return number A otherwise return number B.
In C++ we can encode this algorithm using the following template function:
T& max( T& a, T& b) { return( a>b?a:b ); }
Using this one basic function we can build more complex functions to return the largest of any quantity of numbers. For instance, to return the largest of any three numbers, we would use the following:
T& max( T& a, T& b, T& c ) { return( max( max( a, b ), c )); }
To return the largest of any four numbers, we would use the following:
T& max( T& a, T& b, T& c, T& d) { return( max( max( a, b, c ), d )); }
We could continue in this fashion, but there is a much simpler approach: place all the values in a vector and return the maximum value of the vector. The following example demonstrates this with a vector containing 10 random values:
#include
#include
#include
template
T& max(T& a, T& b ) { return( a>b?a:b ); }
template
T max( std::vector
{
std::vector
int iResult = *it;
while( ++it != v.end() )
iResult = max( iResult, *it );
return( iResult );
}
int main()
{
srand(( unsigned ) time( NULL ));
std::vector
printf( "Array: " );
for( std::vector
{
*it = rand() % 100 + 1;
printf( "%d ", *it );
}
printf( "\n");
printf( "Largest: %d\n", max(v) );
return( 0 );
}
What is the C code for preemptive priority scheduling?
#include<stdio.h>
#include<conio.h>
int main()
{
char p[10][5],temp[5];
int i,j,pt[10],wt[10],totwt=0,pr[10],temp1,n;
float avgwt;
clrscr();
printf("enter no of processes:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("enter process%d name:",i+1);
scanf("%s",&p[i]);
printf("enter process time:");
scanf("%d",&pt[i]);
printf("enter priority:");
scanf("%d",&pr[i]);
}
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(pr[i]>pr[j])
{
temp1=pr[i];
pr[i]=pr[j];
pr[j]=temp1;
temp1=pt[i];
pt[i]=pt[j];
pt[j]=temp1;
strcpy(temp,p[i]);
strcpy(p[i],p[j]);
strcpy(p[j],temp);
}
}
}
wt[0]=0;
for(i=1;i<n;i++)
{
wt[i]=wt[i-1]+et[i-1];
totwt=totwt+wt[i];
}
avgwt=(float)totwt/n;
printf("p_name\t p_time\t priority\t w_time\n");
for(i=0;i<n;i++)
{
printf(" %s\t %d\t %d\t %d\n" ,p[i],pt[i],pr[i],wt[i]);
}
printf("total waiting time=%d\n avg waiting time=%f",tot,avg);
getch();
}
What is the code for the following program 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15?
#include <stdio.h>
int main (int argc, char **argv) {
printf ("1 1 2 1 1 2 1 3 1 2 1 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1\n");
}
What is void main in C programming?
The main function in C serves as the entry point of your application. A C program is not valid without a main function.
There can only be one main function in your program, but you may use a choice of prototypes:
int main (void);
int main (int argc, char* argv[]);
You use the first version when your program has no need for command line arguments (also known as command line switches). The second version passes the full command line in the argv argument as a null-terminated array of null-terminated strings. The argc argument holds the count of strings in argv and is always at least 1 since the program name is part of the command line (stored in argv[0]). Any switches passed to the program will be found in argv[1] through argv[argc-1]. The last argument, argv[argc], is always the null-terminator (a pointer to null).
The return value allows you to return an integer to the host environment. Typically you will return 0 to indicate success and -1 to indicate failure.
The void main (void); prototype is allowed in most implementations of C (but not in C++). This simply indicates no return value is expected. However, the prototype is non-standard and if your program makes use of the exit() function to terminate, your program will return whatever value you pass to the exit() function.
Your implementation of C may also allow additional prototypes, however only the first two shown above are standard across all implementations. For portability, it is best to use one of these at all times.
Write a C Program to draw concentric circles using mid-point algorithm?
#include
#include
#include
void main()
{
int gd=DETECT,gm=4,i;
initgraph(&gd,&gm,"c:\\tc\\bgi");
setcolor(3);
for(i=0;i<150;i+=5)
{
circle(300,300,i);
}
getch();
}
What is definition and declaration in C?
int x;
float x;
char x;
double x;
long x;
long long x;
short x;
unsigned int x;
unsigned float x;
unsigned double x;
signed char x;
unsigned long x;
unsigned long long x;
int *x;
float *x;
char *x;
double *x;
long *x;
long long *x;
int x[100];
typedef struct rect {
int left;
int top;
int right;
int bottom;
};
int main(int argv, char* argc[]) {
return 0;
}
That enough for you?
Well, these are definitions, declarations are like these:
extern char x;
int main (int argc, char **argv);
How to convert 2D array to single dimensional array?
You don't need to physically convert the array, you simply need to point at the first element and read the elements sequentially. The following code shows how to achieve this, as well as how to physically convert a 2D array to a separate 1D array. As can be seen, there is no practical benefit to making the conversion.
Example
#include
int main()
{
const int rows = 2;
const int cols = 3;
const int size = rows * cols;
// Create a static 2D array, intialise and print the matrix
int arr2[rows][cols];
std::cout << "2D array:\n" << std::endl;
for( int r=0; r { for( int c=0; c { arr2[r][c]= (r+1) * (c+1); std::cout << arr2[r][c] << " "; } std::cout << std::endl; } std::cout << std::endl; // Efficient conversion to 1D array: // Point to the first element then print sequential values. int* ptr = (int*) arr2; std::cout << "1D array (using pointer):\n" << std::endl; for( int i=0; i std::cout << *ptr++ << " "; std::cout << "\n" << std::endl; // Inefficient conversion to 1D array: // Copy the 2D array to a separate 1D array int arr1[size]; ptr = (int*) arr2; for( int i=0; i arr1[i]=*ptr++; // Print the copy: std::cout << "1D array (using copy):\n" << std::endl; for( int i=0; i std::cout << arr1[i] << " "; std::cout << "\n" << std::endl; return( 0 ); } Output 2D array: 1 2 3 2 4 6 1D array (using pointer): 1 2 3 2 4 6 1D array (using copy): 1 2 3 2 4 6
Why you use if and else statement in c language program?
There is no "elseif" statement in C. You can only use "else" and "if" separately. This is a good reason for switch/case/break.
Multithreaded program generates Fibonacci series using java-answer?
The formula for the Fibonacci series is
Fn = Fn-1 + Fn-2 for n ≥ 2 with F0 = 0 and F1 = 1.
In layman's terms, in the Fibonacci series each successive number is the sum of the previous two numbers, starting with 1. So we have 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 etc
To do this in Java or any computer program you will need to create a recursive program, one that picks up previous values. This is quite easy, even for a beginner, once one grasps the Fibonacci fundamentals. Here is an example in Java:
public class Fibonacci {
public static long fib(int n) {
if (n <= 1) return n;
else return fib(n-1) + fib(n-2);
}
public static void main(String[] args) {
int N = Integer.parseInt(args[0]);
for (int i = 1; i <= N; i++)
System.out.println(i + ": " + fib(i));
}
}
For n, enter the number of values required, otherwise the increasing values of the results will overflow the parameters of the data display!
This code can be adapted for any progamming language, e.g. pascal, basic etc. One can even use the principles to construct a spreadsheet that will show the Fibonacci series in successive rows in Excel, for example.
void main()
{char a[30] = "India";
//Let the string be stored in a[30];
char b[30]; //declaring another string
for(i=0;i<strlen(a);i++)
{b[strlen(a)-1 - i]=a[i];}
//Now reverse string is stored in b;
//to print it
cout<<b;
getch();
}
Where does the main function return the value in C programming language?
To fulfill the purpose I don't use return but use a different method. pass by references:
#include<stdio.h>
void myFunc(int n[]){
int i;
for(i = 0; i<10; i++)
n[i] = i;
}
int main(void){
int a[10];
int i;
myFunc(a);
for(i=0; i<10; i++){
printf("%d\n",a[i]);
}
}
How do you find greatest factor of a number which is a factorial number in c language?
#include<stdio.h> #include<conio.h> main() { int f=1,i=1,n; clrscr(); printf("\n Enter factorial value"); scanf("%d",&n); for(;i<=n;i++) { f=f*i; } printf("\n The factorial value=%d",f); getch(); }
How memory is allocated for array type variable?
For any given type, T, a definition of type T[n] will allocate an array of n elements of type T in contiguous memory, for all n>=0. The total size of the allocation will be equivalent to n * sizeof(T). Elements of type T can be accessed by index, in the range 0 to n-1. These indices allow the compiler to compute the offset from the start of the array, such that index i refers to the address i * sizeof(T).
Arrays can be either fixed-size or variable-length and can be allocated on the stack or the heap but only fixed-size arrays can be allocated statically. The following shows all the possibilities:
int a[10]; // fixed-size, static allocation, global scope
void f(int n) {
int b[10]; // fixed-size, stack allocation, local scope
int c[n]; // variable-length, stack allocation, local scope
int* d = new int[10]; //fixed-size, heap allocation
int* e = new int[n]; // variable-length, heap allocation
// ...
delete [] e;
delete [] d;
}
Note that the arrays referred to by the pointers d and e are anonymous arrays (as are all heap allocations). It is important that we maintain at least one reference to a heap allocation in order to release that memory back to the system when we no longer require it. The pointers d and e will automatically fall from scope when the function ends, but the memory they refer to remains, unless we explicitly delete that memory. Ideally, the function that allocates heap memory should also release that memory, however so long as we maintain a reference to that memory (such as through a global pointer), any function can release it. This can lead to problems such as resource leaks as ownership of the memory is unspecified; any code can take ownership of the memory at any time. This is particularly problematic in multi-threaded applications where two threads may attempt to take ownership at the same time. If one thread releases the memory while another is still accessing that memory, undefined behaviour will occur. To avoid this, pointers to heap allocations are best encapsulated within a resource handle, a class that takes ownership of the memory. In C++, std::vector provides a thread-safe resource handle to variable-length arrays.