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.
How do you convert decimal number 93 to binary?
To convert any number in any base to another base, simply iteratively divide by the second base, using the rules of arithmetic for the first base, recording the remainders in reverse order, until the quotient is zero. For example, answering the question of how to convert 9310 to 10111012...
93 divided by 2 is 46 remainder 1
46 divided by 2 is 23 remainder 0
23 divided by 2 is 11 remainder 1
11 divided by 2 is 5 remainder 1
5 divided by 2 is 2 remainder 1
2 divided by 2 is 1 remainder 0
1 divided by 2 is 0 remainder 1
The answer, reading the remainders from bottom to top, is 10111012.
This was not a good example, because the answer is palindromic, and can be read the same way forwards and backwards. Here is another example, converting 3710 into 1001012.
37 divided by 2 is 18 remainder 1
18 divided by 2 is 9 remainder 0
9 divided by 2 is 4 remainder 1
4 divided by 2 is 2 remainder 0
2 divided by 2 is 1 remainder 0
1 divided by 2 is 0 remainder 1
The answer is 1001012.
Why is Java not a pure OOP Language?
Java is a OOP language and it is not a pure Object Based Programming Language.
Many languages are Object Oriented. There are seven qualities to be satisfied for a programming language to be pure Object Oriented. They are:
Java is not because it supports Primitive datatype such as int, byte, long... etc, to be used, which are not objects.
Contrast with a pure OOP language like Smalltalk, where there are no primitive types, and boolean, int and methods are all objects.
Which data structure is needed to convert infix notations to pre fix notations?
S: Stack
while(more tokens)
{
x<-next token;
if(x is an operand)
print x
else
{
while(precedence(x) <= precedence(top(s))
print(pop(s))
push(s,x)
}
}
while(!empty(s))
print(pop(s));
Written by: Fabianski Benjamin
Which is the best object oriented programming language for beginners?
I would go with Python.
Python is therefore an ideal backend language due to its simplicity and consistency, where the developers are able to write reliable systems with a vast set of libraries belonging to Machine Learning, Keras, TensorFlow and Scikit-learn
How do you write a c program to generate first n natural numbers using a for loop?
#include<stdio.h>
main(void)
{
int n;
int i;
printf("Type n: ");
scanf("%d",&n);
for(i=1;i<=n;i++) //generates natural numbers from 1,....,n.
printf("%d\n",i); //prints these numbers to standard output
}
Comparison between array and dynamic implementation of linked list?
I assume you are referring to implementation of Abstract Data Types like Stacks and Queues.
Arrays have capacity limits which you set upon declaring them. If you have date which has a definite size, then using arrays is okay.
But if you have data which size changes at runtime, then just use linked lists because linked lists could constantly add nodes whenever needed.
arrays need continuous memory allocation for their creation but in linked list the memory allocation need not be continuous....
What is a enumerated data type?
An enumeration is a group of (closely) related constants of integral type (int, char, short, long or long long).
Members of an enumeration are automatically initialised with values in the order they are declared, starting with the value 0 for the first member and incrementing by 1 for each additional member:
enum traffic_light {green, amber, red}; // e.g., green=0, amber=1, red=2
If the start value 0 is undesirable, we can assign a different start value:
enum traffic_light {green=1, amber, red}; // e.g., green=1, amber=2, red=3
A new start value can be placed anywhere in an enum:
enum traffic_light {green, amber=4, red}; // e.g., green=0, amber=4, red=5
Two or more members can share the same value:
enum traffic_light {green, amber, orange=1, red}; // e.g., green=0, amber=1, orange=1, red=2
The value of a previously declared member can be used to initialise another member:
enum traffic_light {green, amber=green+1, red=green+2}; // e.g., green=0, amber=1, red=2
The names of an enumeration are within the scope of the declaration. This is often undesirable as two enumerations in the same scope cannot share the same member names:
enum traffic_light {green, amber, red};
enum rainbow {red, orange, yellow, green, blue, indigo, violet}; // error!
To avoid this, we can use an enum class. The enumeration then becomes a namespace:
enum class traffic_light {green, amber, red};
enum class rainbow {red, orange, yellow, green, blue, indigo, violet}; // ok
To refer to a member of an enum class, we use namespace resolution:
traffic_light x = red; // error! no red in scope
rainbow y = rainbow::green; // ok
What are the advantages and disadvantages of commercialization?
Commercial advertising is the process of publicising a product or service of trying to sell a product or service by drawing people's attention of the particular product.Through commercial advertising customers can easily get the information about the new product and the methods of using them.It educates them and provides a great knowledge about different products including their advantages also.They are very useful to people.Advertisements are used to build brands for the protects creates awareness among consumers before launching and introducing a new product.It develops an encouragement in the economy.
Can a continue statement be used in a switch statement?
If you have a loop in your switch statement or around your switch statement, you can use the continue statement in that. You cannot use a continue statement outside of a loop (do, for, or while).
Four basic instruction in C language?
They are 'statements' to speak strictly, they are:
Note:
Which language is predecessor to C programming language?
hi everyone..
predecessor to C is B..
don think it's a joke..
in UNIX OS , the assembly code was machine dependent..
so,the version could not be portable..
so Ken Thompson rewrite the whole UNIX code in the new language called B..
But B missed several necessary aspects for real life programming..
so, Ritchie invented the new language called C which solved the inadequacies of B..
that's all...
be happy.. be cool..
Assembly language program to convert 8 bit binary to ascii code?
BinarySearch proc ;params: array (of integers), length, target
push ebp
mov ebp, esp
mov ebx, [ebp + 8]
mov ecx, [ebp + 12]
xor edx, edx
dec ecx
jmp LoopCond
LoopStart:
mov eax, edx
add eax, ecx
shr eax, 1
push ecx
mov ecx, [ebp + 16]
cmp [eax * 4 + ebx], ecx
pop ecx
je Exit
jl UpperHalf
mov ecx, eax
dec ecx
jmp LoopCond
UpperHalf:
mov edx, eax
inc edx
LoopCond:
cmp ecx, edx
jge LoopStart
mov eax, -1
Exit:
pop ebp
ret
BinarySearch endp
Where can a blue laser pointer be bought?
Lots of lasers are available both online and in local shop.
It would be fine to get a laser pointer from a laser shop. I am interested in laser pointer, and I have got a high power 1500mW LEVIN series blue laser pointer from LaserTo. It is pretty cool and powerful.
It is quite important to get a high performance laser pointer with reliable quality, stable operation and long lifetime. For the most important of all, quality and service are both important.
Is Basic a low level language or high level?
Dual system 1 and 0
It can also depend what you mean by computer, and how deep you want to go. You can make a "Computer" with wood and strings, as proven by the Jaquard Loom. Hardware is key, no matter how basic. So, in theory (i guess) the Basic Language would be how the computer...works! If you want to go to the very basics.
Write a program in c language to print some message on the screen with out using printf?
you can put the printf function inside a if() so that you need not use semicolons. for eg to print my name, if(printf("My Name is Maheedharan")) {} this will work. try this out...