#include<stdio.h>
int main(){
int a[20],i,j,n,c=0,loc;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&a[i]);
}
scanf("%d",&j);
for(i=0;i<n;i++){
if(a[i]==j){
c=1;
loc=i+1;
break;
}
}
if(c==1){
printf("Element found at position %d",loc);
}
else
printf("Element not found");
return 0;
}
Codepadma
Play with Codes
Monday, April 20, 2015
C program to implement Linear Search
Friday, October 18, 2013
Java Program to generate a random number with output
Java Program to test whether a given year is a leap year or not
Code:-
import java.util.Scanner;class Leap{
public static void main(String args[]){
System.out.println("Enter year");
Scanner s=new Scanner(System.in);
int a=s.nextInt();
if((a%100)==0){
if((a%400)==0)
System.out.println(a+" is a century year and a leap year too");
else
System.out.println(a+" is a century year");
}
else{
if((a%4)==0)
System.out.println(a+" is leap year ");
else
System.out.println(a+" is not a leap year");
}
}
}
Output:-
Monday, October 14, 2013
Java Program to read text using readline function
import java.io.*;
class Read{
public static void main(String args[]) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str;
System.out.println("Enter text \n stop to terminate" );
do{
str= br.readLine();
System.out.println(str);
}
while(str.equals("Stop"));
}
}
class Read{
public static void main(String args[]) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str;
System.out.println("Enter text \n stop to terminate" );
do{
str= br.readLine();
System.out.println(str);
}
while(str.equals("Stop"));
}
}
Friday, September 27, 2013
C++ Program using nested if else
Saturday, September 21, 2013
Java program to create a frame using Swing
Tuesday, September 17, 2013
C++ Program to multiply two matrices with Output
Program
#include<iostream>
using namespace std;
int main(){
int i,j,a[3][3],b[3][3],c[3][3];
cout<<"Enter first matrix";
for(i=0;i<3;i++){
for(j=0;j<3;j++){
cin>>a[i][j];
}
cout<<endl;
}
cout<<"Enter second matrix";
for(i=0;i<3;i++){
for(j=0;j<3;j++){
cin>>b[i][j];
}
cout<<endl;
}
for(i=0;i<3;i++){
for(j=0;j<3;j++){
c[i][j]=a[i][j]*b[i][j];
}
}
for(i=0;i<3;i++){
for(j=0;j<3;j++){
cout<<c[i][j]<<" ";
}
cout<<endl;
}
return 0;
}
Output:-
Subscribe to:
Posts (Atom)