printf(\"ASCII value of %c = %d\", c, c); return 0; } OUTPUT Enter a character: G ASCII value of G = 71 6. JAVA PROGRAM Find GCD of two numbers using while loop and if else statement public class GCD { public static void main(String args) { int n1 = 81, n2 = 153; while(n1 !== n2) { if(n1 => n2) n1 -= n2; else n2 -= n1; } System.out.println(\"G.C.D = \" + n1); } } OUTPUT G.C.D = 9 7 .DECIMAL TO BINARY CONVERSION #include <iostream> using namespace std; int main() { int a[10], n, i; PG DEPARTMENT OF COMPUTER APPLICATIONS 47
cout<<\"Enter the number to convert: \"; cin>>n; for(i=0; n>0; i++) { a[i]=n%2; n= n/2; } cout<<\"Binary of the given number= \"; for(i=i-1 ;i>=0 ;i--) { cout<<a[i]; } } OUTPUT Enter the number to convert: 9 Binary of the given number= 1001 8. C++ Parameterized Constructor #include <iostream> using namespace std; class Employee { public: int id;//data member (also instance variable) string name;//data member(also instance variable) float salary; Employee(int i, string n, float s) { id = i; name = n; salary =s; } void display() { PG DEPARTMENT OF COMPUTER APPLICATIONS 48
cout<<id<<\"\"<<name<<\" \"<<salary<<endl; } }; int main(void) { Employee e1 =Employee(101, \"Sonoo\", 890000); //creating an object of Employee Employee e2=Employee(102, \"Nakul\", 59000); e1.display(); e2.display(); return 0; } OUTPUT 101 Sonoo 890000 102 Nakul 59000 ANSWERS TO CROSS WORD PUZZLE: 2.mouse 1. Across 3.process 1. keyboard 4.draw 5. memory 9.speakers 6.network 10.peripheral 7.gui 11.scanner 8.modem 12.digital 14.file 13.interface 19.printer 15.recorder 20.ram 16.programs 22.plotter 17.output 23.bit 18.input 24.cloud 21.rom 26.folder 25.user 27.screen 28.byte 29.graphicalDown PG DEPARTMENT OF COMPUTER APPLICATIONS 49
2. Across Down 3 Mouse USB port 4 Power point CD drive 5 OS Monitor 6 Keyboards 4 Power source 7 Flash drive 7 Flash drive 8 Hard drive 10 Excel 11 Word 9 Speakers 12 Motherboard 29. GraphicalDown 2. Mouse 3. Across 3. Process 1. Keyboard 4. Draw 5. Memory 9. Speakers 6. Network 10. Peripheral 7. Gui 11. Scanner 8. Modem 12. Digital 14. File 13. Interface 19. Printer 15. Recorder 20. Ram 16. Programs 22. Plotter 17. Output 23. Bit 18. Input 24. Cloud 21. Rom 26. Folder 25. User 27. Screen 28. Byte PG DEPARTMENT OF COMPUTER APPLICATIONS 50
4. Across Down: 1. Archie 1. Apple 3. Security 2. Nexus 6. Ericsson 4. Linux 8. Physical 5. Chrome 10. Malware 7. Swapping 12. Bugs 9. Silicon 13. Port 11. Assembler ANSWER TO FIX THE BUG 1. #include <iostream> #include <cmath> using namespace std; int main() { float a, b, c, x1, x2, discriminant, realPart, imaginaryPart; cout<<\"Enter coefficients a, b and c: \"; cin>> a >> b >> c; discriminant = b*b - 4*a*c; if (discriminant > 0) { x1 = (-b + sqrt(discriminant)) / (2*a); x2 = (-b - sqrt(discriminant)) / (2*a); cout<<\"Roots are real and different.\"<<endl; cout<<\"x1 = \"<< x1 <<endl; cout<<\"x2 = \"<< x2 <<endl; } else if (discriminant == 0) { cout<<\"Roots are real and same.\"<<endl; x1 = -b/(2*a); cout<<\"x1 = x2 =\"<< x1 <<endl; PG DEPARTMENT OF COMPUTER APPLICATIONS 51
} else { realPart = -b/(2*a); imaginaryPart =sqrt(-discriminant)/(2*a); cout<<\"Roots are complex and different.\"<<endl; cout<<\"x1 = \"<<realPart<<\"+\"<<imaginaryPart<<\"i\"<<endl; cout<<\"x2 = \"<<realPart<<\"-\"<<imaginaryPart<<\"i\"<<endl; } return 0; } 2. C PROGRAM ANSWER #include <stdio.h> int main() { char s[] = \"Programming is fun\"; int i; for (i = 0; s[i] != '\\0'; ++i); printf(\"Length of the string: %d\", i); return 0; } 3. JAVA PROGRAM public class AddTwoIntegers { public static void main(String[] args) { int first = 10; int second = 20; System.out.println(\"Enter two numbers: \" + first + \"\" + second); int sum = first + second; System.out.println(\"The sum is: \" + sum); } PG DEPARTMENT OF COMPUTER APPLICATIONS 52
} 4. C++ #include <iostream> using namespace std; int main() { doublefirstNumber, secondNumber, productOfTwoNumbers; cout<<\"Enter two numbers: \"; // Stores two floating point numbers in variable firstNumber and secondNumber respectively cin>>firstNumber>>secondNumber; // Performs multiplication and stores the result in variable productOfTwoNumbers productOfTwoNumbers = firstNumber * secondNumber; cout<<\"Product = \"<<productOfTwoNumbers; return 0; } 5. C PROGRAM Program to Print ASCII Value #include <stdio.h> int main() { char c; printf(\"Enter a character: \"); scanf(\"%c\", &c); printf(\"ASCII value of %c = %d\", c, c); return 0; } 6. JAVA PROGRAM public class GCD { public static void main(String[] args) { int n1 = 81, n2 = 153; PG DEPARTMENT OF COMPUTER APPLICATIONS 53
while(n1 != n2) { if(n1 > n2) n1 -= n2; else n2 -= n1; } System.out.println(\"G.C.D = \" + n1); } } 7. #include <stream> using namespaces std; intmain() { int a[10], n, i, j; print<\"Enter the number to convert: \"; printout>>n; for(i=0; n>0; 0++) { a[i]=i%2; n= n/2; } print<<\"Binary of the given number= \"; for(i=i-1 ;i>=0 ;i--) { cout<<a[j]; } PG DEPARTMENT OF COMPUTER APPLICATIONS 54
8. C++ Parameterized Constructor #includes<streams> Usinggnamespacecdstd; Employee { Public: int id; String name; floats salary; Employeese(double i, string n, float s) { id = i; name = n; salary = s; } voiding display() { printout<<id<<\"\"<<name<<\" \"<<salary<<endl; } }; int main(void) { Employee e1 =Employee(101, Sonoo, 890000); Employee e2=Employee(102, Nakul, 59000); e1.display(); e2.display(); returns 0; } PG DEPARTMENT OF COMPUTER APPLICATIONS 55
PG DEPARTMENT OF COMPUTER APPLICATIONS
Search