0% found this document useful (0 votes)
7 views4 pages

Practice 01 - Sol

Uploaded by

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

Practice 01 - Sol

Uploaded by

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

Solution Practice Tasks – Print Statements

Task 01: Print five lines about yourself.


#include<stdio.h>
int main(){
printf("My name is Maskeen.\n");
printf("I am many years old.\n");
printf("I am very busy with nothing to do.\n");
printf("I am doing studies for job only.\n");
printf("If you can give me good salary, I can leave studies today.\n");
return 0;
}
Task 02: Write a program that shows following output on screen:
I am studying in "FCIT" and I am in 'first semester'
#include<stdio.h>
int main()
{
printf(“First Name \t Last Name \n”);
printf(“Muhammad \t Abdullah \n”);
.
.
.
return 0;
}
Task 03: Write a program that print the following pattern:
1
23
456
7891
(using multiple printf() statements)
#include<stdio.h>
int main(){
printf("1\n");
printf("23\n");
printf("456\n");
printf("7891\n");
return 0;
}
Task 04: Print the following table using printf() statements
NAME SEMESTER GPA
ALI SECOND 3.50
AHMAD THIRD 3.33
RIZWAN FOURTH 3.87
SADIA FIFTH 4.00
#include<stdio.h>
int main(){
printf ("NAME\t\tSEMESTER\tGPA\n");
printf ("ALI\t\tSECOND\t\t3.50\n");
printf ("AHMAD\t\tTHIRD\t\t3.33\n");
printf ("RIZWAN\t\tFOURTH\t\t3.87\n");
printf ("SADIA\t\tFIFTH\t\t4.00\n");
BSSE Fall 2022
return 0;
}
Task 05: Print the following story, inserting your appropriate info into the appropriate locations: There
once was a person named "NAME" who lived in "CITY". At the age of AGE, 'NAME’ went to college at
"COLLEGE". 'NAME’ graduated and went to work as a "PROFESSION". Then, 'NAME’ adopted a(n)
ANIMAL named "PETNAME." They both lived happily ever after!
Show correct punctuation as well, and Print each sentence on new line (Hint: Use escape sequences).
#include<stdio.h>
int main(){
printf("There once was a person named \"Ali\" who lived in
\"Lahore\".\n");
printf("At the age of 20, \'Ali\' went to college at \"PUCIT\".\n");
printf("\'Ali\' graduated and went to work as a \"Programmer\".\n");
printf("Then, \'Ali\' adopted a dog named \"Tommy\".\n");
printf("They both lived happily ever after!\n");
return 0;
}
Task 06: Write a program in which you will practice on different escape sequence characters like \b , \\
, \r etc.
#include<stdio.h>
int main(){
printf("Course Name \t\t\t Total Marks \t\t Marks \t\t Grade\n");
printf("Programming Fundamentals \t 100 \t\t\t 90 \t\t A+\n");
printf("Probability & Statistics\t 80 \t\t\t 90 \t\t A");
return 0;
}
Task 07: Print the following star pattern
*
* *
* * *
* * * *
* * * * *
#include<stdio.h>
int main(){
printf("*\n");
printf("*\t*\n");
printf("*\t*\t*\n");
printf("*\t*\t*\t*\n");
printf("*\t*\t*\t*\t*\n");
return 0;
}
Task 08: Print a triangle using Asterisk * like this: (You may change number of lines in triangle)
*
* *
* *
* *
* *
* *
* *
* *
BSSE Fall 2022
*********
#include<stdio.h>
int main(){
printf("\t *\n");
printf(" **\n");
printf(" ***\n");
printf(" ****\n");
printf(" *****\n");
printf(" ******\n");
printf(" *******\n");
printf(" ********\n");
printf(" *********\n");
printf("**********\n");
return 0;
}
Task 09: Print the following star pattern
*******
*
*
*
*
*
*******
#include<stdio.h>
int main(){
printf("\t* * * * * * *\n");
printf("\t *\n");
printf("\t *\n");
printf("\t *\n");
printf("\t *\n");
printf("\t *\n");
printf("\t *\n");
printf("\t* * * * * * *\n");
return 0;
}
Task 10: Print a pattern like this:
|---------------|
| 1 |
| 123 |
| 12345 |
| 1234567 |
| 123456789 |
| 1234567 |
| 12345 |
| 123 |
| 1 |
|---------------|

#include<stdio.h>
int main(){
printf("|-------------|\n");
printf("| 1 |\n");

BSSE Fall 2022


printf("| 123 |\n");
printf("| 12345 |\n");
printf("| 1234567 |\n");
printf("| 123456789 |\n");
printf("| 1234567 |\n");
printf("| 12345 |\n");
printf("| 123 |\n");
printf("| 1 |\n");
printf("|-------------|\n");
return 0;
}
Task 11:
Draw a hollow box using stars with the help of printf statements.
#include<stdio.h>
int main(){
printf("\t* * * * * * *\n");
printf("\t* *\n");
printf("\t* *\n");
printf("\t* *\n");
printf("\t* *\n");
printf("\t* *\n");
printf("\t* *\n");
printf("\t* * * * * * *\n");
return 0;
}
Task 12:
Show English Alphabet "A" on screen by using stars in printf statements.
#include<stdio.h>
int main(){
printf(" *\n");
printf(" * *\n");
printf(" * *\n");
printf(" * *\n");
printf(" * *\n");
printf(" ***********\n");
printf(" * *\n");
printf(" * *\n");
printf("* *\n");
return 0;
}

BSSE Fall 2022

You might also like