How can you get how much memory is available using c program?
You don't say whether you mean physical memory or virtual memory. Regardless, there is no portable method given that memory management is system-specific. However, the system should provide some means of giving you the information you need. The following example works on Windows and Linux:
#ifdef WIN32 #include <windows.h>
unsigned long long getTotalSystemMemory()
{
MEMORYSTATUSEX status;
status.dwLength = sizeof(status);
GlobalMemoryStatusEx(&status);
return status.ullTotalPhys;
}
#else // UNIX...
#include <unistd.h>
unsigned long long getTotalSystemMemory()
{
long pages = sysconf(_SC_PHYS_PAGES);
long page_size = sysconf(_SC_PAGE_SIZE);
return pages * page_size;
}
#endif
What two steps are needed to create an array?
For example we have a class :
public class Test()
{
public void print()
{
System.out.println("Hello");
}
}
So, if you want to create array from Test type. You can try something like this :
Test[]myTestArray=new Test[2];
myTestArray[0]=new Test();
myTestArray[1]=new Test();
I hope it will help.
Draw a flowchart to find the sum of given n positive numbers in c?
What is the flowchart C program to check wether a given character is vowel or not using switch case?
Switch case can be flowcharted using a diamond for each case, with a right branch for true and a down branch for false. The false branch simply connects to the next case. The true branch connects to the statement that should be executed for that case. Where multiple cases result in the same statement, the true branches should converge upon that statement. The execution path from the statement(s) should converge with the final false branch of the switch case.
In this case, your switch case might be as as follows:
print %letter%
switch lowercase (%letter%)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
print line " is vowel"
break;
default:
print line " is not vowel"
}
Thus you will have a column of diamonds for each case with false branches linking downwards from one diamond to the next. The statement for case 'a', 'e', 'i', 'o' and 'u' is the same, so their true branches (extending to the right) will converge upon the 'print line " is vowel"' statement which must be placed to the right of the case diamonds. The default case's true branch leads to the 'print line " is not vowel"' statement. Both these statements will then converge with the false branch from the default case, marking the end of the switch case.
Note that, logically, there is no false branch from a default case, thus this link may be omitted. However, all links from all statements must still converge below the default case.
Are there different types of skateboards?
Yes there are good brands of boards such as element, baker, birdhouse, active and DVS.
Definition of Identifier in C Language?
Identifiers or symbols are the names you supply for variables,type,function and labels.Identifiers names must differ in spelling and case from any keyword.you cannot use keyword as an identifier.you can create an identifier by specifying it in the declaration of a variable,type or function.
7 Write a program to append one file at the end of another?
#include
#include
void main()
{
FILE *fp1,*fp2;
char ch,fname1[20],fname2[20];
printf("\n enter sourse file name");
gets(fname1);
printf("\n enter sourse file name");
gets(fname2);
fp1=fopen(fname1,"r");
fp2=fopen(fname2,"a");
if(fp1==NULLfp2==NULL)
{
printf("unable to open");
exit(0);
}
do
{
ch=fgetc(fp1);
fputc(ch,fp2);
}
while(ch!=EOF);
fcloseall();
}
Write an algorithm and Draw a flowchart to accept two numbers and display the sum of the numbers?
#include
using std::cout;
using std::cin;
using std::endl;
int main()
{
double firstNumber = 0;
cout << "Enter first number: ";
cin >> firstNumber;
double secondNumber =0;
cout << "Enter second number: ";
cin << secondNumber;
cout << "Sum of the two numbers is: " << (firstNumber + secondNumber) << endl;
return 0;
}
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.