- Q.1) list out valid and invalid identifiers? Explain the rules for constructing an identifier?
- Three valid identifiers are:_My_name ,Name_23, a1_c3
- Three invalid identifiers are:My-Name-2-3,a1_c3
ANS: An operator is a symbol that the tells the compiler to perform certain mathematical or logical manipulation.Operators used in program to manipulate data and variable.
* The arithmetic operators of the c programming operators which are used to perform automatic operations include operators like addition, subtraction, multiplication, division, and modulus. All these automatic operators in c are binary operators which means they operate and two operands.
*) Relational operators are used to find the relation between two variables i.e to compare the value of two variables in c program. Relational operators are binary operators because they require two operands to operate. If the relation is true the result of the rational expression is 1,if the relation is false the result of the rational expression is 0.greater than(>), greater than or equal to (>=), small then(), not equal to (!=) are relational operators.
*) Assignment operators are used to assigning value to a variable. The light of operand of the assignment operator is a variable and rightside operand of the assignment operators is value. The value of the rightside must be of the same data type of the variable on the left side otherwise compiler will raise error. Equal to (=),”+=”,”-=” “*=” are assignment operators.
Q.3) Explain enumerated data type suitable program.
Ans: Enumerated data type is user defined data type use in c programming to map a set of name to numeric values.Enumerated data type variable can only have value that previously declared. In order word they work with a finite list of value.Enumerated data types make the code more self-documenting and prevent programmers from writing illogical code on a value of enumerateors.Enumerated data type also hide unnecessary details from programmers.
#include enum week{Mon, Tue, Wed, Thur, Fri, Sat, Sun}; int main() { enum
week day; day = Wed; printf("%d",day); return 0;} Q.4) list of variable operators available in c language. How to to use assignment operator in c program? Clarify example.
2. C increment and decrement operators
3. C assignment operator 4. C rational operators 5. C logical operators 6. C bitwise operators |
Assignment operators is is used to assign value to an variable. Assignment operators is denoted by equal to sign. Different ways of using assignment operators.
1. Assignment operator used to assign value:
int main()
{
int value
Value=65
return (0);
}
In the above example we have assigned
2. Assignment operator used to type cast.
int value
value=55.450
printf(“%d”,value);
Assignment operators can type cast higher value to lower value.It can also lower values to higher values.
3. Assignment operators in if statement:
if (value=10)
printf(“true”);
else
printf(“false”);
Above program will always execute true condition because assignment operators is used inside if statement not comparison operators.
Q.5) difference between key words and identifier with suitable program.
Ans:
1)Keywords are the reserved word of a language. Where as identifier user defined name of variable, function and labels.
2) keyboard only consider letter where is identifier consider letter,underscore ,digits.
3) keyword only use lowercase where is identifier used lowercase as well as uppercase.
Q.6) Define symbolic constant. Write a c program to find area and perimeter of circle.
Ans: symbolic constant that substitute for a sequence of characters that can’t be changed. The character may represent a numeric constant, spring constant, character constant
#include
int main()
{
int rad;
float PI=3.14,area,ci;
printf(“\nEnter radius of circle: “); scanf(“%d”,&rad);
area = PI * rad * rad;
printf(“\nArea of circle : %f “,area);
ci =2*PI* rad;
printf(“\nCircumference : %f “,ci); return(0);
}
Q.7) The price of 1 kg of potato is Rs 16.75 in 1 kg onion is 15. Write a c program get this value from the user and display the sum of prices
#include
#include
int main()
{
Float potato, onion, sum;
printf(“Enter price of 1 kg potato and onion :”);
scanf(“%f%f”,& potato,&onion);
Sum=potato +onion;
printf(“Sum of price of 1 kg onion and potato =%f”,sum);
getch();
}
Q.8) what are formatted and unformatted input/output function. Differentiation between putchar() and puts() with example.
Ans: Formatted console input /output function are used to one or more input from user it console and it also allows us to display one or multiple values in the user at the console.
Unformatted console input/output functions are used to read a single input from the user at console and it allows us to display the value in the output to the user at the console.
Different between:
|
Putchar()
|
Puts()
|
|
putchar()are single
character function |
Puts()are string function i8s
|
|
putchar() prints a character to the
screen. |
puts() write s a string on
the screen and advance the course to the newline |
|
Example:putchar(b);
|
Example:put(“one”)
|
Q.9)What are formatted and unformatted input function.
Ans:Formatted input refers to an input data that has been arranged in a particular format.
Unformatted input function used to read the input from the keyboard by the user accessing the console. This input value could be of any primitive data type or an error type.
Q.10)what are formated and unformated output function? Write the difference between gets() and getchar() with example.
Ans: Formatted output function are used to display a store datatype in a particular specified format.
Unformated output function:Unformate output function used to display the output to the user at the console. These output values could be of only primitive data type or on an array type.
|
gets()
|
getchar()
|
|
1. gets() read
stdin until an end of line or end of file is reached. |
1.getchar() read a
single character from stdin. |
|
2. The gets()
function reads a string from through keyboard and stores it in character array. |
2.The getchar()
function read the input fom the user and display back to user. |
|
3.char*gets(char*str)
|
3.int getch(void);
|
Q.12) Distinguish between While and Do while loop. Write a c program to display the
|
While
|
Do while
|
|
1.while is a entire control loop.
|
1. Do while loop is a exit control
loop. |
|
2.In while loop condition is
checked before entering to the loop. |
2. In the do while loop condition is
tasted at the end of the loop. |
int n,I;
|
Continue statement
|
Break statement
|
|
1. Continue statement cause the next
iteration of the enclosing for, while or do loop to begain. |
1. Break statement cause the innermost
enclosing loop or switch to be exited immediately. |
|
2.A break statement can apper in boths
with and loop statement. |
2.A continuous statement only appear
in loop statement. |
|
syntax
|
Example:
|
|
If(test_expression)
{
True_block statement (s);
}
Else
{
False-block statement (s);
}
|
char ch;
ch=getch();
If ch==’m’
printf(“\n you are male”);
else
printf(“\n you are female”);
|
|
syntax
|
Example
|
|
If (expression)
{
If(expression)
{
//body
}
}
|
char chl ;
Int age=20;
chl=getch ();
If (chl)==’m’;
{
If(age>13)
printf(“\n Arun panthi is
an young man”,); }
|
|
Syntax
|
Example
|
|
For(initialization; condition parameter)
{
Statement-block;
}
|
#include
#include
Int main()
{
Int i;
For(i=1;i <==10;i++
{
Printf(%d”,i);
}
getch();
}
|
–In the do while condition is teasted at the end of the loop.
|
syntax
|
Example
|
|
|
Do{
Statement/s;
}
While(condition);
|
Int main()
{
Int i=1;
Do{
While( i<==5);
getch();
}
|
|
Q.16) write a program to determine the weather the given program is even or odd
Q.17) Explain the following statement with suitable example.
A variable is a symbolic name which is used to store data item i.e. a numeric quantity or a character constant.
2.It specifies what type of data the variable will held.
Inta,b,c;
Double d ;
a,b,sum;
|
Syntax :
Variable_name=constant
|