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

How do you sort the name alphabetically in c or c plus plus?

#include

#include

// prints a 2d array of strings

void print2d(const std::string* arr, const size_t rows, const size_t cols)

{

for(size_t row=0; row

{

for(size_t col=0; col

{

std::cout<

}

std::cout<

arr+=cols;

}

}

int main()

{

// example 2d array

const size_t rows = 10;

const size_t cols = 2;

std::string names[rows][cols] = {

"John", "Wayne",

"Johnny", "Depp",

"Michael", "Douglas",

"Anthony", "Hopkins",

"Kirk", "Douglas",

"Daniel", "Craig",

"Tom", "Hanks",

"Sean", "Connery",

"Sean", "Bean",

"Adam", "Baldwin"

};

std::cout<<"\nUnsorted:\n"<

print2d( names[0], rows, cols );

std::cout<

// Sorting algorithm: uses insertion sort

for(size_t row=1; row

{

// copy the current name

std::string copy[2];

copy[0] = names[row][0];

copy[1] = names[row][1];

// store the gap row

size_t gap=row;

// store the compare row (always the row above the gap row)

size_t cmp=gap-1;

// repeat while the gap row is non-zero and the copy name

// is less than the compare name (comparing surname first)

while(gap && (copy[1]

{

// move the compare name into the gap

names[gap][0]=names[cmp][0];

names[gap][1]=names[cmp][1];

// move the gap up one row

--gap;

--cmp;

}

// insert the copy into the gap row

names[gap][0]=copy[0];

names[gap][1]=copy[1];

}

std::cout<<"\nSorted:\n"<

print2d( names[0], rows, cols );

std::cout<

}

Output

Unsorted:

John Wayne

Johnny Depp

Michael Douglas

Anthony Hopkins

Kirk Douglas

Daniel Craig

Tom Hanks

Sean Connery

Sean Bean

Adam Baldwin

Sorted:

Adam Baldwin

Sean Bean

Sean Connery

Daniel Craig

Johnny Depp

Kirk Douglas

Michael Douglas

Tom Hanks

Anthony Hopkins

John Wayne

C program to find salary and bonus of employee?

#include<stdio.h>

#include<conio.h>

#include<math.h>

void main()

{

int salary, bonus;

clrscr();

printf("enter the salary and=");

scanf("%d",&bonus);

if(salary==bonus)

{

salary=salary+bonus;

}

printf("\ncalculate bonus=%d", salary);

getch();

}

Explain the modulo division operator in C?

Division is what you expect it to be, the division of two numbers with the result placed somewhere.

Modulus, on the other hand, is the remainder of integer division of two numbers with the result placed somewhere. The modulus function of a and b, a being the dividend and b being the divisor, is a - int(a/b) * b.

For example, using integer results...

47/4 = 11

47%4 = 3

Check it: 47 = 11*4 + 3

Write a C program to convert decimal number into binary number?

#include<iostream>

using namespace std;

int revDigit(int n){

int r,s=0;

while(n>0){

r=n%10;

n=n/10;

s=(s*10)+r;

}

return s;

}

main(){

long n,r,r1,s=0,s1=10;

cout<<"Enter a number."<<endl;

cin>>n;

while(n>0){

r=n%2;

n=n/2;

s=(s*10)+r;

}

//since we read the binary equivalent in a bottom up manner, we need to reverse it.

s1=revDigit(s);

cout<<"Binary equivalent:\t"<<s1<<endl;

system("pause");//this line is required if you are using dev c++

}

What is simulation recursion in C?

The factorial f(n) = n * (n-1) * (n-2) * .. 1. For example factorial 5 (written as 5!) = 5 x 4 x 3 x 2 x 1 = 120. The function below returns the factorial of the parameter n. int factorial( int n) {

if (n==1)

return 1

else

return n* factorial( n-1) ;

}

What is the job title of a person who writes and test computer programs?

The person who writes a computer program is called a programmer.

Programmers also typically handle some part of testing, the so-called unit test. Unit testing involves testing a small unit of code in relative isolation, and not necessarily as part of a complete and much larger system.

The person who designs the computer program and its chief principles and algorithms is called a software designer or software architect.

The general term for programmers and architects is software engineer.

The person testing a whole program, within the complete infrastructure, with different operating system versions or user languages, use-cases and whichever other important variation the program is expected to handle, is called a software test engineer or system test engineer.

In larger organizations, one (or more) people are responsible for each of these roles. In smaller organizations, programmer and architect are often the same person, but it is always preferable to have different person design and execute the system testing. In very small organizations, a single person may have to handle all these tasks.

What are subscripts in c language?

Subscripts are used when accessing arrays. An array is a contiguous block of memory containing two or more elements of the same type. Since each element is the same length, it is trivial to work out the offset address of one element relative to another using a zero-based index. For any type T, the type T[n] is an array of Ts with indices in the range 0 to n-1. We can also create arrays at runtime by allocating sufficient memory on the heap for the given type:

void f(int n) {

if (n<1) return; // cannot allocate 0 elements!

int* ptr = malloc (n * sizeof(int)); // allocate memory for n integers

if (ptr!=0) return; // ensure memory was allocated!

ptr[0] = 42; // use subscript operator to assign a value to the first element

// assign to other elements...

// use array...

free (ptr); // release memory as soon as we're finished with it

}

When loops are nested does one loop have to end before the other begins?

If one loop ends before the next begins then they are not nested at all -- they are completely independent. To be nested, one loop must contain the other loop in its entirety. That is, the inner, nested loop must start and end within the outer, containing loop.

Nested loop example (in C++):

for( int x = 0; x < 10; ++x ) // outer loop

{

for( int y = 0; y < 10; ++y ) // inner loop (nested loop)

{

printf( "%d x %d = %d\r\n", x, y, x*y );

} // end of inner loop

} // end of outer loop

Write a program to calculate GPA in C plus plus?

#include

#include

using namespace std;

int main ()

{

cout << endl << "Please enter all the grades you wish to use for your GPA." << endl;

cout << endl << "When you have finished, enter N to indicate that you have no more grades." << endl;

cout << endl << "The highest acceptable grade is 100%, if you got higher than this congratulations but please enter only 100 as grade." << endl;

cout << endl;

float Grade = 0;

int NumClass = 0;

const int Stop = -1;

float GPAVal = 0;

float TotGPAVal = 0;

float GPA = 0;

string SemName;

while (SemName != -1)

{

cout << "Please enter name of the semester of grades you want to enter." << endl;

cin >> SemName;

cout << SemName << endl;

do {

cout << endl << "Please enter grade: ";

cin >> Grade;

if ( Grade <=100 && Grade >= 90 )

{

GPAVal = 4.0;

cout << "Grade: " << Grade << "%; GPA Value: 4.0" << endl;

TotGPAVal = TotGPAVal + GPAVal;

}

else if ( Grade < 90 && Grade >= 80 )

{

GPAVal = 3.0;

cout << "Grade: " << Grade << "%; GPA Value: 3.0" << endl;

TotGPAVal = TotGPAVal + GPAVal;

}

else if ( Grade < 80 && Grade >= 70 )

{

GPAVal = 2.0;

cout << "Grade: " << Grade << "%; GPA Value: 2.0" << endl;

TotGPAVal = TotGPAVal + GPAVal;

}

else if ( Grade < 70 && Grade >= 60 )

{

GPAVal = 1.0;

cout << "Grade: " << Grade << "%; GPA Value: 1.0" << endl;

TotGPAVal = TotGPAVal + GPAVal;

}

else if ( Grade < 60 && Grade >= 0 )

{

GPAVal = 0.0;

cout << "Grade: " << Grade << "%; GPA Value: 0.0" << endl;

TotGPAVal = TotGPAVal + GPAVal;

}

else if ( Grade = Stop )

{

GPA = (TotGPAVal / NumClass);

cout << endl<< "Your overall GPA, after " << NumClass << " courses, is " << GPA << "." << endl << endl;

}

NumClass = NumClass + 1;

}

while (( Grade >= 0 ) && ( Grade <=100 ));

if (SemName = -1)

{

cout << "Thank you for using this program!" << endl;

}

}

return (0);

}

What is the purpose of the state array in AES?

Sub byte uses an S-box to perform a byte-by-byte substitution of the block. The left most 4 bits of the byte are used as row value and the rightmost 4 bits are used as a column value. These row and column values serve as indexes into the S-box to select a unique 8-bit value.

Write a program to overload preincrement and postincrement operator?

#include<iostream.h>

#include<conio.h>

class num

{

private:

int a,b,c,d;

publ;ic:

num(int j,int k,int m,int l)

{

a=j;

b=k;

c=m;

d=l;

}

void show(void);

void operator++();

};

void num::show()

{

cout<<...................................................................

}

void num::operator++()

{++a;++b;++c;++d;

}

main()

{

clrscr();

num X(3,2,5,7);

cout<<"b4 inc of x";

X.show();

++X;

cout<<"after inc of x";

X.show();

return 0;

}

Banking operations in c programm?

here is c code for banking system....

#include <stdio.h>

#include <stdlib.h>

#include <conio.h>

#include <dos.h>

#include<string.h>

#include <graphics.h>

#define LEN 100

/*====================================================================*/

What is a header file and library function?

header files are predefined in c, they include the all necessary function to u to do your work easy instead of writing a function for printing a message or to read a input form key board we are using the library functions which are in the header files.

there are different types of header files depending upon the requirement we use them.

Write a Program for ascending order in 8085 microprocessor?

Source program :

  • MVI D, COUNT : Initialize counter
  • MVI B, 00 : Initialize variable to store previous number
  • MVI C, 01 : Initialize variable to store current number
  • MOV A, B :[Add two numbers]
  • BACK: ADD C :[Add two numbers]
  • MOV B, C : Current number is now previous number
  • MOV C, A : Save result as a new current number
  • DCR D : Decrement count
  • JNZ BACK : if count 0 go to BACK
  • HLT : Stop.

Who invented c sharp programming?

It wasn't really invented. It was designed by some Microsoft division, based on best in area tendencies to the point of time. A lot of concepts was taken directly from Java programming language.

What you mean by row major and column major?

its the method for sorting the multidimensional array.

eg:

consider the matrix: 10 1 3

2 7 5

8 6 4

row-major order: 1 3 10

2 5 7

4 6 8

column major order: 2 1 3

8 6 4

10 7 5

C program convert hours to minutes?

#include <stdlib.h>

#include <stdio.h>

int hoursToMinutes( int hours ){ return 60 * hours; }

int main(int argc, char *argv){

if(argc != 2)

return 1;

printf("%i\n", hoursToMinutes(atoi(argv[1])));

return 0;

}

When a language has the capability to produce new data type is also called?

New, compared to what? I guess you meant user-defined data-types, which exist in almost every modern programming language.

Write a c program to print multiplication table using while loop?

void main()

{

int a,b,c,d;

clrscr();

printf("\n Enter the number for table = ");

scanf("%d",&a);

printf("\n Enter the number up to which you want to see the table = ");

scanf("%d",&b);

for(c=1;c<=b;c++)

{

d=a*c;

printf("%d * %d = %d\n", a,c,d);

}

getch();

}

Which programming language uses a string of 1s and 0s?

You, as a programmer, can use a string with 1s and and 0s (or any other content) in each and every programming language.

Where are trees in data structures implemented in the real world?

First off, there are several types of trees in data structures. each with different uses and benefits. The two most common are binary trees and binomial trees.

Binary trees are used most commonly in search algorithms. The benefits of this is that a search can be performed in O(lg(n)) time, instead of the O(n) time that a sequential search takes. An example from the real world of a binary tree in action is in databases, where indexes are organized in a binary tree, thus enabling faster searching.

Binomial trees are usually used in communication, particularly when distributing or aggregating information. A real world example comes from supercomputers, where multiple processors are all working simultaneously. In order to aggregate or distribute data, a binomial tree structure is commonly employed.

Using conditional operator find a biggest number among two numbers?

Here is an example in Java: int a = 5; int b = 7; System.out.println(a > b ? a : b);

Here is an example in Java: int a = 5; int b = 7; System.out.println(a > b ? a : b);

Here is an example in Java: int a = 5; int b = 7; System.out.println(a > b ? a : b);

Here is an example in Java: int a = 5; int b = 7; System.out.println(a > b ? a : b);

What do mean by structural programming?

Structured programming is a programming paradigm. Prior to structured programming, code was typically written with intertwining jumps or gotos producing "spaghetti" code which is difficult to both read and maintain. Structured programming primarily added subroutines and loop control statements and was later extended by procedural programming which primarily added function calls (not to be confused with functional programming) and which also made exception handling that much easier to maintain. This then led to object-oriented programming.