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

Flowchart to find the sum of the square of first 30 even numbers?

The flowchart in deriving the sum of the square root of first N even numbers, You may follow the steps provided below:

# Draw the start symbol then a flow line connecting to item #2 # Draw the init box for the syntax: set variable_A=0, variable_Chk=0, variable_Sum=0, variable_Sqrt, then a flow line connecting to item #3 # Draw the input box and write variable_A then a flow line connecting to item #4 # Draw the decision box for 'Is variable_A not numeric?'. if yes, draw a flow line connecting to item#3 else draw a flow line connecting to item#5 # Draw the process box for the syntax: compute variable_Chk=variable_A / 2 then a flow line connecting to item #6 # Draw the decision box for 'Is variable_chk not whole number?. if yes, draw a flow line connecting to item #3 else draw a flow line connecting to item #7 # Draw the process box for the syntax: compute variable_Sum=variable_Sum + variable_A then a flow line connecting to item #8 # Draw the decision box for 'Do you want to add another number?'. if yes, draw a flow line connecting to item#3 else draw a flow line connecting to item #9 # Draw the process box for the syntax: compute variable_Sqrt=SQRT(variable_Sum) then a flow line connecting to item #10 # Draw the output box and write variable_Sum, variable_Sqrt then a flow line connecting to item #11 # Draw the end symbol.

Where:

variable_A contains a given N number, variable_Chk contains the quotient of variable_A / 2, variable_Sum contains the sum of N numbers and variable_Sqrt contains the result.

How many types of classes in c?

There are no classes in a C program.C is not a object oriented programming language only object oriented programming language has classes c++ is a object oriented programming language.

Class can be defined as a blueprint from which individual objects are created.eg:Car is a Class BMW is an Object of that class.

Join http://www.c-madeeasy.blogspot.com for c programming source codes,tutorials and advanced programming advice.

What is the code for date validation in c plus plus?

You need to check the day, month and year separately, to ensure they are within range. You also need to deal with leap days (29th February) which is every 4 years, but not the 100th unless it is the 400th. Finally, you need to deal with the change from the Julian to Gregorian calendars, which skips the 5th to 14th October, 1582.

bool checkdate(unsigned int d, unsigned int m, unsigned int y)

{

return( !(( d<1 d>31 m<1 m>12 ( y==1582 && m==10 && (d>4 && d<15 )))

( d==31 && ( m==2 m==4 m==6 m==9 m==11 ))

( m==2 && ( d>29 ( d==29 && ( y%4 ( !( y%100 ) && y%400 )))))));

}

What is the difference between Oracle data types char and varchar2?

Character string values storage:

1. CHAR:

§ Stores strings of fixed length.

§ The length parameter s specifies the length of the strings.

§ If the string has smaller length it padded with space at the end

§ It will waste of a lot of disk space.

§ If the string has bigger length it truncated to the scale number of the string.

2. VARCHAR:

§ Stores strings of variable length.

§ The length parameter specifies the maximum length of the strings

§ It stores up to 2000 bytes of characters

§ It will occupy space for NULL values

§ The total length for strings is defined when database was created.

3. VARCHAR(2):

§ Stores strings of variable length.

§ The length parameter specifies the maximum length of the strings

§ It stores up to 4000 bytes of characters

§ It will not occupy space for NULL values

§ The total length of strings is defined when strings are given

Is array made up of number of data items?

Yes, that's the idea of an array.

Yes, that's the idea of an array.

Yes, that's the idea of an array.

Yes, that's the idea of an array.

How can you pause or break a C plus plus program running in DOS-BOX?

There is no pause function as such, but you can easily roll your own:

#include <iostream>

#include <limits>

void Pause()

{

std::cout << "Press ENTER to continue...";

std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );

}

int main()

{

Pause();

return( 0 );

}

What is c program of roman numbers?

There being only 7 symbols to consider (IVXLCDM), conversion is easily achieved in any number of ways. In general, numerals are formed from left to right, largest value to smallest. However, if a smaller value precedes a larger value, the smaller value is subtracted from the larger value (or is negated). This can lead to problems such as IVX. Reading left to right this would become 10 - ( 5 - 1 ) = 10 - 4 = 6. There's nothing wrong with this, but most people would accept 6 = VI, not IVX.

The problem is there has never been an official standard relating to how Roman numerals are formed. Decimal 1999 could be represented as MCMXCIX or MIM or MDCCCCLXXXXVIIII or even a mixed format like MCMXCVIIII. All are intrinsically correct. However, only the first example conforms to what many would consider to be the "unofficial" standard, whereby certain combinations are no longer permitted (such as IIII, IM and VX).

This standard has been incorporated into the following code.

#include <iostream>

using namespace std;

int main()

{

char roman[11];

int decimal[10];

memset( roman, 0, 11 );

memset( decimal, 0, 10 * sizeof( int ));

cout << endl;

cout << "Enter a Roman number (max. 10 chars from I, V, X, L, C, D or M): ";

cin.getline( roman, 11, '\n' );

strupr( roman ); // convert to uppercase for consistency

// check validity, including all invalid combinations

if( !strlen( roman )

( strspn( roman, "IVXLCDM") != strlen( roman ))

( strstr( roman, "IIII" ))

( strstr( roman, "XXXX" ))

( strstr( roman, "CCCC" ))

( strstr( roman, "MMMM"))

( strstr( roman, "IL" ))

( strstr( roman, "IC" ))

( strstr( roman, "ID" ))

( strstr( roman, "IM" ))

( strstr( roman, "XD" ))

( strstr( roman, "XM" ))

( strstr( roman, "VX" ))

( strstr( roman, "VL" ))

( strstr( roman, "VC" ))

( strstr( roman, "VD" ))

( strstr( roman, "VM" ))

( strstr( roman, "LC" ))

( strstr( roman, "LD" ))

( strstr( roman, "LM" ))

( strstr( roman, "DM" ))

( strstr( roman, "IIV" ))

( strstr( roman, "IIX" ))

( strstr( roman, "XXL" ))

( strstr( roman, "XXC" ))

( strstr( roman, "CCD" ))

( strstr( roman, "CCM" )))

{

cout << roman << " is not a valid roman number." << endl;

return( -1 );

}

// convert to decimal, in reverse order.

int c = 9, total = 0;

while( c >= 0 )

{

switch( roman[c] )

{

case('I'): decimal[c] = 1; break;

case('V'): decimal[c] = 5; break;

case('X'): decimal[c] = 10; break;

case('L'): decimal[c] = 50; break;

case('C'): decimal[c] = 100; break;

case('D'): decimal[c] = 500; break;

case('M'): decimal[c] = 1000; break;

}

if( c < 9 ) // subtraction required?

if( decimal[c] < decimal[c+1] )

decimal[c] *= (-1); // negate

// update total.

total += decimal[c--];

}

cout << "Roman " << roman << " is decimal " << total << endl;

return( 0 );

}

What do you mean by operator precedence and associativity?

Calculate y in the following equation: y = 2 + 3 x 4 What answer did you get? Did you get 20? If you did, you messed up. You should have gotten 14. If you got 20, you did the operations in the order in which they appear, from left to right, which is a mistake. You added 2 and 3, to get 5, and then you multiplied by 4, to get 20. But you should have multiplied 3 by 4, first, to get 12, and added that product to 2, to get 14. That's because multiplication (and division) take precedent over addition (and subtraction). Now, try this: y = (2 + 3) x 4 Did you get 20? If so, you got the right answer. Do you know why?

Prime number program in C using recursion?

//Program to check number is prime or not using recursive function

#include<stdio.h>

#include<stdlib.h>

void prime(int num,int count)

{

if(count<num)

{

if(num%count==0)

{

printf("%d is not Prime Number\n",num);

goto exit;

}

count += 1;

if(count<num)

{

prime(num,count);

}

}

if(num==count)

{

printf("%d is a Prime Number\n",num);

}

exit:

return 0;

}

int main()

{

system("cls");

int gvar;

printf("Enter the number = ");

scanf("%d",&gvar);

prime(gvar,2);

printf("\nashokakhil@gmail.com\n");

system("PAUSE");

return 0;

}

I think this can be another solution

#include<stdio.h>

#include<conio.h>

int prime(int);

main()

{

int i=1,r;

clrscr();

r=prime(i);

if(r==1)

printf("\n\n\tNo is prime ");

getch();

}

int prime(int i)

{

int n=1,ans,flag=1;

i++;

ans=n%i;

if(ans==0)

{

printf("\t\t\n\nNo is not prime");

flag=0;

return flag;

}

if((i!=n-1)&&(n!=1))

flag=prime(i);

return flag;

}

Write a program that input a positive integer and prints a triangle using for loop?

write a program that reads in the size of the side of square and then pints a hollow square of that size out of asterisks and blanks?

What is the difference between for if-then and for loop?

a for loop is defined with an boolean expression to indicate when it should terminate. A for each loop iterates once for each item in a collection.

for example, "for each (book in bookshelf)" will iterate once for each book on the bookshelf, providing access to the current book.

a for loop is defined like "for (int i = 0; i<10;i++)" meaning the loop will iterate as long as the condition is true (i < 10), and will increment on each loop.

Note: there is no 'for each' loop in C language, but there is a 'foreach' in PHP.

How is a structure initialized?

In C, structures are uninitialized by default. To initialize a structure you will typically zero the memory allocated to the structure and then set specific members to specific values. If all members are non-zero, you can simply set those members rather than zero the memory first.

In C++, structures are initialized via inline initializes and/or through the class constructor.

Wap for swapping values of two variables using pointers as arguments to functions?

# include<stdio.h>

# include<conio.h>

void main()

{

clrscr();

int a,b;

printf ("Enter the first value:");

scanf ("%d",& a );

printf ("Enter the second value:");

scanf ("%d",& b );

printf ("\n\nBefor swaping the values ");

printf ("\nThe first value is %d",a);

printf ("\nThe second value is %d",b);

printf ("\n\nAfter swaping the values ");

printf ("\nThe first value is %d",b);

printf ("\nThe second value is %d",a);

}

Writ a program in c to display day of the week using in switch case?

/* write a program to print Days of Week using switch-case structure */

#include<stdio.h>

#include<conio.h>

void main()

{

int n;

clrscr();

printf("\n Enter Day of weak as Number 1 to 7 ");

scanf("%d",&n);

switch(n)

{

case 1:

printf("\n MONDAY ");

case 2:

printf("\n TUESDAY");

case 3:

printf("\n WEDNESDAY");

case 4:

printf("\n THURSDAY");

case 5:

printf("\n FRIDAY");

case 6:

printf("\n SATURDAY");

case 7:

printf("\n SUNDAY");

default :

printf("\n no operation is required");

}

getch();

}

Definition of loop and its types and programs in c plus plus?



Executing a segment of a program repeatedly by introducing a counter and later testing it using the if statement.

A sequence of statements are executed until some conditions for termination of the loop are satisfied.

A Program loop consists of two segments:
1.Body of the loop
2. Control Statement


Depending on the position of the control statement in the loop, a control strcture may be classifies either as the 2:

  1. Entry Controlled Loop
  2. Exit Controlled Loop
1.Entry Control Loop-(Pre Test Loop)
The control conditions are tested before the start of the loop execution.
If the conditions are not satisfied , then the body of the loop will not be executed.]
eg:
While Loop

2.Exit Control Loop-(Post Test loop)
The Test is performed at the end of the body of the loop and there fore the body is executed unconditionally for the first time.
eg:
Do-While



while loop
for loop
do-while loop

Is c is regular language?

it is not regular language .it is high level language

How do you install c language in win 7?

How to download and install Turbo C++ in Windows 7....

1.Download dosbox 0.74 from dosbox.com and save in E: drive(say).

2.Download Turbo C++ 3.0.

3.Create a folder Turbo in E: drive & save all contents of Turbo C++ 3.0.

4.Open dosbox.

5.Type as follows:-

mount e e:\ <Press enter>

e: <Press enter>

cd turbo <Press enter>

install install <Press enter>

6.Proceed as per requirements.

7.A folder TC appears in E: drive.

8.To repeat the point 5. commands whenever you open the dosbox, go to E:\Dosbox-0.74\Dosbox-0.74 Options

9.Scroll down to the end of the page and write as follows:-

mount E E:\

E:

CD TC

CD BIN

TC.EXE

10.Now open dosbox by clicking its icon on desktop and find to open Turbo C++ directly, but in a small dialob box.

Why 3rd generation language is a level language?

•Much more portable than low level languages (can be transferred over different computers) •Many tutorials and manual for the languages

•Many prewritten and tested algorithms made (no need to "reinvent the wheel")

•Excellent for general purpose programming

Which command is used to skip the rest of a loop and carry on from the top of the loop again?

From inside any loop statement, the continue; statement will skip any remaining statements and re-evaluate the loop's conditional expression. If that expression remains true, a new iteration of the loop begins, otherwise control passes to the statement that follows the loop. Note that in a for or while loop, the conditional expression is defined before the loop body but in a do loop it is defined after the loop body.

What significance is attached to the name main?

main refers to the entry point of an application. All programs must have a main() function that returns an integer to the calling program or script. The return value can be used for any purpose, but generally a non-zero negative value is used to indicate that an error occurred (zero meaning no error).

Why high level language is slower then assembly language?

Programs written in a high level language might be slower than ones written in Assembly language; but it is not always so, it is very easy to write un-effective programs in Assembly.

What is the return value of getch?

getch(); is used for unbuffered input. e.x:

int main()

{

char num=0;

printf("Press a keyboard button: ");

num = getch(); //This brings in 1 character that the user pressed on the keyboard

printf("\nYou pressed: %c", num); //This prints the character you pressed

getchar(); // I am using getchar(); to stop the program from ending after pressing buttons

return 0;

}

My input will be within the ().

output:

Press a keyboard button: (v)

You pressed: v

EOP //End of program

I hope this has helped you!

Can the program counter be eliminated by using the top of the stack as a program count?

No. The program counter must be stored in a dedicated register. The stack is in working memory and you cannot operate on working memory; all values must be moved into a register in order to operate upon them. It makes no sense to move a program counter in and out of memory unless performing a context switch and you can't use a stack for context switching; a priority queue must be used for this. Keep in mind that the address of the top of the stack has to be moved in and out of its register during a context switch. It doesn't make sense to load the stack register from a priority queue before you can determine where the program counter value is. It's easier to keep all state information in the same place in the priority queue where it belongs.