Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Date:

Introduction to C programming
Exp:No:1

Aim :
To learn about the Data-types, variables and keywords in C - programming

1. Hello world program

#include <stdio.h> // your first program in C


#include <conio.h>

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;

// Sizeof operator is used to evaluate the size of a variable


printf("Size of int: %d bytes\n",sizeof(i));
printf("Size of float: %d bytes\n",sizeof(f));
printf("Size of double: %d bytes\n",sizeof(d));
printf("Size of char: %d byte\n",sizeof(c));
printf("Size of short int: %d byte\n",sizeof(si));
printf("Size of long double: %d byte\n",sizeof(ld));
return 0;
}

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);

printf ( "\nEnter your name " ) ;


gets(str); //get string input followed by enter key
printf("\nprinting name....");
puts(str); // printing the string
printf ( "\nContinue Y/N " ) ;
getchar( ) ; /* will echo character, must be followed by enter key */
return 0;
}
Self-evaluation questions:
What is conio.h ?

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

4. Program to Compute Quotient and Remainder (use of arithmetic operator)

#include <stdio.h>
int main()
{

int dividend, divisor, quotient, remainder;

printf("Enter dividend: ");


scanf("%d", &dividend);

printf("Enter divisor: ");


scanf("%d", &divisor);

// 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.

7. Write a C program to evaluate the given expression.

You might also like