150 likes | 233 Views
Programming In C++. Spring Semester 2013 Practice 1-3 Lectures. Practice-1. Write a program to print you name, Class & group. Practice-1. # include < stdio.h > # include < cosio.h > Void main () { printf (“My name is Ali <br>”); printf (“My Class is BSCS <br>”);
E N D
Programming In C++ Spring Semester 2013 Practice 1-3 Lectures Programming In C++, Lecture 3 By UmerRana
Practice-1 • Write a program to print you name, Class & group. Programming In C++, Lecture 3 By UmerRana
Practice-1 # include <stdio.h> # include <cosio.h> Void main () { printf (“My name is Ali \n”); printf (“My Class is BSCS \n”); printf (“My Group is B \n”); getche(); } Programming In C++, Lecture 3 By UmerRana
Practice-2 • Write a program to show sum of two integer number 10 & 20. Programming In C++, Lecture 3 By UmerRana
Practice-2 # include <stdio.h> # include <cosio.h> Void main () { int num1=10,num2=20,sum; sum=num1+num2; printf(“Sum of integers is %d”,sum); getche(); } Programming In C++, Lecture 3 By UmerRana
Practice-3 • Write a program that will demonstrate the use of escape sequences Output Name RollNo Marks Amir 78 425 Tahir 22 389 Programming In C++, Lecture 3 By UmerRana
Practice-3 # include <stdio.h> # include <cosio.h> Void main () { printf(“Name \t\t Roll No\t\t Marks\n”); printf(“Amir \t\t 78 \t\t 425\n”); printf(“Tahir\t\t 22 \t\t 389\n”); getche(); } Programming In C++, Lecture 3 By UmerRana
Practice-4 • Write a program that displays the ASCII code of the character typed by user. Programming In C++, Lecture 3 By UmerRana
Practice-4 # include <stdio.h> # include <cosio.h> Void main () { char ch; ch=getche(); printf(“\n The ASCII code for %C is %d”,ch ,ch); getche(); } Programming In C++, Lecture 3 By UmerRana
Practice-5 • Write a program to print digits from 1 to 10 Programming In C++, Lecture 3 By UmerRana
Practice-5 # include <stdio.h> # include <cosio.h> Void main () { int count=1; while(count<=10) {printf(“%d\n”,count); count=count+1; } getche(); } # include <stdio.h> # include <cosio.h> Void main () { int count; for(count=1; count<=10;count++) printf(“%d\n”,count); getche(); } Programming In C++, Lecture 3 By UmerRana
Practice-6 • Write a program that will print asterisks (*) according to the pattern shown in: ******* ****** ***** **** *** ** * Programming In C++, Lecture 3 By UmerRana
Practice-6 # include <stdio.h> # include <cosio.h> Void main () { int inner, outer; for(outer=7; outer=>1;outer--) { inner=1; while(inner<+outer) { printf(“*”); inner++ } printf(“\n”); } getche(); } Programming In C++, Lecture 3 By UmerRana
Practice-6 # include <stdio.h> # include <cosio.h> Void main () { int inner, outer; for(outer=7; outer=>1;outer--) { inner=1; while(inner<+outer) { printf(“*”); inner++ } printf(“\n”); } getche(); } Programming In C++, Lecture 3 By UmerRana
Practice-7 • Write a program that will print asterisks (*) according to the pattern shown in: • Re-write by replacing the inner while loop with • For loop • do- while loop • Re-write by replacing the outer for loop with • While loop • do- while loop Programming In C++, Lecture 3 By UmerRana