Sunday, 31 October 2010

C program to find the second largest element in an array

C program to find the second largest element in an array



#include<stdio.h>
int main(){
  int a[50],size,i,j=0,big,secondbig;
  printf("Enter the size of the array: ");
  scanf("%d",&size);
  printf("Enter %d elements in to the array: ", size);
  for(i=0;i<size;i++)
      scanf("%d",&a[i]);

  big=a[0];
  for(i=1;i<size;i++){
      if(big<a[i]){
           big=a[i];
           j = i;
      }
  }

  secondbig=a[size-j-1];
  for(i=1;i<size;i++){
      if(secondbig<a[i] && j != i)
          secondbig =a[i];
  }
 
  printf("Second biggest: %d", secondbig);
  return 0;
}

Sample output:
Enter the size of the array: 5
Enter 5 elements in to the array: 5 3 2 1 0
Second biggest: 3

C Program to find the first capital letter in a string using recursion

1. /*
2. * C Program to find the first capital letter in a string using
3. * Recursion
4. */
5. #include <stdio.h>
6. #include <string.h>
7. #include <ctype.h>
8.
9. charcaps_check(char*);
10.
11. int main()
12. {
13. char string[20], letter;
14.
15. printf("Enter a string to find it's first capital letter: ");
16. scanf("%s", string);
17.    letter =caps_check(string);
18. if(letter ==0)
19. {
20. printf("No capital letter is present in %s.\n", string);
21. }
22. else
23. {
24. printf("The first capital letter in %s is %c.\n", string, letter);}
25. return0;
26. }
27. charcaps_check(char*string)
28. {
29. staticinti=0;
30. if(i<strlen(string))
31. {
32. if(isupper(string[i]))
33. {
34. return string[i];
35. }
36. else
37. {
38. i=i+1;
39. returncaps_check(string);
40. }
41. }
42. elsereturn0;
43. }

output:

Enter a string to findit's first capital letter: iloveC
The first capital letter in iloveC is C.

program on Recursive Length of String

// Recursive Length of String
#include <stdio.h>
#include <string.h>

intgetlength (const char *);

int main ()
{
char text [] = "Hello, World";

printf ("String: %s\nLength: %d\nStrlen: %d\n\n", text, getlength (text), strlen (text));

return 0;
}

intgetlength (const char * s)
{
if (s == NULL || *s == '\0')
return 0;
else
return 1 + getlength (s + 1);
}

C Programs

                                                       C Tokens

swap values of two variables
find simple interest and compound interest

                                                        Operators


Relational Operators: Example program on Relational Operators
logical operators: Example programs on Logical Operators 
Example program for comma operator in for loop


Conditional Statements:

If condition

WAP to find whether a given year is leap or not?

If -Else

write a program to find the average, grade of the 3 subjects using if ..else 
Program To find the roots of the quadratic equation

Else if

Write a program find largest of 3 no's using else– if statement


Switch Statements : Example program on switch statements
Demonstration on switch statement 
C program on quadratic equation by using switch statement
Evaluate an expression like caliculator
Write a program to find the average, grade of the 3 subjects using switch case
Find the areas of circle, square, rectangle
Write a c program to print Hello world without using any semicolon


Unconditional Statements

Write a program using any unconditional statements

continue
Example program on continue statement
Write a C program to find the product of 4 integers entered by a user. If user enters 0 skip it.
Or
Program to demonstrate the working of continue statement in C programming 


break

Example program on break statement


goto

return

                                           
                                                           Loops
For loops

Simple program on for loop

Program to generate the tables using loops
Program to find the sum of first n natural numbers
Program to find out 1.1+2.2+3.3+...n
C program for print the *'s in the following format
Program for To construct a pyramid of numbers

Do-While Loop

Simple example program on do while loop
Find the value of sin(x) using the series up to the given accuracy

Functions


Storage Classes
Write a program ATM money dispatch count while currencies are 1000,500 and 100 using if..else and global variable.


                                                           Pointers




Pointers: C program for addition for two numbers using Pointers
Pointers comparison
Write a program to show same pointer can point to different data variables in different statements
Example program on Pointer array
Example program on Void pointer 
Example program on pointer to pointer
Printing character Array using pointers
Printing character Array using pointers with puts function
Write a program to read the address
Example program on Dangling pointer
Example program on wild pointer

                                                                           Arrays

1 D Array:
1D Array: Example program on array
Program on 1- D array Initialisation
Write a program to find the 2nd Largest and 2nd smallest value
Write a program to delete the particular value from the list
Write a program to perform Cyclically permute the elements of an array


function for searching element in an array with position and also display duplicate values in c

2 D Array:


Wap to bubble sort
Matrix multiplication or product of a matrix or Matrix multiplication 
Transpose of a matrix
Wap to read an 2d array and display 

                                                                  Strings:

C Program To Count the Occurence of a Substring in String
Program on Recursive Length of String
Check if a string is a subsequence of another string
C Program to find the first capital letter in a string using recursion
C program to find the second largest element in an array
Program for Functions to insert a sub string into given main string from a given position
Program for To delete n characters from a given position in a given string
Program for To determine if the given string is a palindrome or not
Program that displays the position or index in the string S where the string T begins , or -1 if S doesn’t contain T
Program for To convert the given binary number to its 2’s complement
Program for To convert roman number to it’s decimal equivalent
character handling functions: Example program on character handling functions
Example programs on string handling functions
How do you compare two strings?

                                                       Structures:


Program for To read the two complex numbers and perform the addition and multiplication of these two numbers.
Structures: Program on simulate the     multiplication of fractions using Structures

Structures: Write a program to simulate the time using 'structures'

Structures: Write a program to sort an array of student using Structures



                                                              Unions





Enumerations 

 
                                                                      Files:


Write a file program explain the data stored on the disk is read
Program which copies one file to another
Program To reverse the first n characters in afile
Program To display the contents of a file
Program To merge the contents of two files into a third file
Copy a text file of integers.
Files: Demonstrate reading names from a file.
Files: This program creates a text file from the keyboard.
Files: Create a grades file for transmission to Registrar.
Files: Example program on fopen() and fclose() functions
Files: Example program on fprintf()
Files: Read a text file of integers, and print the contents.


C Graphics