Algorithm for adjacency matrix representation?
To Find the number in that matrix and check that number adjacency elements...
import java.util.Scanner;
public class FindAdjacencyMatrix {
public static int[][] array1 = new int[30][30];
public static int i,j,num,m,n;
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
//-------------------------------------------------------------------------------------------------
System.out.println("Enter the m ,n matrix");
m = input.nextInt();
n = input.nextInt();
//-------------------------------------------------------------------------------------------------
System.out.println("Enter the matrix Element one by one:");
for(i = 0; i < m; i++) {
for(j = 0; j < n; j++) {
array1[i][j] = input.nextInt();
}
}
System.out.println("The Given Matrix is :");
for(i = 0; i < m; i++) {
for(j = 0; j < n; j++) {
System.out.print(" "+array1[i][j]);
}
System.out.print("\n");
}
//-------------------------------------------------------------------------------------------------
System.out.println("Find The Adjacency Elements for Given Number : ");
System.out.println("Enter The Number : ");
num = input.nextInt();
for(i = 0; i < m; i++) {
for(j = 0; j < n; j++) {
if(num == array1[i][j]) {
System.out.println("Element is Found :"+num);
findAdjacency(num,i,j);
break;
}
}
}
//--------------------------------------------------------------------------------------
}
private static void findAdjacency(int elem,int row,int col) {
try {
if( array1[row][col-1]!=-1) {
System.out.println("Left Adjacency : "+array1[row][col-1]);
}
} catch(Exception e){
System.out.println(" Exception Throwing ");
}
try{
if(array1[row][col+1]!= -1) {
System.out.println("Right Adjacency : "+array1[row][col+1]);
}
}catch(Exception e){
System.out.println(" Exception Throwing ");
}
try {
if(array1[row-1][col]!= -1) {
System.out.println("Top Adjacency : "+array1[row-1][col]);
}
} catch(Exception e){
System.out.println(" Exception Throwing ");
}
try {
if(array1[row+1][col]!= -1) {
System.out.println("Botto Adjacency : "+array1[row+1][col]);
}
} catch(Exception e){
System.out.println(" Exception Throwing ");
}
}
//----------------------------------------------------------------------------------------------
}
Write a program to print prime number using loop?
#include<stdio.h>
int main()
{
int i=1,j,count,n;
printf("enter number range\n");
scanf("%d", &n);
printf("following numbers are prime numbers:\t");
while(i<=n)
{
j=1;
count=0;
while(j<=n)
{
if(i%j==0)
{
count++;
}
j++;
}
if(count==2)
{
printf("%d\t", i);
}
i++;
}
return 0;
}
Platform dependent, possibly LIBC.LIB or something like that.
What is big-o notation for describing time complexity of algorithm?
Big O notation allows to specify the complexity of an algorithm in a simple formula, by dismissing lower-order variables and constant factors.
For example, one might say that a sorting algorithm has O(n * lg(n)) complexity, where n is the number of items to sort.
Big O notation is used in Computer Science to describe the performance or complexity of an algorithm. Big O specifically describes the worst-case scenario, and can be used to describe the execution time required or the space used (e.g. in memory or on disk) by an algorithm.
What type of program is skyscape?
Skyscape is the medical app for iphones and ipads that many nurses and doctors use to help them study.Many medical professionals use this app to help diagnos paitents.
Where can you find file conout.h for c plus?
If it's a part of the standard package it has to be in visual C/Borland folder. Use search to find out exact location. In newer package standard libraries are archived, and it might tricky to find. The best way is to check the software (Microsoft, Borland, and so) producer website.
What are all the different methods of accessing array elements?
#include<iostream>
#include<cassert>
int main()
{
char str[] = "The quick brown fox jumped over the lazy dog.";
// Access the 5th element ('q' @ index 4) in 6 different ways:
char a = *(str+4);
char b = *(4+str);
char c = str[4];
char d = 4[str];
char e = *(&str[2]+2);
char f = *(2+&str[2]);
// Point to 7th element and access the 5th element:
char* p = &str[6];
char g = *(p-2);
// Test for equality:
assert(a==b);
assert(b==c);
assert(c==d);
assert(d==e);
assert(e==f);
assert(f==g);
assert(g=='q');
}
Explanation:
There is really just one version, a, but just as x+y == y+x, it is commutative thus we get version b as well. Note that the array name alone always returns a reference to the start of the array. Once we factor out all the pointer arithmetic, we are essentially just returning the dereferenced value of an address within the array.
Version c is the conventional notation using the subscript operator. However the subscript operator is merely sugar-coating (a notational convenience). Behind the scenes, we're actually executing a.
Version d is an unusual form that is rarely seen but is perfectly valid. Just as str[4] is functionally equivalent to *(str+4), so 4[str] is functionally equivalent to *(4+str), thus d is the same as b (which is the same as a).
Versions e and f are similar to a and b respectively, but instead of taking the address of the start of the array, we now take the address of the 3rd element (index 2) and then offset by 2 elements to get to the 5th element. In these versions, we can also use a negative offset to move backwards from an element, so long as we remain within the bounds of the array. These versions can also be notated more conventionally using version c; str[2+2] which is the same as a.
Version g is similar to e except we now store the address of the 7th element (index 6) in p and then use pointer arithmetic to obtain the offset of the 5th element. However, this version is not commutative so we cannot use *(2-p), but is functionally the same as a.
There are other variants similar to these 7 but they all ultimately come back to version a once you factor out all the pointer arithmetic. In other words, no method is better or worse than any other method. However version c is favoured for its readability alone, regardless of whether the offset is a compile-time constant or needs to be calculated at runtime. All others are academic but give a better understanding of what's really going on behind the scenes.
malloc/calloc/realloc will return NULL
No. A function takes in values of no, one, or more input variables, and returns no or one result. It cannot return more than one result. Do not confuse this with returning multiple results using call by reference parameters - this is not the same thing.
How do you write a C program to find row sum and column sum of a given matrix?
#include #include
This program takes in the number of rows (n) and columns (m) as well as the elements as a screen input in a matrix n x m.
It then calculates the sum of each row and each column and outputs it using the 'cout' command.
Also, if it is a square matrix, it calculates the sum of diagonal elements and prints it out.
Click here for SAMPLE INPUT 3 3 9 8 7 6 5 4 3 2 1
Click here for SAMPLE OUTPUT Matrix A, Row Sum(Last Column) and Column Sum(Last Row) : 9 8 7 24 6 5 4 15 3 2 1 6 18 15 12 Sum of diagonal elements is : 15
How do you tell your program you are using a VARIABLE?
You have to declare it. The simplest way to do so is by using the Dim keyword.
For example if you want a string variable called someString you would declare it thus:
Dim someString as string
What is asm in sorting algorithms?
'ASM' is sort for Assembly, it has nothing to do with sorting algorithms.
It is exactly what it says it is: a pointer to a base class. The assumption is that you have an object to a derived class, but actually hold a pointer to its base class. The following minimal example demonstrates this:
class base{ public: virtual ~base(){} };
class derived: public base{};
int main()
{
base* p = new derived; // base class pointer to a derived instance.
delete( p );
return(0);
}
Note that derived has an "is-a" relationship with base (derived is a base), thus the above code is perfectly legal. Moreover, because the base class destructor is declared virtual, when you delete p you automatically destroy the instance of derived before the instance of base, thus ensuring a clean teardown (without a virtual destructor, a dangling reference to derived would be left behind, which will only lead to problems further down the line).
Taking things further, calling any virtual methods upon the base class automatically invokes the override in your derived class, thus ensuring that your derived class behaves accordingly, polymorphically, even though you only hold a pointer to the base class. In other words, the base class provides a generic interface that is common to all its derivatives, and you can call those generic methods via the base class pointer without ever needing to know the actual derived type.
Remember that base classes should never know anything about their derivatives since a new derivative could be created at any time in the future and would therefore be impossible to predict in advance. But so long as the derivative makes use of the virtual functions (the generic interface) provided by the base class, there is never any need to know the actual type. The derivative's own v-table takes care of that for you, thus completely eliminating the need for expensive runtime type information and dynamic downcasts (which is always a sign of poor class design). This then makes it possible for your derived class overrides to call non-generic methods, thus extorting non-generic behaviour from what is essentially a generic, base class pointer.
How do you copy output of turbo c in Microsoft Word?
You cannot directly copy from Turbo editor and paste it in Word. But instead you can save your source file from Turbo. Then open that file in Notepad. From Notepad you can copy or paste to MS Word.
An ultrasound scanner is a scanning machine to do with sound. As the ultrasound scanner moves back and forth over your body, it sends sound waves through your skin and muscle. The sound waves are then turned into images that appear on TV screens, and can also be copied onto paper or X-ray film.
How do you draw a circle in c program?
Here, maybe a few other shapes as well
#include
#include
void main()
{
int gd=DETECT, gm;
int poly[12]={350,450, 350,410, 430,400, 350,350, 300,430, 350,450 };
initgraph(&gd, &gm, "");
circle(100,100,50);
outtextxy(75,170, "Circle");
rectangle(200,50,350,150);
outtextxy(240, 170, "Rectangle");
ellipse(500, 100,0,360, 100,50);
outtextxy(480, 170, "Ellipse");
line(100,250,540,250);
outtextxy(300,260,"Line");
sector(150, 400, 30, 300, 100,50);
outtextxy(120, 460, "Sector");
drawpoly(6, poly);
outtextxy(340, 460, "Polygon");
getch();
closegraph();
}
C program to remove all comments from a c program?
/ sub.c Copyright 2009 vishnuprathish This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. / #include int main(int argc, char** argv) { FILE *fp; fp=fopen("sub.c","r"); char ch; ch=getc(fp); while(ch!=EOF) { if(ch=='/') { ch=getc(fp); if(ch=='/') { while((ch=getc(fp))!='\n') { getc(fp);//This commment wil be removed } } if(ch=='*')/*This also wil be removed*/ { while(1) { ch=getc(fp); if(ch=='*') { ch=getc(fp); if(ch='/') { break; } } } } } printf("%c",ch); ch=getc(fp); } return 0; }
Why you have to declare variable first in turbo c?
All variables (and constants) must be declared before they can be used. This is so the compiler knows exactly how much memory to allocate to the variable, as the declaration tells the compiler exactly what the variable's type is.
What is the difference between null pointer ASCII null character and null string?
A null pointer is a pointer which does not point to any valid memory location, and usually contains the binary value "0" to represent this (this is language dependent). The ASCII null character is a character-sized zero value (in ASCII, it is an unsigned byte with a value of 0), and typically represents the end of a string (esp. as in C and C++). A null string is one that is zero characters of usable string data; in a length-based string, this means the length parameter is set to 0, and in an ASCII null-terminated string, means the first character is set to 0.