answersLogoWhite

0

📱

C Programming

Questions related to the C Computer Programming Language. This ranges all the way from K&R to the most recent ANSI incarnations. C has become one of the most popular languages today, and has been used to write all sorts of things for nearly all of the modern operating systems and applications. It it a good compromise between speed, power, and complexity.

9,649 Questions

What is the difference between base class and derived class in c plus plus?

There is no difference other than that a derived class inherits from a base class. That is, the derived class inherits all the public and protected members of its base class, and is a more specialised form of its base class. Thus both can be treated as if they really were base classes. The derived class can also override the virtual methods of the base class, thus allowing polymorphic behaviour without the need to know the exact type of the derived class.

How do you write a C plus plus program to display the Fibonacci sequence to 10 terms and then display the 20th term?

#include<iostream>

#include<vector>

#include<cassert>

using namespace std;

// Returns a vector of Fibonacci numbers from start to max.

// Sequence A000045 in OEIS if start is 0.

vector<unsigned> fibonacci (const unsigned start, const unsigned max)

{

// Invariants:

if (1<start)

throw std::range_error

("vector<unsigned> fibonacci (const unsigned start, const unsigned max): start < 1");

if (max<start)

throw std::range_error

("vector<unsigned> fibonacci (const unsigned start, const unsigned max): max < start");

// Empty set...

vector<unsigned> fib {};

if (max)

{

// First term...

fib.push_back (start);

if (1<max)

{

// Second term...

fib.push_back (1);

// All remaining terms...

unsigned next = 0;

while ((next = fib.back()+fib[fib.size()-2]) <= max)

fib.push_back (next);

}

}

return fib;

};

// Return true if the given number is prime.

bool is_prime (const unsigned num)

{

if (num<2) return false;

if (!(num%2)) return num==2;

for (unsigned div=3; div<=sqrt(num); div+=2)

if (!(num%div)) return false;

return true;

}

// Displays all prime Fibonacci numbers in range [1:10,000].

int main()

{

const unsigned max=10000;

vector<unsigned> f = fibonacci (1, max);

cout << "Prime Fibonacci numbers in range [1:" << max << "]\n";

for (auto n : f)

if (is_prime (n))

cout << n << ", ";

cout << "\b\b " << endl; // backspace and overwrite trailing comma

}

C program on shortest-job-first scheduling algorithm?

#include #include #include void main() { char p[10][5],temp[5]; int tot=0,wt[10],pt[10],i,j,n,temp1; float avg=0; clrscr(); printf("enter no of processes:"); scanf("%d",&n); for(i=0;i\n",i+1); scanf("%s",&p[i]); printf("enter process time"); scanf("%d",&pt[i]); } for(i=0;ipt[j]) { 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\t P_time\t w_time\n"); for(i=0;i\t%d\t%d\n",p[i],et[i],wt[i]); printf("total waiting time=%d\n avg waiting time=%f",tot,avg); getch(); }

Write a c program divisible by 3 and 5 or not?

void main(){ int i,j; scanf("%d",&i); if((i%5)==0) printf("the given number is divisible by 5); }

How do you Write a program to read natural numbers from a keyboard Find the largest and the smallest number?

This sounds like a homework assignment, so I will give you some pseudo code instead of straight C code.

[code]

OPEN FILE FOR READING

IF NOT END OF FILE THEN

min = READ FILE INPUT

max = min

ENDIF

WHILE NOT END OF FILE

x = READ FILE INPUT

IF x < min THEN

min = x

ENDIF

IF x > max THEN

max = x

ENDIF

ENDWHILE

CLOSE FILE

[/code]

If you are using C, then you will need to use fopen(), scanf(), fclose() and maybe feof(). If you are using C++ then you can use fstream, must like you would use cin, except that you have to open the stream, check for end of file and close it.

Three elements that must be included in order for a loop to successfully perform correctly?

Well, in C for example the while-loop looks like this:

while (condition) statement

The following ones are all wrong:

condition (while) statement

while (statement) condition

statement (condition) while

...

Write a c program to reverse the any number without using loops?

#include<stdio.h>

#include<conio.h>

void main(){

int a[100],i,temp,j,n;

printf("\t \n enter the size of the array");

scanf("%d",&n);

printf("\n enter the numbers ");

for(i=0;i<n;i++){

scanf("%d",&a[i]);

}

j=n-1;

for(i=0;i<(n/2);i++){

temp=a[i];

a[i]=a[j];

a[j]=temp;

j--;

}

for(i=0;i<n;i++){

printf("\n %d",a[i]);

}

}

What are the different types of data types used in c.net?

In C#, data types can be categorised as

  1. Value Types.
  2. Reference Types.

Value Types

Variables defined from Value Types store values. Copying one value type caribale tp another, doesn't affect the priginal vraible.

They can be further categorised into: -

1) structs: - They can be numeric (int, float, decimal), bool, user-defined structs.

2) Enumerations: - They consist of a set of named constants. By default the first enumerator has value=0.

Reference Types

These objects store references to the actual data. These can be categorised into: -

1) Classes: -- They encapsulate data and its functionality into a single entity called OBJECT.

2) Interfaces: - These are used to declare the signatures, blurprints of methods, delegates and events.

3) Delegates: - These contain the addresses/references to a method.

For more information refer to related links.

What are the disadvantages of switch statement in C-language?

In some languages and programming environments, a case or switch statement is considered easier to read and maintain than an equivalent series of if-else statements, because it is more concise.

However, when implemented with fall-through, switch statements are a frequent source of bugs among programmers new to the switch statement.

What are different ways by which you can access public member functions of an object?

You simply access it. That's what public means. You can access a public member from any other class, or even from non class code, so long as the referenced class is in scope to the referencing code. In order to do that, you need to have a reference (directly or indirectly) to the instance of the class you want to reference. This would generally be passed as an argument to the referencing code.

What is counter loop?

A counted loop is a loop that executes the loop's statement a pre-determined number of times. The count represent the exit condition of the loop. A loop that is not counted is an infinite loop.

What is function of include in c language?

The #include directive is used to tell the preprocessor that the specified file's contents are to be included at the point where the directive appears, just as if you'd typed those contents in full yourself.

Include files are primarily used to organise declarations of external variables and functions, complex data types, constants and macro definitions. The code need only be declared once, and included wherever required. Think of include files as a means of providing forward declarations without having to retype those declarations in full. The definitions of those declarations needn't be contained in the included file, but they must be made available to the program, either as a linked library or as a separate source code file which includes those same declarations.

The include keyword is used in C to tell the linker what libraries your code is going to be using.

What is an example program in c plus plus to square a number using the concept of an inline function?

... double squareOf_Number(double Number)

{

return (Number*Number);

}

...

int main()

{

...

double Number = 0;

...

printf("Enter a number: ");

cin >> Number;

...

printf("Square of %f is %f\n", Number, squareOf_Number(Number));

...

}

Or you can include #include <math.h> and use the function pow(double a, double b) which returns a^b.

C Program To Find GCD?

This function presumes that both parameters are greater than 0.

int gcd(int m, int n)

{ while( m > 0 )

{

if( n > m )

{ int t = m; m = n; n = t; }

m -= n;

}

return n;

}

What is the difference between c plus plus and object code?

Short answer: They're the same.

Due to technical limitations, we on WikiAnswers cannot write C++ in the question field. So we must write "C plus plus." Unfortunately, we're also lazy. So we write "cpp" as an abbreviation.

What is the answer to computer networking a top-down approach featuring the internet 3rd by kurose ross chapter1 question 18?

According to computer networking: a top-down approach, the transmission rate of Ethernet LAN is 10 Mbps, 100 Mbps, 1 Gbps and 10 Gbps. Maximum rate can be transmitted to a destination that is not being transmitted to by other users.

How do you do bubble sort in C programming?

Bubble sort, also known as sinking sort, is a simple sorting algorithm that works by repeatedly stepping through the list to be sorted, comparing each pair of adjacent items and swapping them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted. The algorithm gets its name from the way smaller elements "bubble" to the top of the list. Because it only uses comparisons to operate on elements, it is a comparison sort. Although the algorithm is simple, it is not efficient for sorting large lists; other algorithms are better.

Write an Assembly language program to multiply 32 bit numbers?

.data mult1 dw 2521H dw 3206H mult2 dw 0A26H dw 6400H ans dw 0,0,0,0 .code mov ax,@data mov ds,ax ; LEA SI,ans mov ax,mult1 mul mult2 mov ans,ax mov ans+2,dx mov ax,mult1+2 mul mult2 add ans+2,ax adc ans+4,dx adc ans+6,0 mov ax,mult1 mul mult2+2 add ans+2,ax adc ans+4,dx adc ans+6,0 mov ax,mult1+2 mul mult2+2 add ans+4,ax adc ans+6,dx mov ax,4C00h int 21h end

Write a program to insert or delete a node from doubly linked list?

Encoder:- In character recognition, that class of printer which is usually designed for the specific purpose of printing a particular type font in predetermined positions on certain size forms.

(electronics) In an electronic computer, a network or system in which only one input is excited at a time and each input produces a combination of outputs. encoder http://www.answers.com/main/Record2?a=NR&url=http%3A%2F%2Fcommons.wikimedia.org%2Fwiki%2FImage%3AEncoder%2520diagram.svg http://www.answers.com/main/Record2?a=NR&url=http%3A%2F%2Fcommons.wikimedia.org%2Fwiki%2FImage%3AEncoder%2520diagram.svg Circuit diagram of a single bit 4-to-2 line encoder A3A2 A1 A0 F1 F0 0 0 0 1 0 0 0 0 1 0 0 1 0 1 0 0 1 0 Encoder:- In character recognition, that class of printer which is usually designed for the specific purpose of printing a particular type font in predetermined positions on certain size forms.

(electronics) In an electronic computer, a network or system in which only one input is excited at a time and each input produces a combination of outputs. encoder http://www.answers.com/main/Record2?a=NR&url=http%3A%2F%2Fcommons.wikimedia.org%2Fwiki%2FImage%3AEncoder%2520diagram.svg http://www.answers.com/main/Record2?a=NR&url=http%3A%2F%2Fcommons.wikimedia.org%2Fwiki%2FImage%3AEncoder%2520diagram.svg Circuit diagram of a single bit 4-to-2 line encoder A3A2 A1 A0 F1 F0 0 0 0 1 0 0 0 0 1 0 0 1 0 1 0 0 1 0 1 0 0 0 1 1 Truth table

What are the disadvantages of breadth first search?

takes a lot of time because you will have to go through all the parent nodes before going to the children nodes

How do you print the revers string?

u got a String A

String B stores the reverse

A="John"

use a reverse loop.

for(int i=A.length();i>0;i--)
{
p=A.charAt(i);
B=B+p;
}

thats it u got the reverse in B


In Java, you can just use the build-in method of the class StringBuffer.

1 121 12321 1234321 program?

1^2 = 1
11^2 = 121
111^2 = 12321
1111^2 = 1234321
11111^2 = 123454321













#include
#include
#include
void main()
{
clrscr(); int n;//soullessgod
cout<<"\n enter number of lines ";//whatsoever
cin>>n;
int a=1,b,s=1;
for(;a<=n;s=s*10+1)
{
for(b=n-a;b>=1;b--)
{
cout<<" ";
}
cout<cout<<"\n";
a++;
}

getch();
}

What are the data types provided in c language?

C is not an object oriented programming language. As such there are no class data types in C.