C language interview questions solution for freshers beginners placement tricky good pointers answers explanation operators data types arrays structures functions recursion preprocessors looping file handling strings switch case if else printf advance linux objective mcq faq online written test prime numbers Armstrong Fibonacci series factorial palindrome code programs examples on c++ tutorials and pdf

#include int main(void) { int pri, sec, i, v; int arr[] = {4,10,3,8,6,7,2,7,9,2,0}; pri = sec = 0; for (i = 0; arr[i]; ++i) { v = arr[i]; if (v > pri) sec = pri, pri = v; if (v > sec && v < pri) sec = v; } printf("pri is %d, sec is %d\n", pri, sec); return 0; }

please send me simple programming learning tips in c on (cv.welcome.cv@gmail.com). also write me to contact you thorugh my id. i also have some querries regarding programming in c. therefore, i request you to accept my request again.

For second largest element of an array go through the following link: http://cquestionbank.blogspot.com/2008/01/write-c-program-to-find-second-largest.html

# include main() { int i,j,x[200],n; printf ( "\n Enter numbers of element " ); scanf ( "%d",&n ); for ( i=0; i j ) { j=x[i]; } } printf ( "The answer is %d " ,j ); }

Say 1st element is biggest one...... Now big contains 1st element ... Now it compares 2nd element with big and if it is greater it stores dat element else 1st element is biggest... Again 3rd element is compared to big....then 4th....so on....until all are compared then biggest is printed....

// print the values between 100 to 200 that are divisible by 7

#include int main(){ int vector[100]={};//all elements are 0 int i=0;//first position of the array int no; int j; for(no=100;no<=200;no++) if(no%7==0){ vector[i]=no;//we start putting the elements in the array, we start at element 0(i=0) i++;//then we move to the next position } printf("The array:\n"); for(j=0;j<=i-1;j++) printf("%d ", vector[j]); printf("\n"); return 0; }

#include int main() { int t; scanf("%d",&t); int a[t]; int i=0,j=0,k,l; for(i=0;ia[i]){ k=a[i]; a[i]=a[j]; a[j]=k; } } } printf("%d",a[1]); }

this is code to get 2nd biggest number... to try my code , follow these rules:- * first enter the number, total numbers you want to enter; * enter all number with gap of space or new line; after you enter all number you will get second largest number...

here is another code to know n th biggest number...

#include int main() { int t; scanf("%d",&t); int a[t]; int i=0,j=0,k,l; for(i=0;ia[i]){ k=a[i]; a[i]=a[j]; a[j]=k; } } } scanf("%d",&l); printf("%d",a[l-1]); }

*enter hoe many numbers you want to enter * enter total numbers * enter n, to know nth biggest number

#include int main() { int t; scanf("%d",&t); int a[t]; int i=0,j=0,k,l,m=0; for(i=0;ia[i]){ k=a[i]; a[i]=a[j]; a[j]=k; } } } l=a[0]; for(i=0;i<t;i++){ if(l==a[i]){ m++; } } printf("maximum number is %d and it was entered %d times",l,m); }

#include int main(void) { int sum=0,a[4],i,j,max=0; printf("Enter the 10 numbers\n"); for(i=0;i<4;i++){ scanf("%d\n",&a[i]); } printf("The sum of 10 numbers is "); for(i=0;i<4;i++){ sum=sum+a[i];} printf("%d\n",sum);

void main() { int n,a[10],i,min; printf("enter the no of array elements"); scanf("%d",&n); for(i=0;ia[i]) { max=a[i]; } } printf("the max is%d",&max); }

## 42 comments:

Dude this is for LARGEST....

and NOT for SECOND LARGEST....

give a short code for SECOND LARGEST..

Go through the following link to fiind out second largest element of an array:

http://cquestionbank.blogspot.com/2008/01/write-c-program-to-find-second-largest.html

find the largest number in an array in c which is equals to zero

#include

int main(void) {

int pri, sec, i, v;

int arr[] = {4,10,3,8,6,7,2,7,9,2,0};

pri = sec = 0;

for (i = 0; arr[i]; ++i) {

v = arr[i];

if (v > pri) sec = pri, pri = v;

if (v > sec && v < pri) sec = v;

}

printf("pri is %d, sec is %d\n", pri, sec);

return 0;

}

why u took big=a[0]??? i m nt able to undrstnd please explain......

please send me simple programming learning tips in c on (cv.welcome.cv@gmail.com).

also write me to contact you thorugh my id. i also have some querries regarding programming in c.

therefore, i request you to accept my request again.

shivee kant singh

thanks.

big=a;

if(big<b) big=b;

if(big<c) big=c;

printf("%d",big);

please explain and want o/p..if i tried oly it ll display the biggest no...want to know the second largest no.....how to get the second largest no...

plz explain soon

For second largest element of an array go through the following link:

http://cquestionbank.blogspot.com/2008/01/write-c-program-to-find-second-largest.html

# include

main()

{

int i,j,x[200],n;

printf ( "\n Enter numbers of element " );

scanf ( "%d",&n );

for ( i=0; i j )

{

j=x[i];

}

}

printf ( "The answer is %d " ,j );

}

HEy can anybody tell me why this program not running . is anything done wrong?

#include

#include

void main()

{

int a[3][3];

int i,j;

printf("enter the elements of an 3X3 array:\n");

for (i=0;i<3;i++)

{

for (j=0;j<3;j++)

{

scanf(" %d",a[i][j]);

}

}

for (i=0;i<3;i++)

{

printf("\n");

for (j=0;j<3;j++)

{

printf(" %d",a[i][j]);

}

}

getch();

}

I think you have missed the & in scanf statement.

Replace scanf(" %d",a[i][j]); by

scanf(" %d",&a[i][j]);

I hope this will help you.

Can you show a code on how to find the largest value in an array and how many times it was entered?. Tnx

Say 1st element is biggest one......

Now big contains 1st element ...

Now it compares 2nd element with big and if it is greater it stores dat element else 1st element is biggest...

Again 3rd element is compared to big....then 4th....so on....until all are compared then biggest is printed....

some one help me.. to print the values between 100 t0 200 that are divisible by 7.. using for loop to input the value using array concept..

cout<<"Enter the values";

cin>>a>>b>>c;

if(a>b)

{

if(a>c)

{

m=a;

}

else

{

m=c;

}

}

else

{

if(b>c)

{

m=b;

}

else

{

m=c;

}

}

j=0;

for(i=m;i>=2;i--)

{

if(a%i==0 && b%i==0 && c%i==0)

{

j++;

break;

}

}

if(j==0)

cout<<"GCD is 1";

else

cout<<"GCD is"<<i;

getch();

// print the values between 100 to 200 that are divisible by 7

#include

int main(){

int vector[100]={};//all elements are 0

int i=0;//first position of the array

int no;

int j;

for(no=100;no<=200;no++)

if(no%7==0){

vector[i]=no;//we start putting the elements in the array, we start at element 0(i=0)

i++;//then we move to the next position

}

printf("The array:\n");

for(j=0;j<=i-1;j++)

printf("%d ", vector[j]);

printf("\n");

return 0;

}

can any1 Write a c program to find the second highest number from a set of numbers.

Q13 Write a program that adds up two 4x4 arrays and stores the sum in third array.

can any one of you solve this programme

thanks

not bad bro..

while reading the elements u have not used & in scanf,so the elements are getting stored, correct it as:

scanf(" %d",&a[i][j]);

is this right way to find largest element...?

static int max(int arr[])

{

int i;

for(i=0;iarr[i+1])

{

int temp=arr[i];

arr[i]=arr[i+1];

arr[i+1]=temp;

}

}

int mx=arr[i];

return mx;

}

pls explain this program

#include

#include

void main()

{

int a[30],i,n,largest;

printf("n Enter no of elements :");

scanf("%d",&n);

/* read n elements in an array */

for(i=0 ; i < n ; i++)

scanf("%d",&a[i]);

largest = a[0];

for(i = 0;i largest )

largest = a[i];

}

/* Print out the Result */

printf("nLargest Element : %d",largest);

getch();

}

#include

int main()

{

int t;

scanf("%d",&t);

int a[t];

int i=0,j=0,k,l;

for(i=0;ia[i]){

k=a[i];

a[i]=a[j];

a[j]=k;

}

}

}

printf("%d",a[1]);

}

this is code to get 2nd biggest number...

to try my code , follow these rules:-

* first enter the number, total numbers you want to enter;

* enter all number with gap of space or new line;

after you enter all number you will get second largest number...

here is another code to know n th biggest number...

#include

int main()

{

int t;

scanf("%d",&t);

int a[t];

int i=0,j=0,k,l;

for(i=0;ia[i]){

k=a[i];

a[i]=a[j];

a[j]=k;

}

}

}

scanf("%d",&l);

printf("%d",a[l-1]);

}

*enter hoe many numbers you want to enter

* enter total numbers

* enter n, to know nth biggest number

thats it...

#include

int main()

{

int t;

scanf("%d",&t);

int a[t];

int i=0,j=0,k,l,m=0;

for(i=0;ia[i]){

k=a[i];

a[i]=a[j];

a[j]=k;

}

}

}

l=a[0];

for(i=0;i<t;i++){

if(l==a[i]){

m++;

}

}

printf("maximum number is %d and it was entered %d times",l,m);

}

No i can not solve it.

we need pleas solve this Q13.

Compute the sum of 10 numbers and the largest number should be printed on the monitor

Can anyone tell me the code

#include

int main(void)

{

int sum=0,a[4],i,j,max=0;

printf("Enter the 10 numbers\n");

for(i=0;i<4;i++){

scanf("%d\n",&a[i]);

}

printf("The sum of 10 numbers is ");

for(i=0;i<4;i++){

sum=sum+a[i];}

printf("%d\n",sum);

max=a[0];

for(i=1;i<4;i++){

if(a[i]>max){

max=a[i];

}}

printf("Largest number is %d\n",max);

}

--

can anyone tell me the code to print the following structure

1

3 5

7 9 11

can anyone tell me the code to print the following structure

1

3 5

7 9 11

can any one tell me the flow chart to find 2nd largest number without using array and string

can anybody tell me the c program to find the maximum of n numbers without storing them into an array. plz..

can anybody tell me the c program to find the maximum of n numbers without storing them into an array. plz..

Q.make an array and write a program that find a maximum number from that the array ? how to solve any 1 help this program. .. ?

void main()

{

int n,a[10],i,min;

printf("enter the no of array elements");

scanf("%d",&n);

for(i=0;ia[i])

{

max=a[i];

}

}

printf("the max is%d",&max);

}

What is question is create a program using a 3x3 array to input integer number. Get the sum in horizontal and vertical manne.

sample output:

1 2 3 = 6

4 5 1 = 10

2 3 4 = 9

7 10 8 =

Please input?

Nice way to find element in array. there is also good way to find element in array Find max element in array

Post a Comment