# Programming In C++ Spring Semester 2013 Practice 2 Programming In C++, Practice By Umer Rana.

## Presentation on theme: "Programming In C++ Spring Semester 2013 Practice 2 Programming In C++, Practice By Umer Rana."— Presentation transcript:

Programming In C++ Spring Semester 2013 Practice 2 Programming In C++, Practice By Umer Rana

Practice-1 n Write down a program to return sum of square of two numbers entered by the user with the help of a function. Programming In C++, Practice By Umer Rana

Practice-1 #include int sqSum(int,int); int main(void) { int num1,num2,Ans; printf("First Number is "); scanf("%d",&num1); printf("\n2nd Number is "); scanf("%d",&num2); Ans=sqSum(num1,num2); printf("\nSum of the Square of two Numbers is %d",Ans); getch(); } int sqSum(int p,int q) { p=p*p; q=q*q; return p+q; } Programming In C++, Practice By Umer Rana

Practice-2 n Write nested loop with help of program? Programming In C++, Practice By Umer Rana

Practice-2 Programming In C++, Practice By Umer Rana # include Void main () { int inner, outer; for(outer=7; outer=>1;outer--) { inner=1; while(inner<+outer) { printf(“*”); inner++ } printf(“\n”); } getche(); }

Practice-3 n Write down a program using if-else-if statement to find the age group of a student. Programming In C++, Practice By Umer Rana Group Age A 18-21 B 22-25 C 25-30 D31 and Greater

Practice-3 int main(void) { int Age; printf("Please Enter the Age of the Student"); scanf("%d",&Age); if (Age>=18 && Age<=21) printf("You are in Age Group A"); else if (Age>=22 && Age<=25) printf("You are in Age Group B"); else if (Age>=26 && Age<=30) printf("You are in Age Group C"); else if (Age>=31) printf("You are in Age Group D"); getch(); } Programming In C++, Practice By Umer Rana

Practice-4 n Define an array of ten elements to accept a series of numbers from user and then print in descending order. Programming In C++, Practice By Umer Rana

Practice-4 Programming In C++, Practice By Umer Rana { int i,j,temp,a[10]; printf ("Enter the numbers \n"); for (i=0; i<10; ++i) scanf ("%d",&a[i]); for (i=0; i<10; ++i) { for (j=i+1; j<10; ++j) { if (a[i] < a[j]) { temp = a[i]; a[i] = a[j]; a[j] = temp; } printf (“Descending order are given below\n"); for (i=0; i<10; ++i) printf ("%d\n",a[i]); getche(); }

Practice-5 n Write down a program using if-else-if statement to calculate two values enter by user and apply chosen function as ( +, -, *, / ). Programming In C++, Practice By Umer Rana

Practice-5 int num1,num2,Ans; char ope; printf("Please Enter the two number to operate\n"); scanf("%d",&num1); scanf("%d",&num2); printf("\n Please Choose the Function Please (+,-,*,/)\n"); ope=getche(); if(ope=='-') printf("\nSubtraction of two numbers are %d",num1-num2); else if(ope=='+') printf("\nSum of two numbers are %d",num1+num2); else if(ope=='*') printf("\n Multiply of two numbers are %d",num1*num2); else if(ope=='/') printf("\n Division of two numbers are %d",num1/num2); getche(); Programming In C++, Practice By Umer Rana

Practice-6 n Write a program that will print asterisks (*) according to the pattern shown in: ********* Programming In C++, Practice By Umer Rana

Practice-6 int main() { for ( int i=0; i<5; i++) { for (int j=0; j<=8; j++) printf("*"); printf("\n"); } getch(); } Programming In C++, Practice By Umer Rana

Practice-7 n Write a program that will print asterisks (*) according to the pattern shown in: * ** *** **** ***** **** *** ** * Programming In C++, Practice By Umer Rana

Practice-7 Void main () { for ( int i=0; i<5; i++) { for (int j=0; j<=i; j++) printf("*"); printf("\n"); } for ( int i=0; i<5; i++) { for (int j=4; j>=i; j--) printf("*"); printf("\n"); } getch(); } Programming In C++, Practice By Umer Rana

Download ppt "Programming In C++ Spring Semester 2013 Practice 2 Programming In C++, Practice By Umer Rana."

Similar presentations