Posted by : Arun panthi
Saturday, December 28, 2019
कृपया samedio yadhav यादवद्वारा check गरिने हुँदा यस पुस्तकमा भएका सबै कुराहरु नसार्नु होला। यसमा भएका language portion आफै मिलाएर लेख्नुहोला । यदि यसमा भएको सबै कुरा सार्नुभयो भने तपाइको पनि जिरो मेरो पनि जिरो आउने हुनाले नसार्नु होला। यो केवल तपाईं मलाई सजिलो बनाउनको लागि लेखिएको हो।
- Q.1) list out valid and invalid identifiers? Explain the rules for constructing an identifier?
ANS:
- Three valid identifiers are:_My_name ,Name_23, a1_c3
- Three invalid identifiers are:My-Name-2-3,a1_c3
Identifiers name given to identify something. Dear as some rule for naming identifiers:
1. The first characters of the identifier must be letter of alphabet on underscore.
2. The rest of the identifier name can consist of letters, underscore or digits.
3. Identifier names are case sensitive
Q.2) what is an operator?Explain the automatic rational and assignment of operations in c.
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(<), greater 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.
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<stdio.h>
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<stdio.h>
#include<conio.h>
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:
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.
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(<), greater 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<stdio.h> 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. Ans: variable operators available in c language: 1. C arithmetic operators 2. C increment and decrement operators 3. C assignment operator 4. C rational operators 5. C logical operators 6. C bitwise 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<stdio.h>
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<stdio.h>
#include<conio.h>
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") |
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.11) WAP to calculate prime number till 100.
#include<stdio.h>
Int main()
{
Int i ,Number,count;
Printf(“prime No from 1 to 100 are :\n”);
For(Number=1; Number<==100,Number++)
Count=0;for(i=2; i<==Number/2;i++)
{
If(Number%i==0)
{
Count++;
Break;
}
}
If count==0 &&Number!=1)
{
Printf(“%d”,Number);
}
}
Return 0;
}
multiplication table of 6
ANS:
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. |
#include<stdio.h>
int main()
{
int n,I;
int n,I;
printf(“Enter an integer : ”);
scanf(“%d”,&n);
For(i=1;I<==10;++i)
{
printf(“%d*%d=%d\n”,n,I,n*i)
}
return o;
}
Q.13)What the major difference are between continue and break statement? Write a c program to print all odd number from 5 to 50.
Ans:
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. 8 |
#include <stdio.h>
int main()
{
int i, n;
printf("All odd numbers from 5 to 50 %d are: \n", n)
/* Start loop from 5 and increment it by 1 */
for(i=5; i<=50; i++)
{
/* If 'i' is odd then print it*/
if(i%2!=0)
{
printf("%d\n", i);
}
}
return 0;
}
Q.14)Expain the following with syntax and suitable program.
1: If Else statement:
If Else statement is an extension of simple if statement. It is use when there are only two possible actions.One happen when a test condition is true and the other when it is false.
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”); |
2. Nested if statement:
When one if statement is written with in body of another if statement, it is called nested if statement. The several statement shall be declared as nested if statement.
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”,); } |
Q.15)Explain the following with syntax and suitable program
1. for loop:
For loop allowed to execute block of statement for a number of times.When the number of revtitation is known in advance ,the user of this loop will be more effective .Thus this loop is also known as a determinant or define loop.
Syntax | Example |
For(initialization; condition parameter) { Statement-block; } | #include<stdio.h> #include<conio.h> Int main() { Int i; For(i=1;i <==10;i++ { Printf(%d”,i); } getch(); } |
2. Do while loop:
- Its exit control loop.
-In the do while condition is teasted at the end of the loop.
-In the do while condition is teasted at the end of the loop.
- The do while loop will execute at least on time even if the condition is false initially.
- The do while loop executes untill the condition becomes false.
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
#include<stdio.h>
#include<conio.h>
Int main()
{
Int n;
printf(“Enter a number”);
Scanf(%d”,&n);
If(n%2==0)
printf(“\n\t Number is even”);
Else
printf(“\n\t Number is odd”);
getch();
}
Q.17) Explain the following statement with suitable example.
1. Expression Statement:
Expression statement represent a single data item. The expression may consist of a single entity such as a constant or Variable, or it may consist of some combination of such entitles, interconnected by one or more operations. Example: c=a+b;
2. Compound statement:
Compound statement are typically appears as the body of another statement, such as the if statement. Declarations and types describes the form and meaning of the declaration that can appear at the head of a compound statement.
Q.18)Define Variable .How to declare and initialization a variables? Explain with syntax and suitable program.
Ans:
A variable is a symbolic name which is used to store data item i.e. a numeric quantity or a character constant.
A variable is a symbolic name which is used to store data item i.e. a numeric quantity or a character constant.
All the variable that is use in a program must be declared. Declaration of variable does the things:
1.It tells the compiler what the variable name is.
2.It specifies what type of data the variable will held.
2.It specifies what type of data the variable will held.
Some valid declaration are
·
Inta,b,c;
Inta,b,c;
Char,c,ch;
·
Double d ;
Double d ;
#include<stdio.h>
#include<conio.h>
Void main()
{
Int
a,b,sum;
a,b,sum;
//variable declaration
a=30;
b=20;
sum=a+b;
printf(“sum is=%d”,sum);
getch();
}
Variable declaration can be assigned or initialized using assignment operator”=” .The declaration and initialization can be done in a same line.
Syntax : Variable_name=constant |
#include<stdio.h>
Void main()
{
Int r=2;
float area;
area=3.14*r*r;
printf(“Area of a circle is =%f”,area);
}
Post a Comment