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

C program to find the lowest digit of a number?

#include<stdio.h>

#include<conio.h>

void main()

{

int n,d[10],i,k,s;

clrscr();

printf("enter the number..:");

scanf("%d",&n);

for(i=0,t=n;t>0;i++)

{

d[i]=t%10;

t=t/10;

}

k=i;

s=d[0];

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

{

if(d[i]<s)

s=d[i];

}

printf("\n The smallest digit is...%d",s);

getch();

}

Program to drow graphical circle in c?

Standard C does not include any graphical functions thus there is no standard method for drawing circles. For that you will need a graphics library suited to your specific hardware and operating system. Specific methods will vary according to which library you use, however there are also generic library's available depending on your hardware's capabilities. Consult your library's documentation; there will typically be simple examples to demonstrate the library's core features, including drawing circles.

What kind of diagram graphically illustrates the structure of a program?

A flowchart is used to illustrate the logic of the program. To illustrate the structure we typically use a hierarchical tree, where the main function serves as the root.

How do you write a c program to swap the values of two variables in unix?

#include<stdio.h>

void main()

{

int a=2,b=4;

printf("Program for swapping two numbers ");

printf("Numbers before swapping");

printf("a=%d and b=%d",a,b);

a=((a+b)-(b=a));

printf("Numbers after swapping");

printf("a=%d and b=%d",a,b);

getch();

}

How do you write a C program to print the table from 1 to n side by side?

#include
#include
void main()
{ int
printf("\nEnter the no. upto which the multiplication table is to be displayed:");
scanf("%d",&n);

for(i=1;i<=n;i++)
{ printf("\n%d TABLE:\n",i);
for(j=1;j<=10;j++)
printf("d=%d\n",i,j,i*j);
}
getch();
}
If the ans helps you,plz increase the trust point.

How do you make a C plus plus program that arrange the numbers from highest to lowest?

Use the std::vector template class (in header <vector>) to store the numbers, then apply the std::vector.sort() algorithm. The default sort order is ascending. The elements must support the less-than operator (<). All the built-in primitives (int, char, double and float) already support this operator.

How do you create our own header file in c plus plus?

1. open word processing software. (Notepad or wordpad)

2. Write the desired function for the header.

3. Save it with .h as extension. Like "myheader.h"

4. Run cpp.

5. It should be like this... #include "myheader.h" 1. A header file is not any different to the compiler than ordinary code

2. Its just a convenient way to have commonly "included" code

3. It is primarily used for prototypes, not actual code, such as declaring an API

4. Be care with redeclarations. The #ifdef / #endif pragmas can help

5. The location of "user defined" headers is different than system headers

6. They are normally in the build directory, whereas system headers are elsewhere

Write a c program that reverse a given integer number and check whether the number is palindrome or not?

#include <stdio.h>

#include <string.h>

#define N 100

#define PALINDROME 0

#define NONPALINDROME 1

/*Program that tells you whether what you enter is a palindrome or not*/

char pal[N]; //input line

int i; //counter

int k; //counter

int tag;

int flag = PALINDROME; /*flag=0 ->palindrome, flag =1 ->nonpalindrome*/

int main()

{

printf("Enter something: \n");

scanf("%s", pal);

tag = strlen(pal); /*determine length of string*/

/* pointer running from the beginning and the end simultaneously

looking for two characters that don't match */

/* initially assumed that string IS a palindrome */

/* the following for loop looks for inequality and flags the string as

a non palindrome the moment two characters don't match */

for (i=0,k=tag-1; i=0; i++,k--) {

if(pal[i] != pal[k]) {

flag=NONPALINDROME;

break;

}

}

if(flag == PALINDROME) {

printf("This is a palindrome\n");

}

else {

printf("This is NOT a palindrome\n");

}

return 0;

}

#include <stdio.h>

#include <string.h>

#define N 100

#define PALINDROME 0

#define NONPALINDROME 1

/*Program that tells you whether what you enter is a palindrome or not*/

char pal[N]; //input line

int i; //counter

int k; //counter

int tag;

int flag = PALINDROME; /*flag=0 ->palindrome, flag =1 ->nonpalindrome*/

int main()

{

printf("Enter something: \n");

scanf("%s", pal);

tag = strlen(pal); /*determine length of string*/

/* pointer running from the beginning and the end simultaneously

looking for two characters that don't match */

/* initially assumed that string IS a palindrome */

/* the following for loop looks for inequality and flags the string as

a non palindrome the moment two characters don't match */

for (i=0,k=tag-1; i=0; i++,k--) {

if(pal[i] != pal[k]) {

flag=NONPALINDROME;

break;

}

}

if(flag == PALINDROME) {

printf("This is a palindrome\n");

}

else {

printf("This is NOT a palindrome\n");

}

return 0;

}

Characteristics of an algorithm?

An algorithm is written in simple English and is not a formal document. An algorithm must:

- be lucid, precise and unambiguous

- give the correct solution in all cases

- eventually end

Also note it is important to use indentation when writing solution algorithm because it helps to differentiate between the different control structures.

1) Finiteness: - an algorithm terminates after a finite numbers of steps. 2) Definiteness: - each step in algorithm is unambiguous. This means that the action specified by the step cannot be interpreted (explain the meaning of) in multiple ways & can be performed without any confusion. 3) Input:- an algorithm accepts zero or more inputs 4) Output:- it produces at least one output. 5) Effectiveness:- it consists of basic instructions that are realizable. This means that the instructions can be performed by using the given inputs in a finite amount of time.

What is difference between c plus plus and data structures?

Data structure is nothing but a way to organize and

manipulate any given set of data in a specific and reusable

format/structure hence simplifying the manipulation of data.

Some of the commonly and frequently used data structures

are Stack, Queue, List, Set, e.t.c. But this list is not

limited to what we see here, rather we can invent our own

as long as there is a definite structure and better

efficiency by using it than work with raw data.

What does the header file in c consists of?

Headers are primarily used to separate interfaces from implementations in order to provide modularity and organisation of code. Headers typically contain declarations of related data types, classes and functions while corresponding source files contain the implementations or definitions for those types. The only real exceptions are template functions and classes which must be fully-defined within the header.

By separating the interfaces from the implementations, other source files can make use of those interfaces simply by including the appropriate headers. All headers must use header guards to ensure each is only included once in any compilation.

Headers can also include other headers, however this is only necessary if the header requires access to the interface contained therein. For instance, if the header declares a derived class, the base class header must be included as the derived class declaration needs to know the interface details of its base class. Similarly if a class contains an embedded class member, the interface for that member must be known. Pointers and references to types do not require interfaces, thus a forward declaration suffices. However, if a header includes an inline implementation that requires an interface (such as an accessor that returns a type by value, or that invokes a method of a type), the appropriate header for that type must be included.

All types that can be forward declared in a header must be included in the header's corresponding source file.

The one exception to separating interface from implementations is when creating template functions or classes. Templates must be fully-defined thus all implementation details must be available from the header alone. One way of maintaining separation is to have the header include the source file rather than the other way around. However, the inclusion must come after the interface declaration, and the source must not include the header.

How do you write a program to arrange the numbers in ascending order using 8085 microprocessor?

MVI B, 09 : Initialize counter

START : LXI H, 2200H: Initialize memory pointer

MVI C, 09H : Initialize counter 2

BACK: MOV A, M : Get the number

INX H : Increment memory pointer

CMP M : Compare number with next number

JC SKIP : If less, don't interchange

JZ SKIP : If equal, don't interchange

MOV D, M

MOV M, A

DCX H

MOV M, D

INX H : Interchange two numbers

SKIP:DCR C : Decrement counter 2

JNZ BACK : If not zero, repeat

DCR B : Decrement counter 1

JNZ START

HLT : Terminate program execution

How do you declare a two dimensional array with initialiser in C programming?

#include <iostream>

#include <iomanip>

using std::cout;

using std::endl;

using std::setw;

int main()

{

static const char *Rush[3][2] = {

{ "Geddy Lee", "Vocals, bass and keyboards" },

{ "Alex Lifeson", "Lead/rhythm guitar" },

{ "Neil Peart", "Drums & percussion" }};

cout << "Personnel:" << endl << endl;

for (int nPerson=0; nPerson<3; ++nPerson)

cout << setw(16) << Rush[nPerson][0] << " : " << Rush[nPerson][1] << endl;

cout << endl;

return( 0 );

}

Write an 8086 assembly language program to compare if two strings are of the same length?

org 100h

.data

str1 db "Computer"

str2 db "computer"

mes1 db "string are same $"

mes2 db "string are different $"

.code

assume cs:code,ds:data

start: mov ax,@data

mov ds,ax

mov es,ax

mov si,offset str1

mov di,offset str2

cld

mov cx,8

repe cmpsb

mov ah,9

jz skip

lea dx,mes2

jmp over

skip: lea dx,mes1

over: int 21h

mov ax,4c00h

int 21h

end start

ret

What is the binary search tree worst case time complexity?

Binary search is a log n type of search, because the number of operations required to find an element is proportional to the log base 2 of the number of elements. This is because binary search is a successive halving operation, where each step cuts the number of choices in half. This is a log base 2 sequence.

C program for prime number?

A number is a prime number if it is divisible by only 1 and itself. So make use of for loop and check for this condition.

int i,num,flag = 0;//num is the number to check

scanf("%d", &num);

for( i=2; i

if( num%i == 0)//it has other divisors

flag = 1;

}

if( !flag)

printf("The number is prime\n");

else

printf("The number is not prime\n");


Implementation of index sequential file organization?

Indexed sequential file organization. =In indexed sequential file organization, the records arestored in sequence according to a primary key and an index is created to allow random access of the file. This type of organization also allows the file to be accessed sequentially. Indexed sequential is the most commonlyused type of file organization. writer-k.k.b -montanna

Is a for loop a post-test loop?

Yes. The second clause (the condition) is evaluated before each iteration through a loop. It is possible that a for loop will not execute if its precondition is not met. For example, "for( int x = 5; x < 5; x++ )" will not iterate even once.

Check wheather the strings are equal?

int string_equal (char *p1,char *p2)

{

int status = 1;

while ((*p1 *p2) && status==1)

{

if (*p1++ != *p2++) status = 0;

}

return status;

}

What is the difference between sprintf and fprintf?

sprintf: This Writes formatted data to a character string in memory instead of stdout

Syntax of sprintf is:

#include

int sprintf (char *string, const char *format

[,item [,item]...]);

Here

String refers to the pointer to a buffer in memory where the data is to be written. Format refers to pointer to a character string defining the format. Each item is a variable or expression specifying the data to write.

The value returned by sprintf is greater than or equal to zero if the operation is successful or in other words the number of characters written, not counting the terminating null character is returned. And return a value less than zero if an error occurred.

printf: Prints to stdout

Syntax for printf is:

printf format [argument]...

The only difference between sprintf() and printf() is that sprintf() writes data into a character array, while printf() writes data to stdout, the standard output device

Write a program to find the reverse of a given number with help of function?

//Reverse of the Number

#include<stdio.h>

#include<conio.h>

int main ()

{

int num,mod,rev=0;

printf("Enter a number:");

scanf("%d", &num);

while (num>0)

{

mod=num%10;

rev=(rev*10)+mod;

num=num/10;

}

printf("Reverse of the given number: %d", rev);

getchar();

return 0;

}

// alternative solution based on reversing the alphanumeric representation of

// the number:

void rev(int me) {

char alpha[32];

sprintf(alpha, "%d", me);

for (const char* cp = alpha + strlen(alpha) - 1; cp >= alpha; --cp) {

putchar(cp); }

}

What are sequential access files?

The file(s) (data) which are accessed in a sequential or a orderly manner is called as a sequentially accessing a file.