1 / 15

Programming In C++

Programming In C++. Spring Semester 2013 Practice 2. Practice-1. Write down a program to return sum of square of two numbers entered by the user with the help of a function. Practice-1. #include< stdio.h > #include< conio.h > int sqSum ( int,int ); int main(void) {

gloria
Download Presentation

Programming In C++

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Practice-1 • 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

  3. Practice-1 #include<stdio.h> #include<conio.h> intsqSum(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(); } intsqSum(intp,int q) { p=p*p; q=q*q; return p+q; } Programming In C++, Practice By Umer Rana

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

  5. Practice-2 # 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++, Practice By Umer Rana

  6. Practice-3 • Write down a program using if-else-if statement to find the age group of a student. Programming In C++, Practice By Umer Rana

  7. 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

  8. Practice-4 • 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

  9. Practice-4 { inti,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(); } Programming In C++, Practice By Umer Rana

  10. Practice-5 • 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

  11. 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

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

  13. 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

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

  15. 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

More Related