Assignment 2 C Language
Assignment 2 C Language
4. Putch -
This function is used to print one character ,on the screen
This Function also print One Character as an input
Syntax-putch(variable_name);
5. Getche –
This function is used to Accept one character , from keyboard ,echo to the screen
This Function also takes One Character as an input
Syntax-character_var = getche();
9. What is the difference between unary and binary and ternary operator?
Unary- works on one operand.
Binary- works on two operands.
Ternary- works on three operands.
10. What is operator in C and what are the difference types of operator in C?
Operator is symbol which operates on a value or a variable.
Operator allow to perform diff kinds of operations on operands.
Different types of operator is as follows-
1. Arithmetic operator
2. Increment decrement operator
3. Assignment operator
4. Relational operator
5. Logical operator
6. Conditional operator
7. Bitwise operator
8. Special operator
11. What is the difference between single equal "=" and double equal "=="operators in
C?
Single equal “=” is assignment operator used to assign value to operator
Double equal “==” is relational operator used to compare two variable or
constants
12. What is the difference between pre decrement operator and post decrement operator?
Pre decrement operator is used to decrement variable value by 1 before assigning
the value to the variable. Post decrement operator is used to decrement variable
value by 1 after assigning the value to the variable.
13. How much bytes of space does integer , float data type take in memory?
integer - 4 bytes
character - 1 byte
float - 4 bytes
double - 8 bytes
long double - 16 bytes
Lab: 2
1. Write a C program to convert specified days into years, weeks and days. Note: Ignore leap
year. Test Data : Number of days : 1329 Expected Output : Years: 3 Weeks: 33 Days:
3
#include <stdio.h>
int main()
{
int days,weeks,years;
printf("Number of days: ");
scanf("%d",&days);
years = days/365;
weeks = (days % 365)/7;
days = days- ((years*365) + (weeks*7));
printf("Years: %d\n", years);
printf("Weeks: %d\n", weeks);
printf("Days: %d \n", days);
return 0;
}
5. Accept principal amount, rate of interest, and duration from the user. Display Interest
Amount and Total Amount (Principal + Interest).
#include <stdio.h>
int main()
{
float principle, rate, interest,Total_Amount;
int time;