Sunday, 2 December 2007
Preprocessor questions and answer with explanation
Topic 1 Good questions of preprocessorTopic 2 What is preprocessor? Topic 3 Why preprocessor in c programming language? Topic 4 List all preprocessor directives. Topic 5 Explain macro substitution directive?Topic 6 File inclusion directive or #include directive?Topic 8 # and ## operatorTopic 9 #pragmaTopic 10 #pragma inlineTopic 11 #pragma warnTopic 12 #pragma startup and #
Structure questions with answer and explanations in c language
Topic 1 Good questions of structure with explanation
Wednesday, 7 November 2007
Frequently asked questions of c programming with answer
check given number is prime number or not using
check the given number is armstrong number or not
check the given number is palindrome number or not
CHECKING LEAP YEAR
CHECK STRING IS PALINDROME OR NOT
PASSING ONE-DIMENSIONAL ARRAY TO A FUNCTION
CREATE A FILE AND STORE DATA IN IT
TO PASSING 2-DIMENSIONAL ARRAY TO A FUNCTION
WRITING OF STRINGS TO A FILE
Thursday, 13 September 2007
C best coding questions with answer
C best language questions and answer
C coding good questions and answer
C coding good questions and answer
(1) What
will be output of the following code?
#include"stdio.h"
void main(){
char
a='\\';
clrscr();
a=a-'/';
printf("%d",a);
getch();
}
Output: error
Explanation:
Character is \ has special meaning
in c programming. For example:
‘\0’ represents octal character.
‘\n’ represents new line character.
So we cannot use ‘\’ directly.
(2
C good questions and answer
Good questions in c programming language.
(1) What will be output
of the following program?
void main(){
enum data{a,b,c};
clrscr();
printf("%i %i %i",a,b,c);
getch();
}
Output: 0 1 2
Explanation:
By default initial
value of first enum constant is zero. Value of next enum constant
will be:
Next_enum_constant_value=previous_enum_constant_value+1
(2) What will be output
of
good questions of c with answer
Volatile modifier keyword
questions in c programming language:
(q) What will be output of the
following program?
void main()
{
volatile a=5;
a=~a+ ++a;
clrscr();
printf("%d",a);
getch();
}
Output: -1
Explanation:
Volatile variable can be modifying by interrupt or other
process in preprocessor. So in normal output will not affect.
Note. ~ is one’s complement operator
(q) What
Saturday, 1 September 2007
Properties of constructor in c++ with example
(1) Constructor is special type function which must has same name of class name.
(2) Constructor doesn’t return any data type even void
Example:
#include
#include
class school
{
char *name;
int capacity;
public:
void school();
void display()
{
cout<
#include
class math
{
int a;
float b;
public:
math(int p,float q) //constructor should be in
Why constructor in c++
Ans:
Goal of c++ is to create such type of class which is very similar to basic data type like int
char,float etc.
It is possible in basic data type like int,char etc we can initialize the data type at the
time of creation .
Example:
#include
#include
int main()
{
int a=6; //intialization at the time
char b='v'; // of creation
What is printf in c or prototype of printf with example
(q) What is prototype of printf function? Explain each term.
Answer:
Prototype of printf function is:
int printf( const char *format ,…)
Explanation of each term:
Parameter of printf function is:
(1) … (Three continuous dots): It is called ellipsis. It indicates the variable number of arguments.
Example of ellipsis:
void ellipsis(int a,...);
void main()
{
int a=5,b=10;
Tuesday, 28 August 2007
SUM OF ARRAY
PASSWORD VERIFICATION
WAP to print the detail of the programmer
if the given number is 464
void main ()
{
int pass;
clrscr();
do
{
printf ("Enter Password to see the detail of programmer:\n");
scanf ("%d",&pass);
}
while (pass!=464);
printf ("\nJagjeet Singh");
printf ("\nB.Sc. (I.T.)\nPunjab
getch ();
}
PRINT STARS
SKIP 5 & 7
WAP to print series from 1 to 10 and skip 5 & 7
void main ()
{
int a;
clrscr ();
for (a=1;a<=10;a++)
{
if (a==5 || a==7)
continue;
printf ("%d\n",a);
}
getch ();
}
SERIES BREAK ON 5
ENTER & DISPLAY
ASCII CODE - 0 TO 255
void main ()
{
int i=0,count=0;
clrscr ();
for(i=0;i<=255;i++)
{
if (count>24)
{count=0;getch();}
else
{printf("%d=%c\n",i,i);
count++;}
}
getch ();
}
Click on image to enlarge it
STRING LENGTH
FIND STRING
UPPER, LOWER AND REVERSE
void main ()
{
char str [20];
clrscr ();
printf ("Enter your name: ");
gets (str);
printf("\nLength is : %d",strlen(str));
printf("\nUpper is : %s",strupr(str));
printf("\nLower is : %s",strlwr(str));
printf("\nReverese is : %s",strrev(str));
getch ();
}
GOOD ELSE BAD
RECORDS ENTRY
WAP to enter records and also repeat the step if user wants to continue
void main ()
{
char nm [20],cls[10];
int rollno,m1,m2,m3,tm;
float per;
char ch;
clrscr ();
do
{
printf ("\nEnter Marks of Hindi: ");
scanf ("%d",&m1);
printf ("Enter Marks of Pbi : ");
scanf ("%d",&m2);
printf ("Enter Marks of Math : ");
scanf ("%d",&m3);
tm=m1+m2+m3;
per=(tm*100)/300;
printf ("\nTotal Marks are %d",tm);
printf ("\nPercentage is %.2f",per);
printf ("\nDo you want to continue Y/N: ");
fflush(stdin);
scanf ("%c",&ch);
}
while (ch=='y' || ch=='Y');
getch ();
}
GETCH ( ) FUNCTION
MATRIX 2 X 3
WAP to create double dimension array of 2x3 matrix and display its Elements
void main ()
{
int a[2][3],i,j;
clrscr ();
for (i=0;i<2;i++)
{
for (j=0;j<3;j++)
{
printf ("\nEnter element: ");
scanf ("%d",&a[i][j]);
}
}
for (i=0;i<2;i++)
{
for (j=0;j<3;j++)
{
printf ("%d\t",a[i][j]);
}
printf ("\n");
}
getch ();
}
NUMBER OF VOWELS
WAP to count number of vowels
void main ()
{
char s[20],vw=0,i;
clrscr();
printf ("Enter any string: ");
gets (s);
for (i=0;i<=strlen(s);i++)
{
switch (s[i])
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
vw++;
}
}
printf ("There are %d vowels in it",vw);
getch ();
}
CONCATENATE TWO STRINGS
void main ()
{
char *str,*str1;
clrscr ();
printf("Enter your name: ");
gets (str);
str1="jeet";
strcat(str,str1);
printf("\n %s",str);
getch ();
}
SWITCH CASE
WAP to find amount of given quantity of any company with 10% discount using switch case
void main()
{
int,ch qty;
long tb,dis,nb;
clrscr();
printf("1.BPL\n2.Onida\n3.Sony\n4.Samsung\n5.LG\n");
printf("\nEnter Your Choice: ");
fflush(stdin);
scanf("%d",&ch);
printf("Enter Qty: ");
scanf("%d",&qty);
switch(ch)
{
case 1:tb=(long)qty*10000;
printf("\nBPL is %ld",tb);
break;
case 2:tb=(long)qty*12000;
printf("\nOnida is %ld",tb);
break;
case 3:tb=(long)qty*11500;
printf("\nSony is %ld ",tb);
break;
case 4:tb=(long)qty*11000;
printf("\nSamsung is %ld ",tb);
break;
case 5:tb=(long)qty*13000;
printf("\nLG is %ld ",tb);
break;
Default:
printf("Wrong Choice...");
}
dis=(tb*10)/100;
nb=tb-dis;
printf("\nDiscount is %ld",dis);
printf("
\nNet bill is %ld",nb);
getch();
}
SIZE OF VARIABLE
void main()
{
int a;
float b;
double c;
char ch;
long d;
char nm[10];
clrscr();
printf("\nInt size is \t:%d", sizeof (a));
printf("\nFloat size is \t:%d", sizeof (b));
printf("\nDouble size is \t:%d", sizeof (c));
printf("\nChar size is \t:%d", sizeof (ch));
printf("\nLong size is \t:%d", sizeof (d));
printf("\nString size is \t:%d", sizeof (nm));
getch ();
}
FACTORIAL NUMBER
WAP to find the factorial of the number
void main ()
{
int fact=1,no;
clrscr();
printf ("Enter any number: ");
scanf ("%d",&no);
do
{
fact=fact*no;
no--;
}
while (no>0);
printf ("\nFactorial is %d",fact);
getch ();
}
PRINT SERIES (VARIABLE)
PRINT NAME 10 TIMES
PRIME NUMBER
SQUARE & CUBE
WAP to print series from 1 to 10 & find its
void main ()
{
int a=1,sqr=0,cube=0;
clrscr ();
while (a<=10)
{
sqr=pow(a,2);
cube=pow(a,3);
printf ("%d\t %d\t %d\n",a,sqr,cube);
a++;
}
getch ();
}
FABBONIC SERIES
TABLE OF 5
NUMBERS DIVIDED BY 7
ADD ENTERED DIGITS
REVERSE NUMBER
ODD SERIES 20 TO 1
SERIES 20 TO 1
WAP to print series from 20 to 1
#include
void main ()
{
int a;
clrscr ();
a=20;
while (a>=1)
{
printf ("\n%d",a);
a--;
}
getch ();
}
ODD SERIES
void main ()
{
int a;
clrscr ();
a=1;
while (a<=20)
{
if (a%2==1)
printf ("\n%d",a);
a++;
}
getch ();
}
PALANDROM NUMBER
#include
void main ()
{
int no,r,res,temp=0;
clrscr ();
printf ("Enter Number: ");
scanf ("%d",&no);
r=res=0;
temp=no;
while (no>0)
{
r=no%10;
no=no/10;
res=(res*10)+r;
}
if (temp==res)
printf("Number is Palandrom");
else
printf("Number is not Palandrom");
getch ();
}
QUARDRATIC EQUATION
LEAP YEAR
SWAP NUMBERS
INCREMENTAL / DECREMENTAL
POSITIVE / NEGATIVE
EVEN OR ODD
TOTAL SALARY
TOTAL BILL/ DISCOUNT A
WAP to find out Total Bill with discount according to conditions (Ternary Operators)
void main ()
{
int b,dis,n;
clrscr ();
printf ("Enter Bill: ");
scanf ("%d",&b);
dis=(b<500)?(b*.10):(b>=500 && b<1000)?(b*.15):(b>=1000 && b<=2000)?(b*.20):(b*.25);
n=b-dis;
printf ("Net Bill is %d",n);
getch();
}
BIGGER & EQUAL
WAP to find out Bigger & Equal number from three numbers
(Ternary Operators)
void main ()
{
int a,b,c;
clrscr ();
printf ("Enter the value of A: ");
scanf("%d",&a);
printf ("Enter the value of B: ");
scanf ("%d",&b);
printf ("Enter the value of C: ");
scanf ("%d",&c);
(a>b && a>c)?printf("A is Big"):(b>a && b>c)?printf("B is Big"):(a==b && b==c)?printf("All are Eqaul"):printf("C is Big");
getch ();
}