Unit 1 Programs
Unit 1 Programs
C
SUBJECT CODE : CS-205
SEMESTER
UNIT 1 : : 2 ND
SEMESTER
Programming Methodology
and Introduction to C
Language
TOPIC : Simple Programs
PREPARED BY
G.UMASHANKAR
LECTURER IN
ECE
Program-1
Write a c program to print area of triangle.
#include<stdio.h>
#include<conio.h>
void main ( )
{
int a=10, h=20,area;
clrscr( );
area =0.5*b*h
printf (“ %d ”, area);
getch( );
}
INPUT : Given inputs
b=10,h=20
OUTPUT:
area = 100
Program -2 :
Write a c program to print area of circle
#include<stdio.h>
#include<conio.h>
#define pi 3.14
void main( )
{
int r;
float area ;
clrscr( );
printf(“enter the value of r = ”);
scanf(“ %d ”, &r );
area= pi*r*r;
printf(“ %f ”, area);
getch( );
}
INPUT :
Enter the value of r =5
OUTPUT :
78.500000
Program - 3 :
Write a c program to print area of
rectangle
#include<stdio.h>
#include<conio.h>
void main ( )
{
int l, b , area;
clrscr( );
printf(“enter the value of l , b”);
scanf(“%d\n % d ”, &l , & b);
area = l * b;
printf ( “ %d “,area);
getch( );
}
INPUT :
Enter the value of l = 5 , b=5
OUTPUT :
25
Program -4 :
Write a c program to print are a of square
#include<stdio.h>
#include<conio.h>
void main( )
{
int side , area;
clrscr( );
printf(“ enter the value of side :
“);
scanf(“ %d ’, &side”);
area = side*side;
printf(“\n area of square =%d” ,
area);
getch( );
}
INPUT :
Enter the length of the side 50
OUTPUT :
Area of square =2500
Program -5 :
Write a c program to convert Fahrenheit
temperature to Celsius scale
#include<stdio.h>
#include<conio.h>
void main ( )
{
int f ;
float c ;
clrscr( );
printf( “enter the values of f” );
scanf(“%d “, &f );
c=( ( f-32 ) * 5 ) / 9;
printf( “%f ”, c);
getch();
}
INPUT :
Enter the value of f 140
OUTPUT:
60.000000
Program-5 :
Write a C program to print sum and average of
6 subjects
#include<stdio.h>
#include<conio.h>
void main( )
{
int m1, m2, m3, m4, m5, m6, total ;
float avg;
printf(“Enter 6 subject marks\n” );
scanf(“%d%d%d%d%d%d ”, &m1, &m2,
&m3, &m4, &m5, &m6);
total = m1+ m2 + m3 + m4 + m5 +
m6;
Avg = total/6;
printf(“sum of 6 subjects =%d\n ”,
total );
printf(“Average of 6 subjects=%f”,
avg );
getch();
}
Input :
Enter 6 subjects marks 92 90 85 99 89
94
Output :
Sum of 6 subjects = 549
Average of 6 subjects=91.500000
FREQUENTLY ASKED QUESTIONS