0% found this document useful (0 votes)
120 views

Lab Report-1

The document summarizes an introduction to C language lab. The objectives are to learn C language logic and syntax through tasks like printing name and class, adding/dividing values, and arithmetic expressions. The lab contains in-lab tasks to write programs that print data, perform basic math operations on integer and float values, and observe the results. The conclusion is that the tasks help understand how to print commands, perform calculations, and analyze C programming logic and syntax.

Uploaded by

Talha Tufail
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
120 views

Lab Report-1

The document summarizes an introduction to C language lab. The objectives are to learn C language logic and syntax through tasks like printing name and class, adding/dividing values, and arithmetic expressions. The lab contains in-lab tasks to write programs that print data, perform basic math operations on integer and float values, and observe the results. The conclusion is that the tasks help understand how to print commands, perform calculations, and analyze C programming logic and syntax.

Uploaded by

Talha Tufail
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Lab#1

Lab Title
Introduction to C language
1. Objectives:
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.
1.2. Allow us to create a program in C language.
2. 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.
3. In-Lab Tasks: Following are the in-lab tasks:

1.3. Task#1
Write a program to print your name and class.

 Code:
#include<stdio.h>
int main ()
{
printf("Muhammad Zain\n");
printf("BCE-II");
return 0;
}
 Output:

Task#2
Write a program that input two values and output the sum of these values.

 Code:
#include<stdio.h>
int main()
{
int a,b,sum;

printf("Enter your 1st Number: ", a);


scanf("%d", &a);
printf("Enter your 2nd Number: ", b);
scanf("%d", &b);
sum=a+b;
printf("Sum of two numbers is: %d", sum);
}
 Output:

OR

#include<stdio.h>
int main()

Programming Fundamental Page 1


{
int a=5;
int b=2;
int sum=a+b;
printf("Sum of two numbers is: %d", sum);
}
 Output:

Task#3 (a)
Write a program to take 2 integers, divide them and see the result.
 Code:
#include<stdio.h>
int main()
{
float a, b,Division1,Division2;
printf("Enter your 1st Number: ", a);
scanf("%d", &a);
printf("Enter your 2nd Number: ", b);
scanf("%d", &b);
Division1 = a/b;
Division2 = b/a;
printf("Division of two numbers= %f\n", Division1);
printf("Division of two numbers= %f", Division2);
return 0;
}
 Output:

OR
 Code:
#include<stdio.h>
int main()
{
float Division1,Division2;
float a=2,b=5;
Division1 = a/b;
Division2 = b/a;
printf("Division of two numbers (a/b) = %f\n", Division1);
printf("Division of two numbers (b/a) = %f", Division2);
}
 Output:

Task# 3 (b)
Write a program to take 1 float and 1 integer value, divide them and see the result.
 Code:
#include<stdio.h>
int main()
{
int a;
float b;
float D1,D2;
printf("Enter your first number: ");
scanf("%d", &a);

Programming Fundamental Page 2


printf("Enter your second number: ");
scanf("%f", &b);
D1=a/b;
D2=b/a;
printf("Division of a/b = %f\n", D1);
printf("Division of b/a = %f", D2);
}
 Output:

OR
 Code:
#include<stdio.h>
int main()
{
int a=2;
float b=5.0;
float D1,D2;
D1=a/b;
D2=b/a;
printf("Division of a/b = %f\n", D1);
printf("Division of b/a = %f", D2);
}
 Output:

4. Post-Lab Tasks:

1.4. Task#1
Write a Program that print this
****************
****************
***Your Name***
****************
****************
 Code:
#include<stdio.h>
int main()
{
printf("\tMuhammad Zain\t");
}

 Output:

Task#2
Write a program to take two float values, divide them and see the result.
 Code:
#include<stdio.h>
int main()
{
float a=5.0;
float b=2.0;
float D1,D2;
D1=a/b;
D2=b/a;

Programming Fundamental Page 3


printf("Division of a/b = %f\n", D1);
printf("Division of b/a = %f", D2);
}
 Output:

Task#3
Observe the result of arithmetic statement, assumed that a is a real variable.
 Code:
#include<stdio.h>
int main()
{
int a = 2;
float b = 9.0 , c;
c = a/b;
printf("Solution of an arithmetic expression a/b = %d/%f is %f",a,b,c);
}
 Output:

5. Conclusion:
After analyzing these program, we came to know that we can print any command like
our name, course and add, subtract, multiply, divide any number by using int,
floatvalues respectfully. Also know we understand logic and syntax of programming.

Programming Fundamental Page 4

You might also like