Java Program to Add Two Complex Numbers

  public class ComplexNumber{ double real, img; ComplexNumber(double r, double i){ this.real = r; this.img = i; } public static ComplexNumber sum(ComplexNumber c1, ComplexNumber c2) { ComplexNumber temp = new ComplexNumber(0, 0); temp.real = c1.real + c2.real; temp.img = c1.img + c2.img; return temp; } public static void main(String args[]) { ComplexNumber c1 = new … Read more

Java Program to Calculate Compound Interest

public class JavaExm { public void calculate(int p, int t, double r, int n) { double amount = p * Math.pow(1 + (r / n), n * t); double cinterest = amount – p; System.out.println(“Compound Interest after ” + t + ” years: “+cinterest); System.out.println(“Amount after ” + t + ” years: “+amount); } public … Read more

C Program to find largest element of an Array

#include <stdio.h> largest_element(int arr[], int num) { int i, max_element; max_element = arr[0]; for (i = 1; i < num; i++) if (arr[i] > max_element) max_element = arr[i]; return max_element; } int main() { int arr[] = {1, 24, 145, 20, 8, -101, 300}; int n = sizeof(arr)/sizeof(arr[0]); printf(“Largest element of array is %d”, largest_element(arr, … Read more

C Program to arrange numbers in ascending order

  #include <stdio.h> void sort_numbers_ascending(int number[], int count) { int temp, i, j, k; for (j = 0; j < count; ++j) { for (k = j + 1; k < count; ++k) { if (number[j] > number[k]) { temp = number[j]; number[j] = number[k]; number[k] = temp; } } } printf(“Numbers in ascending order:\n”); … Read more

C program to find the length of a String without using function strlen()

#include <stdio.h> int main() { char str[100],i; printf(“Enter a string: \n”); scanf(“%s”,str); for(i=0; str[i]!=’\0′; ++i); printf(“\nLength of input string: %d”,i); return 0; }  

C Program to calculate Area of Equilatral triangle

#include<stdio.h> #include<math.h> int main() { int triangle_side; float triangle_area, temp_variable; printf(“\nEnter the Side of the triangle:”); scanf(“%d”,&triangle_side); temp_variable = sqrt(3) / 4 ; triangle_area = temp_variable * triangle_side * triangle_side ; printf(“\nArea of Equilateral Triangle is: %f”,triangle_area); return(0); }  

C Program to calculate Area and Circumference of Circle

#include <stdio.h> int main() { int circle_radius; float PI_VALUE=3.14, circle_area, circle_circumf; printf(“\nEnter radius of circle: “); scanf(“%d”,&circle_radius); circle_area = PI_VALUE * circle_radius * circle_radius; printf(“\nArea of circle is: %f”,circle_area); circle_circumf = 2 * PI_VALUE * circle_radius; printf(“\nCircumference of circle is: %f”,circle_circumf); return(0); }