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

Is string is an predefined data types in c?

No. In C string is an array of characters terminated by a null character (a character having ascii value 0).In more high level languages like C# and Java string is a predefined data type and hence limits the operation on string by some pre-defined library functions. But C provides complete control over strings.The Following step shows declaration of a string in various methods.

char str[6] = {'h' . 'e'. 'l'. 'l'. 'o'.'\0'};

One thing you need to notice is that the size of the character array should be atleast 1 greater than the number of characters in the string for accommodating the null character.

but

char str[] = "hello";

statement appends the null character automatically and no need to specify the length of the array (of course you can specify it if you want). The compiler automatically allocates the memory according to the length of the string.

What is Newton raphson's method in r programing?

It's a method used in Numerical Analysis to find increasingly more accurate solutions to the roots of an equation.

x1 = x0 - f(x0)/f'(x0) where f'(x0) is the derivative of f(x0)

What are the three uses of void data types?

The void type has only one purpose: to specify the return type of a function that has no return value. In this case void simply means no type.

The only other usage is when used as a pointer to void (void*), which simply means a pointer type that can refer to any type of object. If the pointer is non-null, it must be cast to a specific type before it can be dereferenced.

What is the value of 201 percent 4?

201% of 4 = 8.04

On a calculator you can do this by:

201%*4 or 2 1/10 * 4 or 2.1 * 4

Does nyquist plot uses open loop closed loop or characteristic equation?

everyone knows the answer to that. if u dont u need to change ur major

What is the function of adobe premiere?

You use Adobe Premiere to create movies, edit videos, etc. Adobe Premiere is like a more professional version of iMovie, Windows Media Player, and is closely related to Final Cut.

What are the different types of agonist?

There are partial agonists and full agonists. Partial don't elicit a maximum response and have an efficacy of less than 1. Full elicit a full response and have an efficacy of 1. There are also antagonists that bind to receptors but don't elicit a response. Inverse agonists produce an opposite response.

The distance between two cities in km is input through the keyboard write a program to convert and print this distance in meters feet inches and centimeters?

mesh's basic salary is input through the keyboard. his dearness allowance is 40% of basic salarying , and house rent allowance is 20% of basic salaried. write a program to calculate his gross salary

C plus plus code that determine prime number?

#include <iostream.h>

main()

{

int a;

cout<<"enter a number : ";

cin>>a;

cout<<endl;

if (a%2-1)

cout<<"it is a prime number";

else

cout<<"it is not a prime number"

return 0;

}

------------------------------------------

output: enter a number : 30

it is a not a prime number

Overload plus operator for string concatenation in coding?

#include
using std::cout;
using std::endl;

#include
using std::string;

int main()
{
string s1( "AA" );
string s2( " AAB" );
string s3;

//
cout << "\n\ns1 += s2 yields s1 = ";
s1 += s2; // test overloaded concatenation
cout << s1;
return 0;
}

Write a program that prompts the user to input a positive integer It should then output a message indicating whether the number is aprime or not?

Output a prompt.
Either:
Read from standard input (std::cin) to an integer.

Or:
Read a line from standard input (std::getline()) to a string.
Create a string stream (std::stringstream) to read the string.
Read from the string stream to an integer.

For each integer from 2 to half the entered integer:
If the entered integer is divisible by the current integer:
The number is not prime.
Exit the program.

The number is prime.
Exit the program.

How do you give values to variable?

it depend on the programming language u use. for instance in c, just decalre the variable and equal it to the value it is to take. eg. my_age=21; /*my_age is the decared variable and 21 is the assigned value*/ //for php $my_age=21; /*my_age is the decared variable and 21 is the assigned value*/ for strings (in php)eg. $my_age="none of ur business" /*$my_age is the variable and the string "none of ur business" is the assigned value*/

What does it mean to run a program?

In computer terminology, "running a program" means copying a sequence of instructions from storage into main memory and initiating the execution or interpretation of those instructions.

What step that converts source file directives to source code program statements.?

A pre-processor will scan your code files for directives and then evaluate the conditions specified by the directive. Then depending on the evaluation of the condition it may include certain program statements and/or ignore others before handing the "modified" source code to the compiler.

Can you have two mains in a c program?

No you can't. main() is the entry point of a C program where execution starts. Only a single main() can exist in a C program. A program with 2 mains wil not even compile successfully.

Find out the address of the element A452 where A is a 3-dimensional array with subscript limits 1 you 6 1 j 7 and 0 k 4 when A is in row major addressing Assume base address is 1000 and word size is 2?

1. Find out the address of the element A(4,5,2) where A is a 3-dimensional array with subscript limits 1≤ i ≤6, 1≤ j ≤7 and 0≤ k ≤4 when A is in row major addressing. Assume base address is 1000 and word size is 2.

Answer:

Array(depth,col,row) means A(4,5,2)

Address= BASE+ ((depthindex*col_size+colindex) * row_size + rowindex) * Element_Size

ADDRESS=1000+((4*7+5)*5+2)*2

(1000+((33*5)+2)*2

(1000+(167*2))

(1000+334)

1334

How to pass the parm parameter in PL1?

In JCL it would be of the form exec pgm=mypgroam, parms="/B" where the info after the "/" is the parameter strring.

8086 program to arrange a string of bytes in ascending order?

Mov ax,data

mov ds,ax

mov dl,05h

up2: lea si,ser1

mov cl,05h

up1: mov al,ds:[si]

mov ah,al

inc si

cmp al,ds:[si]

jc down

mov ah,ds:[si]

mov ds:[si],al

dec si

mov ds:[si],ah

inc si

down:dec cl

jnz up1

dec dl

jnz up2

int 3h

Write a C program to generate following sequence eg when 5 is pressed the sequence should be 0 1 1 2 3 5 and if 3 is pressed 0 1 1 2 the sequence should be according to the number pressed?

/* the sequence printed is Fibonacci's sequence, each element is calculated as a sum of two previous elements */
#include
int main()
{
int i;
int n;
int a0=0;
int a1=1;

printf("How many elements do you want to print? ");
scanf("%d",&n);

printf("0 ");
if (n > 0)
printf("1 ");


for (i = 2; i <= n; i++)
{
printf("%d ", a0+a1);

a1 = a0 + a1;
a0 = a1 - a0;

}
return 0;

}

Heap sort program in C language?

#include <stdlib.h>

#include <stdio.h>

#define uint unsigned int

typedef int (*compare_func)(int, int);

void heap_sort(int This[], compare_func func_pointer, uint len)

{

/* heap sort */

uint half;

uint parents;

if (len <= 1)

return;

half = len >> 1;

for (parents = half; parents >= 1; --parents)

{

int tmp;

int level = 0;

uint child;

child = parents;

/* bottom-up downheap */

/* leaf-search for largest child path */

while (child <= half)

{

++level;

child += child;

if ((child < len) &&

((*func_pointer)(This[child], This[child - 1]) > 0))

++child;

}

/* bottom-up-search for rotation point */

tmp = This[parents - 1];

for (;;)

{

if (parents child)

break;

if ((*func_pointer)(tmp, This[child - 1]) <= 0)

break;

child >>= 1;

--level;

}

/* rotate nodes from parents to rotation point */

for (;level > 0; --level)

{

This[(child >> level) - 1] =

This[(child >> (level - 1)) - 1];

}

This[child - 1] = tmp;

} while (--len >= 1);

}

#define ARRAY_SIZE 250000

int my_array[ARRAY_SIZE];

void init()

{

int indx;

for (indx=0; indx < ARRAY_SIZE; ++indx)

{

my_array[indx] = rand();

}

}

int cmpfun(int a, int b)

{

if (a > b)

return 1;

else if (a < b)

return -1;

else

return 0;

}

int main()

{

int indx;

init();

heap_sort(my_array, cmpfun, ARRAY_SIZE);

for (indx=1; indx < ARRAY_SIZE; ++indx)

{

if (my_array[indx - 1] > my_array[indx])

{

printf("bad sort\n");

return(1);

}

}

return(0);

}

What is the program for snake and ladder game in c plus plus?

#include<iostream>

#include<array>

#include<string>

#include<random>

#include<ctime>

using player_t = std::array<unsigned, 2>;

using pair_t = std::pair<unsigned, unsigned>;

using snake_t = std::array<pair_t, 10>;

using ladder_t = std::array<std::pair<unsigned, unsigned>, 9>;

const std::string player (const bool human)

{

return std::string {human ? "You" : "I"};

}

int main()

{

std::default_random_engine generator ((unsigned) time (0));

std::uniform_int_distribution<unsigned> distribution (1, 6);

player_t players = {0,0};

const snake_t snakes = {pair_t {98,78}, {95,75}, {93,73}, {87,24}, {64,60}, {62,19}, {56,53}, {49,11}, {47,26}, {16,6}};

const ladder_t ladders = {pair_t {1,38}, {4,14}, {9,31}, {21,42}, {28,84}, {36,44}, {51,67}, {71,91}, {80,100}};

std::cout << "Snakes and Ladders\n";

std::cout << "==================\n\n";

std::cout << "First to land exactly on square 100 wins.\n";

bool human = (distribution (generator) % 2)==0 ? true : false;

std::cout << player (human) << " will go first.\n\n";

for (;;human=!human)

{

std::cout << (human ? "Your" : "My") << " turn:\n";

unsigned dice = distribution (generator);

std::cout << '\t' << player (human) << " rolled a " << dice << ".\n";

unsigned& pos = players [human?0:1];

if (pos+dice>100)

{

std::cout << '\t' << player (human) << " cannot move";

goto next_player;

}

pos+=dice;

std::cout << '\t' << player (human) << " landed on square " << pos;

for (auto snake : snakes)

{

if (snake.first==pos)

{

pos = snake.second;

std::cout << " with a snake; return to square " << pos;

goto next_player;

}

}

for (auto ladder : ladders)

{

if (ladder.first==pos)

{

pos = ladder.second;

std::cout << " with a ladder; climb to square " << pos;

goto next_player;

}

}

next_player:

std::cout << ".\n\n";

if (pos==100)

{

std::cout << player (human) << " won!\n";

break;

}

}

}