Professional Documents
Culture Documents
22ec260 - Ex 1-c Basics
22ec260 - Ex 1-c Basics
Introduction to C programming
Exp:No:1
Aim :
To learn about the Data-types, variables and keywords in C - programming
int main(void)
{
printf("---------------------------------------------------------------------- \n");
printf("--------------------------Hello, World!------------------------------- \n");
printf("---------------------------------------------------------------------- \n");
printf("-----------------Welcome to the World of Programming------------------- \n");
printf("---------------------------------------------------------------------- \n");
getch();
return 0;
}
Write the output of the given problem. Remove \n and check the output.
2. Write a program to print the number of bytes occupied by different data types
#include <stdio.h>
int main()
{
Int i;
float f;
double d;
char c;
short int si;
long double ld;
Self-evaluation questions:
1. What is the use of sizeof() function.
2. Explain why are we using %d in the printf function.
3. Find out the size of
short int
long int
long long int
long double
3. Write a program to illustrate use of different Input, output statements. ( scanf(), printf(), getchar(),
getche(), getch(), gets(), putchar(), puts() )
#include <stdio.h>
#include <conio.h>
int main( )
{
char ch, str[15];
printf ( "\nPress any key to continue " ) ;
getch( ) ; /* will not echo the character */
printf ( "\nType any character " ) ;
ch = getche( ) ; /* will echo the character typed */
printf ( "\nType any character " ) ;
ch = getchar( ) ; /* will echo character, must be followed by enter key */
printf("\nprinting character....");
putchar(ch); //printing a character value
fflush(stdin);
Sample output:
Press any key to continue
Type any character a
Type any character b
printing character....b
Enter your name asmi
printing name....asmi
Continue Y/N n
#include <stdio.h>
int main()
{
// Computes quotient
quotient = dividend/divisor;
// Computes remainder
remainder = dividend%divisor; // % operator gives the remainder after division
printf("Quotient = %d \n",quotient);
printf("Remainder = %d \n",remainder);
return 0;
}
a. Use following Test case i/P and print the quotient and remainder
(i)dividend = 25, divisor=3 (ii)dividend =25, divisor=9 (iii)dividend=9, divisor=25
(iv)dividend = 25, divisor=5
b. Use % operator with float input and check
Practice Problems:
1. Write a program to find the average of three numbers.
2. Write a program to swap the two numbers with three variables
3. Write a program to swap the two numbers with two variables
4. Ramesh’s basic salary is input through the keyboard. His dearness allowance is 40% of basic salary, and
house rent allowance is 20% of basic salary. Write a program to calculate the gross salary.
5. Temperature of a city in Fahrenheit degrees is input through the keyboard. Write a program to convert
this temperature into Centigrade degrees.
6. Write a C program to perform various arithmetic operations on two integer inputs.