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

Write a program in C language to find the ratio of two numbers?

To find the ratio of x and y, the formula is x/GCD(x,y) : y/GCD(x,y).

#include<stdio.h>

#include<conio.h>

int gcdrec(int ,int);

void main()

{

int x,y;

clrscr();

scanf("%d %d",&x,&y);

printf("Ratio = %d:%d",x/gcdrec(x,y),y/gcdrec(x,y));

getch();

}

int gcdrec(int a , int b)

{

return(b!=0 ? gcdrec(b,a%b) :a);

}

Factorial in c program using for loop?

#include<stdio.h>

#include<conio.h>

void main()

{

int i,n,fact=1;

clrscr();

printf("enter the number");

scanf("%d",&n);

for(i=1;i<=n;i++)

printf("%d",n);

fact=fact*i;

{

printf("the factorial is=%d",fact);

}

getch();

}

By:-Abhishek Goyal(goyal.abhi40@yahoo.com)

What is the index number of the last element of an array with 9 elements?

(array.length - 1) will find the index of the last element in an array (or -1 if the array is empty).

Is pascal high level language?

The original Pascal programming language was designed by Niklaus Wirth between 1968 and 1969, published in 1970. Object Pascal was developed in 1985 by Larry Tessler, in consultation with Wirth.

What is static function and static class?

Static function are function only visible to other function in same file Function outside the class can access, useful whenever we need to have functions which are accessible even when the class is not instantiated.

What does iteration mean in ict?

i want the answers not to answer it

come on

:(

mas

mildly amused smile=mas

lol

Illustrate to implement deque using circular linked list?

#include <stdio.h>

#include <conio.h>

#include <alloc.h>

struct node

{

int data ;

struct node *link ;

} ;

struct dqueue

{

struct node *front ;

struct node *rear ;

} ;

void initdqueue ( struct dqueue * ) ;

void addqatend ( struct dqueue *, int item ) ;

void addqatbeg ( struct dqueue *, int item ) ;

int delqatbeg ( struct dqueue * ) ;

int delqatend ( struct dqueue * ) ;

void display ( struct dqueue ) ;

int count ( struct dqueue ) ;

void deldqueue ( struct dqueue * ) ;

void main( )

{

struct dqueue dq ;

int i, n ;

clrscr( ) ;

initdqueue ( &dq ) ;

addqatend ( &dq, 11 ) ;

addqatbeg ( &dq, 10 ) ;

addqatend ( &dq, 12 ) ;

addqatbeg ( &dq, 9 ) ;

addqatend ( &dq, 13 ) ;

addqatbeg ( &dq, 8 ) ;

addqatend ( &dq, 14 ) ;

addqatbeg ( &dq, 7 ) ;

display ( dq ) ;

n = count ( dq ) ;

printf ( "\nTotal elements: %d", n ) ;

i = delqatbeg ( &dq ) ;

printf ( "\nItem extracted = %d", i ) ;

i = delqatbeg ( &dq ) ;

printf ( "\nItem extracted = %d", i ) ;

i = delqatbeg ( &dq ) ;

printf ( "\nItem extracted = %d", i ) ;

i = delqatend ( &dq ) ;

printf ( "\nItem extracted = %d", i ) ;

display ( dq ) ;

n = count ( dq ) ;

printf ( "\nElements Left: %d", n ) ;

deldqueue ( &dq ) ;

getch( ) ;

}

/* initializes elements of structure */

void initdqueue ( struct dqueue *p )

{

p -> front = p -> rear = NULL ;

}

/* adds item at the end of dqueue */

void addqatend ( struct dqueue *p, int item )

{

struct node *temp ;

temp = ( struct node * ) malloc ( sizeof ( struct node ) );

temp -> data = item ;

temp -> link = NULL ;

if ( p -> front NULL )

return ;

while ( p -> front != NULL )

{

temp = p -> front ;

p -> front = p -> front -> link ;

free ( temp ) ;

}

}

What does Microsoft Visual C plus plus Runtime Library mean?

The runtime library is a collection of routines that implements basic functionality of the platform. Routines such as I/O, memory control, startup, shutdown, common system functions, etc. are located in the runtime library.

Write a program to print n natural numbers using for loop?

//to display 'n' natural numbers using for loop......(in C).....

#include<stdio.h>

main()

{

int n,i;

printf("\n Enter the range......Please...\t");

scanf("%d",&n);

printf("\n Range of Natural Numbers.....\t");

for(i=1;i<=n;i++)

{

printf("\t%d",i);

}

}

Basic parts of TURBO C program?

Editor - edits text

Compiler - compiles the program

Linker - links the program

Debugger - helps finding bugs

What is a small increment of time?

the smallest increment of time is... miliseconds.

What are the advantages of a class in C over a structure in C?

A C struct only has public member variables whereas a C++ class combines member variables with member functions; the methods that operate upon the data. Moreover, each member of a class can be assigned a different level of access from public, protected or private access, thus limiting the member's exposure. This allows classes to hide data and implementation details from outside of the class, exposing only as much as is necessary in order to use the class. Thus the class becomes entirely responsible for the integrity of its data, while its methods act as the gatekeepers to that data.


Note that in C++, a struct is exactly the same as a class, other than the fact that the members of a struct are public by default while members of a class are private by default, unless explicitly declared otherwise. Aside from that they operate in exactly the same way. In other words, a C++ struct is not the same as a C struct.



How do you write a program to accept a month number and display a maximum number of days?

DisplayMonth( int month ) //base 0

{

switch( month )

{

case 0: printf("January\n"); break;

case 1: printf("February\n"); break;

case 2: printf("March\n"); break;

.... and so on

}

}

enjoy

What is bus memory transfer?

A bus transfer is basically proof that you paid. It is also used whenever you need to take two buses to get to your destination. For example, if you need to go northeast then you'll probably need to take two buses.

You pay the price for the first bus you get on and ask the bus driver for a transfer after you pay. After you get off the first bus and get onto the second bus, you just need to show the transfer to the bus driver and he or she will let you in unless it is expired because there's a one-hour time limit. If you're not sure what I'm saying, you can ask the bus driver for a transfer and look at the back of it. There's usually some information about how to use it.

What are the subject-matters of data structure?

types of data structure types of data structure

Which of the following symbols can be used while naming a variable in C?

User-defined names (whether variables or functions) must begin with a letter or an underscore (not a digit), and may contain any combination of letters, numbers and underscores, but no spaces or punctuation.

No name may be the same as a reserved word or keyword, but all names are case sensitive. So while return is a reserved word, Return and RETURN are not. However, it's best to avoid such ambiguities and come up with your own unique names.

Beyond that you are free to use any naming convention that makes sense to you, but ultimately your code must be readable. Variable names like i, j and k may seem obvious to you while you are hurriedly writing code, but next time you look at that code it somehow doesn't seem quite so obvious what i represents. Single letters are fine for looping purposes and temporary variables but even a short abbreviation can help clarify the exact purpose of a variable. The more self-explanatory a variable is, the more readable your code becomes.

It is quite common for constants to be all uppercase to give a visual reminder. However, there are other conventions you may encounter such as prefixing class member variables with m_ often followed by a short type identifier, such as m_iAge, to denote a member integer variable, or pszCaption to denote a null-terminated string. There are no rules on this regard, but whatever conventions you choose to use, use them consistently.

What do you know about for loop and do while loop?

The condition for a while loop is tested at the start of the loop. It is tested at the end of the loop for a do-while loop.

The body of a do-while loop will always be executed at least once. Whereas for

a while loop if the condition is false to start with, the body of the loop is never executed.

How function declared in C plus plus?

Functions are declared by specifying the function return type (which includes any use of the const qualifier), the name of the function, and the function's argument types enclosed in parentheses (round brackets), which also includes any use of the const qualifier. The declaration ends with a semi-colon. Arguments may also be given default values but if any argument has a default value, all arguments that follow must also have default values.

[const] type name([[const] type [=value][, ...]]);

Declarations may also contain definitions in which case you must include the formal argument names that will be used by the definition. The definition (or implementation) must be enclosed in braces (curly brackets) and the semi-colon must be omitted.

[const] type name([[const] type arg1 [=value][, ...]])

{

statement;

}

Functions must be declared before they can be used. In most cases it is necessary to forward declare functions in a header. In these cases, default values must be omitted from the definition.

Functions that do not return a value must return void. Functions that do not accept arguments must still include the argument parentheses. Use of the void keyword to indicate no arguments is optional. Thus the following declarations are exactly the same (although declaring both in the same program would be invalid):

void f();

void f(void);

As well as the return type and argument types, class member functions (methods) can also be modified with the const qualifier:

struct obj

{

void f(void) const;

};

The const keyword assures the caller that the object's immutable members will not be modified by the function (that is, the internal state of the object's immutable data will remain unaltered). Also, when working with constant objects, only constant methods can be called.

Functions can also be declared static. In the case of external functions, the static keyword limits the visibility of the function to its translation unit. In the case of class methods, static member functions are local to the class as opposed to instances of the class. Static member functions do not have access to an implicit this pointer since they are not associated with any instance of the class but are accessible even when no instances of the class exist.

Can you declared constructor as private?

If you declare the main method anything other than public, it will not run.

If you declare main method as private, you would not be able to execute the class as a standalone java program. Any java class that needs to be executed as a standalone file needs to have a main method that is public, static and returns a void. Otherwise the Java compiler would not recognize the file as an executable standalone java file and would not allow you to run it.

Return type of malloc?

void * (If you used your help/manual system, you would get an answer much sooner.)

Why does a java compiler use C language?

The original Java compiler was probably written in C/C++ because an efficient language like C is ideal for writing compilers in.

What is difference between C and C plus plus programming?

THE DIFFERENCE BETWEEN c&c++ IS JST THAT c++ IS MODIFIED LANGUAGE AND IT IS A HOGH LEVEL LANGUAGE AS COMPARED c IS A LOW LEVEL LANGUAGE

C++ was developed as a better 'C' language. In addition, C is a procedural language only, and C++ has both procedural language features and object oriented features.

Both are considered high level languages.

C++ is an addition to C. C only allows you to write programs as a list of instructions (procedure), while C++ allows you to write separate objects, and link them together to produce a piece of software.

What are the advantages and disadvantages of searching in C programming?

If the data is sorted and every element is directly accessible, then you can perform binary search (see built-in function bsearch), otherwise you have to do linear search (which is slower).

How do you declare a stack in c?

# #include

# #include

#

# const int TPILA=5; // TPILA es el valor maximo de elementos

# // que puede tener nuestra pila

#

# class PILA{

# public:

# int mipila[TPILA]; // Crea mi PILA de tamano TPILA

# int apilados; // Numero de objetos en LA PILA

# void reset(); // Vacia LA PILA

# void push(int v); // Agrega Valores en el tope de la PILA

# int pop(); // Retorna y elimina el tope de la PILA

# };

#

# void PILA::reset() // Vacia la PILA

# {

# apilados=0;

# }

#

# //Se Agrega(PUSH) un valor en el tope de la pila

# void PILA::push(int v)

# {

# // Comprueba que haya espacio dentro de la pila

# // para poder agregar el nuevo valor

# if(apilados

# {

# mipila[apilados++]=v;

# }

# }

#

# // Se Elimina (POP) el ultimo valor de la pila

# // y retorna el nuevo tope

# int PILA::pop()

# {

# if(apilados>0)

# {

# cout<<"El valor del tope eliminado era: ";

# // Retorna el valor del tope que fue eliminado

# return(mipila[--apilados]);

# }

# else

# cout<<"No existen datos para eliminar. ERROR ";

# return (0);

# }

#

# main()

# {

# PILA stack;

# stack.reset();

# int opc, i, dato;

# char out;

# do

# {

# do

# {

# clrscr();

# cout<<"El siguiente programa simula el funcionamiento de"<

# cout<<"una pila y es capaz de apilar un max. de 5 Valores"<

# cout<<"numericos enteros, para fines practicos\n\n";

# cout<<"Que operacion desea Realizar\n\n";

# cout<<"1.- Insertar un dato\n";

# cout<<"2.- Borrar un dato\n";

# cout<<"3.- Mostrar pila\n";

# cout<<"4.- Resetear Pila\n";

# cout<<"5.- Salir";

# cout<<"\n\n\nOpcion(1-5): ";

# cin>>opc;

# }

# while(opc>5);

#

# switch(opc)

# {

# case(1):

# if(stack.apilados

# {

# cout<<"dato?: ";

# cin>>dato;

# stack.push(dato);

# }

# else

# cout<<"ERROR! PILA LLENA!";

# cout<<"\n\nSalir?? (S/N): "; cin>>out;

# break;

# case(2):

# cout<

# cout<<"\n\nSalir?? (S/N): "; cin>>out;

# break;

# case(3):

# if(stack.apilados!=0)

# {

# cout<<"Los datos en la pila actualmente son: "<

# for(i=0;i

# { cout<

# }

# else

# cout<<"No existen datos en la pila"<

# cout<<"\n\nSalir?? (S/N): "; cin>>out;

# break;

# case(4):

# stack.reset();

# cout<<"\n\nSalir?? (S/N): "; cin>>out;

# break;

# case(5):

# out='s'; break;

# default:

# out='s'; break;

# }

# }

# while(out=='n' out=='N');

# }