
Delzinho
Membros-
Total de itens
15 -
Registro em
-
Última visita
Sobre Delzinho

Delzinho's Achievements
0
Reputação
-
import java.util. Scanner; class BinarySearch { public static void main main (String args[]) { int c, first, last void main (String args [] ) { int c first, last, middle, n, search, array[]; Scanner in = new Scanner (System in ); System.out. println ("Enter number of elements"); n = in.nextInt(); array = new int [n]; System. out. println ("Enter " + n +" integers"); for (c=0; c < n; c++) array = new. int [n] System.out println ("Enter" + n+" integers"); for (c=0; c < n; c++) array[c] = in nextInt (); System. out.println ("Enter value to find"); search = in.nextInt(); first = 0; last = n-1; middle= (first +last)/2; while (first<= last { if (array[middle] <search) first = middle+ 1; else if (array[middle]== search) { System.out. println (search +" found at location" +(middle +1)+");. break; } else last = middle =( first +last)/2; } if (first > last System.out.println(search+" is not present in the list.\n"); } } Output: Enter numbers of elements 5 Enter 5 integers 2 5 5 8 9 Enter value to find 5 5 found at location 2
-
import java. util Scanner; class Add Two Matrix { public static void main (String args[]) { int m, n, c, d; Scanner in = new Scanner (System.in); System.out. println ("Enter the number of rows and columns of matrix"); m= in nextInt(); n= in nextInt(); int first[] = new int [m][n]; int sum [ ] [ ] = new int [m][n]; System.out.println ("Enter the elements of first matrix"); for (C= 0; c <m; c++ ) for ( d =0; d < n; d++) first [c][d] = in. next Int (); System.out. println (Enter the elements of second matrix") for ( c =0; c< m ; c++) for (d =0 ; d< n ; d++) sum [c][d] = first [c][d] + second [c][d]; // replace '+' with '-' to subtract matrices System. out. println ("Sum of entered matrices:-"); for ( c = 0; c < m; c++) { for ( d = 0; d<n ; d++) System.out print (sum[c][d] +"\t"); System. out. println (); } } } Out put Enter the number of rows and columns of matrix 2 2 Enter the elements of second matrix 4 3 2 1 Sum of entered matrices 5 5 5 5
-
/*HelloWorld.java */ public class Hello world { public class HelloWorld { public static void main (String[] args) { publicstatic void main (String [] args){ System. out.println ("Hello World"); } } Output Hello World!!!
-
Delete vowels #include <stdio.h> #include<string.h> int check_vowel (char); int main () { char s [100], t {100] int i, j=0; printf ("Enter a string to delete vowels\n); gets(s); /* In the program we create a new string and process entered string character by character and if a vowel in found it is foud is not added to new string after the string ends we copy the new string into original string*/ for ( i=0; s != '\0; i++){ if (check _vowel (s)==0 { /*not a vowel */ t [j] = s ; j++; } }
-
Copy string #include <stdio.h> #include<string.h> main () { char source[]= "C program"; char destination [50]; strcpy (destination , source); /* strcpy will copy string from source to destination*/ printf "(Source string %s\n", souche); printf (Destination string: %s\n destination ); return 0; }
-
Binary to Octal #include <stdio.h> int main () { long int binarynum, octalnum=0, j =1, remainder; printf ("Enter the value for binary number:"); scanf ("%d"&binarium; whille (binarium "=0) { remainder = binarynum "=0) { remainder = binarynum %10; octalnum = octalnum+remainder*)j j =j * 2; binarynum = binarynum /10; } printf ("Equivalent octal value: %lo", octalnum); return 0; }
-
Print String #include <stdio.h> int main() { char array [100]; printf ("Enter a string from user") /*%S is used to retrive string from user*/ print ("You entered the string %s\n", array); return 0 }
-
Remove Spaces #include <stdio.h> int main () { char text [100], blank [100] int c= 0, d=0; printf ("Enter some text\n); gets(text); while (text[c]!= '\0') { /*if two consecutives spaces foud then it will not be added to new string*/ if (!(text[c]=='' && text [ c+1]=='')){ blank[d] = text[c]; } c++ } black [d]='\0'; printf ("text after removing blanks \n%s\n", blank); return 0; }
-
Print String #include <stdio.h> int main() { char array [100]; printf (Enter a string \ n); scanf ("%s", array); /* %s is used to retrive string from user*/ printf ("You entered the string %s\n", array); return 0; }
-
Add n Numbers # include < stdio.h> int main () { int n, sum = 0, c, value; printf ("Enter the number of integers you want to add\n"); scanf ("%d",&n); printf ("Enter %d integers \ n", n); for ( c=1; c<=n; c++) { scanf ("%d" &value); sum= sum +value /adding each no in sum*/ } printf ("Sum of entered integers=%d\n", sum); return 0 }
-
Prime Numbers #include <stdio.h> int check_prime (int); main () { int i, n, result printf ("Enter the number of prime numbers required\n"); scanf ("%d, &n); printf ("First %d prime numbers are: \n", n); for (i=0; i<n; i++){ result = check_prime(i) \if i is prime then it will return 1 */ if (result==1) printf ("%d \n", i ); } return 0 } int check _ prime ( int a) { int c; /*starting from 2, if no is completely divisible by any no then it is not prime*/ for ( c=2; c<=a - 1; c++){ { if (a %c ==0) return 0; } if (a%c==0) return 0; } if (c==a ) return 1 }
-
Leap Year # include <stdio.h> int main () { int year; printf ("Enter a year to check if is a leap year\n") scanf ("%d is a leap year. \n", year); else if ( year%100==0 printf ("%d is a leap year. /year); printf ("%d is a leap year.\n", year); else printf ("%d is not a leap year. /n" year); return 0; }
-
Nested If Else #include <stdio.h> void main () { int marks; printf ("Enter your marks:"); scanf ("%d"&marks); if (marks> 100) /*marks greater than 100*/ printf ("Not valid marks"); else if (marks>=80) /*marks between 80 & 99*/ printf ("your grade is B"); else if (marks>=70) /*marks between 70 & 79*/ printf ("your grade is B"); else if (marks >= 50) /*marks between 50 & 69*/ printf (your grade is C" else marks less than 35) printf ( your grade is E"); }
-
PRINT INTEGER #include <stdio.h> int main () { int a; printf ("Enter an Integer \n); scanf ("%d",&a); //takes an integer from user printf ("Integer that you have entered is %d\n",a); return 0 }
-
Vai um exemplo de um programa em C para calcular Porcentagem #include <stdio.h> void main() { int s1, s2, s3,s4,s5, sum, total=500 float per; printf("\n Enter marks of sbjects:"); scanf("%d%d%d%d%d",&s1,&s2&s3,&s4,&s5); sum= s1+s2+s3+s4+s5; printf("\nSum:%d",sum); per=(sum*100)/500; /*percentege :%f",per); } -------------------------------------- Enter Marks of 5 subjects: 09 01 79 85 75 Sum : 409 Percentage : 01.000000000