Unit no. 01: Introduction to Programming
Programming Exercise:
Exercise 1:
- With the help of your teacher open the IDE installed on your lab computer for writing C programs.
- Write the following program in the editor and save it as “welcome.c”
#include<stdio.h>
#include<conio.h>
Void main()
{
Printf (” Welcome to C language”); /* A simple C language program*/
getch ();
}
Run the program to see welcome to C language printed on the screen as output.
“ You just have to write above program in an IDE to get output”
Exercise 2
- Write a program that declares variables of appropriate data types to store the personal data about your best friend. Initialize these variables with the following data:
- Initial letter of his name
- Initial letter of his gender
- His age
- His height
#include <stdio.h>
int main()
{
// Declaring and initializing variables
char initial_name = ‘A’; // Initial letter of name
char gender_initial = ‘M’; // ‘M’ for Male, ‘F’ for Female
int age = 21; // Age in years
float height = 1.75; // Height in meters
// Displaying the personal data
Printf (“Best Friend’s name Initial letter: %c\n”, initial_name);
printf(“Gender Initial: %c\n”, gender_initial);
printf(“Age: %d\n”, age);
printf(“Height (in meters): %.2f\n”, height);
return 0;
}
