0% found this document useful (0 votes)
91 views7 pages

Lab Report-4

This document contains a lab assignment on decision control structures in C language. The lab has 6 tasks to write programs that take user input and use conditional statements like if-else to output results. The tasks include programs to check grades, even/odd numbers, triangle validity, alphabet recognition, sign of a number, and calculating areas of shapes. The document also has 2 post-lab tasks - one to reverse and compare 5-digit numbers, and another to find the largest of 3 numbers. It concludes that the programs help understand logic and syntax of programming.

Uploaded by

Talha Tufail
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
91 views7 pages

Lab Report-4

This document contains a lab assignment on decision control structures in C language. The lab has 6 tasks to write programs that take user input and use conditional statements like if-else to output results. The tasks include programs to check grades, even/odd numbers, triangle validity, alphabet recognition, sign of a number, and calculating areas of shapes. The document also has 2 post-lab tasks - one to reverse and compare 5-digit numbers, and another to find the largest of 3 numbers. It concludes that the programs help understand logic and syntax of programming.

Uploaded by

Talha Tufail
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Lab#4

Decision Control Structure


1. Objective:
2. 1.1. The objective of C language is simple, designed to enable sophisticated objective-
oriented programming. Easy to analyze program. Help to understand the logic of
programming.
3. 1.2. The objective of C language is simple, designed to enable sophisticated objective-
oriented programming. Easy to analyze program. Help to understand the logic of
programming.
4. Introduction:
C is a procedural programming language. It was mainly developed as a system
programming language to write an operating system. The main features of C language
include low-level access to memory, a simple set of keywords, and clean style, these
features make C language suitable for system programming’s like an operating system.

5. In-Lab Tasks: Following are the in-lab tasks:

Task#1

 Code:
#include<stdio.h>
int main()
{
char c; /
printf("Enter a character: ");
scanf("%c", &c);
if (c=='A')
{
printf("Excellent work ");
}
if (c=='B')
{
printf("Continue Hard-working ")
}
if (c=='F')
{
printf("Fail ");
}
}
 Output:

Task#2
 Code:
#include<stdio.h>
int main()
{
int num;

Programming Fundamental Page 1


printf("Enter an integer: ");
scanf("%d", &num);
if (num%2)
{
printf("The integer you entered is ODD");
}
else
{
printf("The integer you entered is EVEN");
}
}
 Output:

Task#3

 Code:
#include<stdio.h>
int main()
{
int a1, a2, a3, sum;
printf("Enter angle # 1: ");
scanf("%d", &a1);
printf("Enter angle # 2: ");
scanf("%d", &a2);
printf("Enter angle # 3: ");
scanf("%d", &a3);
sum = a1 + a2 + a3;
if(sum==180)
{
printf("The triangle is valid");
}
else
{
printf("The triangle is invalid");
}
}
 Output:

Task# 4

 Code:
#include<stdio.h>
int main()
{
char c;
printf("Enter a character: ");
scanf("%c", &c);
if((c>='A' && c<='Z') || (c>='a' && c<='z'))
{

Programming Fundamental Page 2


printf("The character you entered is an alphabet");
}
else
{
printf("The character you entered is not an alphabet");
}
}

 Output:

Task # 5

 Code:
#include<stdio.h>
int main()
{
int num;
printf("Enter a number: ");
scanf("%d", &num);
if(num>0)
{
printf("The number is positive");
}
else
{
printf("The number is negative");
}
}
 Output:

Task # 6

 Code:
#include<stdio.h>
int area_circle (int r);
int area_rect (int l, int w);
int area_tri (int h, int b);
int area_square (int s);
int main()
{
char ch;
int area, circle, triangle, rectangle, square;
printf("Enter a character: ");
scanf("%c", &ch);
area = ch;
if (ch=='c')
{
int a;

Programming Fundamental Page 3


printf("Enter the radius of circle: ");
scanf("%d", &a);
area_circle(a);
}
else if(ch=='t')
{
int b,h;
printf("Enter the height of triangle: ")
scanf("%d", &h);
printf("Enter the breadth of triangle: ");
scanf("%d", &b);
area_tri(h,b);
}
else if(ch=='r')
{
int l,w;
printf("Enter the length of rectangle: ");
scanf("%d", &l);
printf("Enter the width of rectangle: ");
scanf("%d", &w);
area_rect(l,w);
}
else if(ch=='s')
{
int s;
printf("Enter the length of the side of square: ");
scanf("%d", &s);
area_square(s);
}
else
{
printf("You entered a wrong character");
}
}

int area_circle (int r)


{
int circle;
circle = 3.14*r*r;
printf("Area of circle is: %d",circle);
}
int area_tri (int h, int b)
{
int triangle;
triangle = (h*b)/2;
printf("Area of triangle is: %d", triangle);
}
int area_rect (int l, int w)
{
int rectangle;
rectangle = l*w;
printf("Area of rectangle is: %d", rectangle);
}
int area_square (int s)
{
int square;
square = s*s*s*s;
printf("Area of square is: %d", square);
}

Programming Fundamental Page 4


 Output:

6. Post-Lab Tasks: Following are the post-lab tasks:

Task#1

 Code:
#include<stdio.h>
int main()
{
int a, b, c, d, e, num, newnum, sum1, sum2;
printf("Enter a five-digit number: ");
scanf("%d", &num);
a = (num/10000)%10;
printf("1st digit is %d\n", a);
b = (num/1000)%10;
printf("2nd digit is %d\n", b);
c = (num/100)%10;
printf("3rd digit is %d\n", c);
d = (num/10)%10;
printf("4th digit is %d\n", d);
e = num%10;
printf("5th digit is %d\n", e);
printf("Original sequence is %d\n", num);
newnum = printf("Reverse sequence is %d%d%d%d%d\n", e,d,c,b,a);
sum1 = a+b+c+d+e;
sum2 = e+d+c+b+a;
if (sum1==sum2)
{
printf("Reverse and Original numbers are equal.");
}
else
{
printf("Original and Reverse numbers are not equal.");
}
}
 Output:

Task#2

 Code:

Programming Fundamental Page 5


#include<stdio.h>
int main()
{
int num1, num2, num3;
printf("Enter the first number: ");
scanf("%d", &num1);
printf("Enter the second number: ");
scanf("%d", &num2);
printf("Enter the third number: ");
scanf("%d", &num3);
if ((num1>num2)&&(num1>num3))
{
printf("The first number is the largest number.");
}
else if ((num2>num1)&&(num2>num3))
{
printf("The second number is the largest number.");
}
else
{
printf("The third number is the largest number.");
}
}
 Output:

Task#3
Observe the result of arithmetic statement, assumed that a is a real variable.
 Code:
#include<stdio.h>
int main()
{
int year;
printf("Enter the Year: ");
scanf("%d", &year);
if (year%4==0)
{
printf("The year you entered is a leap year.");
}
else
{
printf("The year you entered is not a leap year.");
}
}
 Output:

7. Conclusion:
After analyzing these program, we cane to know that how to solve equation, converting
temperature into centigrade, area and perimeter of rectangular, Gross income, ASCII value,

Programming Fundamental Page 6


Interchanging constants, Integer, Float, Character respectfully. Also know we understand
logic and syntax of programming.

Programming Fundamental Page 7

You might also like