0% found this document useful (0 votes)
38 views9 pages

CSC103-Programming Fundamentals: Lab Work - 1

The document contains the lab work submitted by Zagim Murtza Awan. It includes 6 programs to print different shapes using asterisks, a program to print numbers 1-4 using different printf methods, and a program to perform basic arithmetic operations like addition, subtraction, multiplication, division, and modulus. The programs demonstrate the use of basic C programming constructs like printf, scanf, and comments.

Uploaded by

Zaigham Malik
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)
38 views9 pages

CSC103-Programming Fundamentals: Lab Work - 1

The document contains the lab work submitted by Zagim Murtza Awan. It includes 6 programs to print different shapes using asterisks, a program to print numbers 1-4 using different printf methods, and a program to perform basic arithmetic operations like addition, subtraction, multiplication, division, and modulus. The programs demonstrate the use of basic C programming constructs like printf, scanf, and comments.

Uploaded by

Zaigham Malik
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/ 9

Lab Work -1

CSC103-Programming Fundamentals

Submitted by:
Zagim Murtza Awan
SP19-BCS-148
B
Submitted to:
Mr. Abdul Karim Shahid

Submitted on:September 12, 2019

Department of Computer Science


COMSATS University Islamabad
Lahore Campus

CSC103-Programming Fundamentals 1
Exercise 1: Print following shape using simple printf statements (You may print these shapes
vertically in one program)

(1) (2) (3) (4) (5) (6)

* ********** * * ***** *****


*** * * ** ** **** ****
***** * * *** *** *** ***
*** * * **** **** ** **
* ********** ***** ***** * *

(1)

Code:

/*This programme is prepared by ZAGIM MURTZA AWAN Reg no.: SP19-BCS-

148 Section: B on 11/9/2019. This programme prints shape*/

#include<stdio.h>

int main()

printf(" * \n"); /*\n is used for new line*/

printf(" *** \n");

printf(" ***** \n");

printf(" *** \n");

printf(" * \n");

return 0;

CSC103-Programming Fundamentals 1
Output:

(2)

Code:

/* This programme is prepared by ZAGIM MURTZA AWAN Reg no.: SP19-BCS-


148 Section: B on 12/09/1019. This programme is used to print shapes of different types.*/
#include<stdio.h>
int main()
{
printf("********** \n");
printf("* * \n");
printf("* * \n");
printf("* * \n");
printf("********** \n");
}

CSC103-Programming Fundamentals 1
Output:

(3)

Code:
/* This programme is prepared by ZAGIM MURTZA AWAN Reg no.: SP19-BCS-
148 Section: B on 12/09/1019. This programme is used to print shapes of different types.*/
#include<stdio.h>
int main()
{
printf("* \n");
printf("** \n");
printf("*** \n");
printf("**** \n");
printf("***** \n");
return 0;
}

CSC103-Programming Fundamentals 1
Output:

(4)

Code:

/* This programme is prepared by ZAGIM MURTZA AWAN Reg no.: SP19-BCS-


148 Section: B on 11/9/2019. This programme prints shape*/
#include<stdio.h>
int main()
{
printf(" ***** \n"); /*\n is used for new line*/
printf(" **** \n");
printf(" *** \n");
printf(" ** \n");
printf(" * \n");
return 0;
}

Output:

CSC103-Programming Fundamentals 1
(5)

Code:

/* This programme is prepared by ZAGIM MURTZA AWAN Reg no.: SP19-BCS-


148 Section: B on 11/9/2019. This programme prints shape*/
#include<stdio.h>
int main()
{
printf(" * \n"); /*\n is used for new line*/
printf(" ** \n");
printf(" *** \n");
printf(" **** \n");
printf(" ***** \n");
return 0;
}

Output:

(6)

Code:
/* This programme is prepared by ZAGIM MURTZA AWAN Reg no.: SP19-BCS-
148 Section: B on 11/9/2019. This programme prints shape*/
#include<stdio.h>
int main()
{
printf(" * \n"); /*\n is used for new line*/
printf(" ** \n");
printf(" *** \n");
printf(" **** \n");
printf(" ***** \n");
return 0;
}

CSC103-Programming Fundamentals 1
Output:

Exercise 2: Write a program that prints the numbers 1 to 4 on the same line. Write the program using the
following methods.

a) Using one printf statement with no conversion specifiers.


b) Using one printf statement with four conversion specifiers.
c) Using four printf statements

a)

Code:

/* This programme is prepared by ZAGIM MURTZA AWAN Reg no.: SP19-BCS-


148 Section: B on 11/9/2019. This programme prints 1 to 4 on the same line using one printf statement
with no conversion specifier*/
#include<stdio.h>
int main()
{
printf("1 2 3 4");
return 0;
}

Output:

CSC103-Programming Fundamentals 1
b)

Code:

/* This programme is prepared by ZAGIM MURTZA AWAN Reg no.: SP19-BCS-


148 Section: B on 11/9/2019. This programme prints 1 to 4 on the same line Using one printf statement
with four conversion specifiers*/
#include<stdio.h>
int main()
{
printf("1 ");
printf("2 ");
printf("3 ");
printf("4 ");
return 0;
}

Output:

c)

Code:

/* This programme is prepared by ZAGIM MURTZA AWAN Reg no.: SP19-BCS-


148 Section: B on 11/9/2019. This programme prints 1 to 4 on the same line Using one printf statement
with four conversion specifiers*/
#include<stdio.h>
int main()
{
printf("%d,%d,%d,%d",1,2,3,4);
return 0;
}

Output:

CSC103-Programming Fundamentals 1
Exercise 3: Write a C-Program to perform the simple arithmetic operations (addition,
subtraction, multiplication, division, remainder).

Code:
/* This programme is prepared by ZAGIM MURTZA AWAN Reg no.: SP19-BCS-
148 Section: B on 11/9/2019. This program is to perform arithmetic operations on two numbers input by
user*/
#include<stdio.h>
int main()
{
int a,b;/*Declaration*/
print("Enter the values of a and b");
scanf("%d%d",&a,&b);
printf("the sum of %d and %d is %d",a,b,a+b);/*Addition(arithmetic operation)*/
printf("the difference of %d and %d is %d",a,b,a-b);/*subtraction(arithmetic operation )*/
printf("the product of %d and %d is %d",a,b,a*b );/*multiplication(arithmetic operation)*/
printf("the quotient of %d and %d is %d",a,b,a/b);/*division(arithmetic operation)*/
printf("the remainder of %d and %d is %d",a,b,a%b);/*Modulus(arithmetic operation)*/
return 0;
}
Output:-

CSC103-Programming Fundamentals 1

You might also like