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

Answers to Programming in C Third Edition by Stephen G Kochan?

Programming in C Third Edition by Stephen G Kochan is a book about a programming language that consists of cross platform usage as long as you had adhered to the rules of the language!

This language can be combined with other "SDK" header files or basically code sepearated and formatted to isolated header files that consist of "variable declarations", "function declarations" and perform certain matmatical operations for you as you use the functions in a "modular" way and share peacfully.

What is the ASCII value of white space in c language?

int main (void) { printf ("space is %d\n", ' '); return 0; }

Program to find the occurrences of a given character in a string in c plus plus?

#include

#include

size_t count_char (const std::string& s, const char c)

{

size_t count = 0;

size_t offset = 0;

while ((offset = s.find(c, offset)) != s.npos)

{

++count;

++offset;

}

return count;

}

int main()

{

std::string str {"Hello world!"};

std::cout << "String: "" << str << """ << std::endl;

for (auto c : str )

{

size_t count = count_char (str, c);

std::cout << "'" << c << "' occurs " << count << " time" << (count==1?"":"s") << "." << std::endl;

}

}

Example output:

String: "Hello world!"

'H' occurs 1 time.

'e' occurs 1 time.

'l' occurs 3 times.

'l' occurs 3 times.

'o' occurs 2 times.

' ' occurs 1 time.

'w' occurs 1 time.

'o' occurs 2 times.

'r' occurs 1 time.

'l' occurs 3 times.

'd' occurs 1 time.

'!' occurs 1 time.

Write a program to print whether the letter is vowel or not in BASIC?

vowels$ = "aeiou"

CLS

PRINT "PROGRAM: Find if letter is a vowel or not"

PRINT

INPUT "Type a single alphabet letter: (a-z)/and, then, press Enter key"; aLetter$

PRINT

PRINT "Letter "; aLetter$;

IF INSTR(vowels$, LCASE$(aLetter$)) THEN PRINT " is a vowel." ELSE PRINT " is NOT a vowel."

END

What are the different types of control units and explain the hardwired control unit with diagram?

Answer: Control unit is a computerized part of the speech processor. Most of the controls, such as program, volume and sensitivity, are located on the control unit.

Write a program to display Identity matrix?

#include <stdio.h> void main() { int a,b,c,i,j; printf("Enter the number of rows for square matrix : "); scanf("%d",&a); for(i=1;i<=a;i++) { for(c=1,j=1;j<=a;j++,c++) { if(c==i) printf("1 "); else printf("0 "); } printf("\n"); } getch(); }

Assembly language program to check whether the number is even or odd?

;Program to check whether the value in register is even or odd

.ORIG X3000

AND R2,R1,X0001

BRZ EVEN

LEA R0,DEF ;PRINTS ODD IF VALUE IN REGISTER R2 IS 1

PUTS

HALT

EVEN:

LEA R0,ABC ;PRINTS EVEN IF VALUE IN R2 IS 0

PUTS

HALT

ABC .STRINGZ "EVEN"

DEF .STRINGZ "ODD"

.END

What is ASC11?

It is ASCII not ASC11.

American Standard Code for Information Interchange

Sales consultant interview questions?

One question may be about talking on the telephone. You may also be asked about how much you like dealing with others.

How do you print highest number in an array in C language?

#include <iostream>

using std::cout;

using std::cin;

using std::endl;

void input(double arr[], const int arr_size);

double max(double arr[], const int arr_size);

int main()

{

const int arr_size = 5;

double arr[arr_size] = {0.0};

input(arr, arr_size);

cout << "Highest number is: " << max(arr, arr_size) << endl;

system("PAUSE");

return 0;

}

void input(double arr[], const int arr_size)

{

cout << "Enter " << arr_size << " elements to find the highest:" << endl;

for (int i = 0; i < arr_size; i++)

{

cout << (i + 1) << " element is: ";

cin >> arr[i];

}

}

double max(double arr[], const int arr_size)

{

double highest_num = arr[0];

for (int i = 0; i < arr_size; i++)

{

if (highest_num < arr[i])

{

highest_num = arr[i];

}

}

return highest_num;

}

Base Conversion program in c language?

#include void main(void) { char base_digits[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; int converted_number[64]; long int number_to_convert; int next_digit, base, index=0; /* get the number and base */ printf("Enter number and desired base: "); scanf("%ld %i", &number_to_convert, &base); /* convert to the indicated base */ while (number_to_convert != 0) { converted_number[index] = number_to_convert % base; number_to_convert = number_to_convert / base; ++index; } /* now print the result in reverse order */ --index; /* back up to last entry in the array */ printf("\n\nConverted Number = "); for( ; index>=0; index--) /* go backward through array */ { printf("%c", base_digits[converted_number[index]]); } printf("\n"); }

Write a program to use recursive and non-recursive functions to perform linear search operation for a key value in a given set of integers?

/* Write C programs that use both recursive and non recursive functions to perform the following searching operation for a Key value in a given list of integers : i) Linear search */

#include <stdio.h>

#define MAX_LEN 10

void l_search_recursive(int l[],int num,int ele);

void l_search(int l[],int num,int ele);

void read_list(int l[],int num);

void print_list(int l[],int num);

void main()

{

int l[MAX_LEN], num, ele;

int ch;

printf("======================================================");

printf("\n\t\t\tMENU");

printf("\n=====================================================");

printf("\n[1] Linary Search using Recursion method");

printf("\n[2] Linary Search using Non-Recursion method");

printf("\n\nEnter your Choice:");

scanf("%d",&ch);

if(ch<=2 & ch>0) {

printf("Enter the number of elements :");

scanf("%d",&num);

read_list(l,num);

printf("\nElements present in the list are:\n\n");

print_list(l,num);

printf("\n\nElement you want to search:\n\n");

scanf("%d",&ele);

switch(ch) {

case 1:

printf("\n**Recursion method**\n");

l_search_recursive(l,num,ele);

getch();

break;

case 2:

printf("\n**Non-Recursion method**\n");

l_search_nonrecursive(l,num,ele);

getch();

break;

}

}

getch();

}

/*end main*/

/* Non-Recursive method*/

void l_search_nonrecursive(int l[],int num,int ele)

{

int j, f=0;

for(j=0; j<num; j++) if( l[j] ele) {

printf("\nThe element %d is present at position %d in list\n",ele,num);

f=1;

}

else {

if((num==0) && (f==0)) printf("The element %d is not found.",ele);

else l_search(l,num-1,ele);

}

getch();

}

void read_list(int l[],int num) {

int j;

printf("\nEnter the elements:\n");

for(j=0;j<num;j++) scanf("%d",&l[j]);

}

void print_list(int l[],int num) {

int j;

for(j=0;j<num;j++) printf("%d\t",l[j]);

}

(Note: Edited for clarity.)

Wap to sorting the element of the array?

void main()

{

int i,j,temp1,temp2;

int arr[8]={5,3,0,2,12,1,33,2};

int *ptr;

for(i=0;i<7;i++)

{ for(j=0;j<7-i;j++) {

if(*(arr+j)>*(arr+j+1))

{ ptr=arr+j;

temp1=*ptr++;

temp2=*ptr;

*ptr--=temp1;

*ptr=temp2;

clrscr();

for(i=0;i<8;i++)

printf(" %d",arr[i]);

getch(); }

Write a program to store students records in a file?

  1. #include
  2. #include
  3. FILE *fp;
  4. sturct student
  5. {
  6. int a,r;
  7. char n[10];
  8. float p;
  9. }s;
  10. main()
  11. {
  12. int response;
  13. clrscr();
  14. fp=fopen("file1.dat","w+");
  15. while(1)
  16. {
  17. printf("\nInput data from keyboard to write to file\n");
  18. printf("input name ");
  19. scanf("%s",s.n);
  20. printf("\nInput roll no.,age and percentage ");
  21. scanf("%d%d%f",&s.r,&s.a,&s.p);
  22. fprintf(fp,"%s%d%d%f",s.n,s.r,s.a,s.p);
  23. printf("\nAnother record 1:yes, 0:no ");
  24. scanf("%d",&response);
  25. if(response==0)
  26. break;
  27. }
  28. rewind(fp);
  29. printf("\nDate storeed in file is\n");
  30. printf("\nName\tRollNo.Age\tPer.\n");
  31. while(!feof(fp))
  32. {
  33. scanf(fp,"%s%d%d%f",s.n,&s.r,&s.a,&s.p);
  34. printf("\n%s\t%d\t%d\t%f",s.n,s.r,s.a,s.p);
  35. }
  36. fclose(fp);
  37. }

Polynomial multiplication in link list using c language?

#include

#include

struct polynode

{

float coeff;

int exp;

struct polynode *link;

};

void poly_append(struct polynode **,float,int);

void display_poly(struct polynode *);

void poly_multiply(struct polynode *, struct polynode *, struct polynode **);

void padd(float, int, struct polynode **);

main()

{

struct polynode *first, *second, *mult;

int i,coeff,exp,high;

first = second = mult = NULL;

printf("Enter the highest power of polynomial 1: \n");

scanf("%d",&high);

for(i=high;i>0;i--)

{

printf("Enter value for coeff for X^%d : ",i);

scanf("%d",&coeff);

poly_append(&first, coeff,i);

}

printf("\nEnter the highest power of polynomial 2: \n");

scanf("%d",&high);

for(i=high;i>0;i--)

{

printf("Enter value for coeff for X^%d : ",i);

scanf("%d",&coeff);

poly_append(&second, coeff,i);

}

printf("\n\n");

display_poly(&first);

printf("\n");

display_poly(second);

printf("\n");

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

printf("-");

poly_multiply(first, second, &mult);

printf("\n");

display_poly(mult);

}

/* adds a term to a polynomial */

poly_append(struct polynode **q, float x, int y)

{

struct polynode *temp;

temp = *q;

/* create a new node if the list is empty */

if(*q NULL ) )

{

r = malloc ( sizeof ( struct polynode ) );

r -> coeff = c;

r -> exp = e;

r -> link = temp -> link;

temp -> link = r;

return;

}

temp = temp -> link; /* go to next node */

}

r -> link = NULL;

temp -> link = r;

}

}

Write your own printf and scanf functions?

just include #define next to #include

or
/*just follow the pattern below*/ example:






#include
#include
#define pf printf
#define sf scanf
void main
{
int number

pf("Enter a value:");
sf("%i",&number);

getch();
}

Write a c program the extracts and prints the rightmost digit of the integral portion of the float?

#include<stdio.h>

int main (void)

{

float x,y;

int z,w;

printf("enter a number:");

scanf("%6.2f",&x);

y=x/10.0;

z=x-y;

w=z%10;

printf("the rightmost digit is %d\n",w);

return 0;

}//main