Sunday, November 7, 2010

Programming C

Programs’ List


1.     Post-increment
2.     Pre-increment
3.     Type casting_1
4.     Type casting_2
5.     A program to determine a Digit or Uppercase Char or        Lowercase Char
6.     Case conversion
7.     Write a program to check whether an integer is even  or odd
8.     Check an integer is divisible by both 5 & 3
9.     Find the Ceiling and Floor value
10.                     Take three integers and sort them
11.                     Use of goto
12.                     Write a program to print two columns
13.                     Find the even numbers from a to b
14.                     Find the numbers from a to b those are divisible by 3
15.                     Sum of the numbers from a to b
16.                     Printing each number from 1 to 10
17.                     Find the factorial of an integer
18.                     Find the L.C.M. of two integers
19.                     Find the G.C.F. of two integers
20.                     Permutation
21.                     Combination
22.                     Split an integer from last to first
23.                     Reverse of an integer
24.                     Fibonacci Series (How many Fibonacci nos. do you want to see?)
25.                     Print a specific Fibonacci number
26.                     Print Fibonacci numbers up to a range
27.                     Check that a number is prime or not
28.                     Print a multiplication-table
29.                     Using of nested for loop (Right Triangle 1)
30.                     Using of nested for loop (Right Triangle 2)
31.                     Using of nested for loop (Right Triangle 3)
32.                     Using of nested for loop (Right Triangle 4)
33.                     Using of nested for loop (Right Triangle 5)
34.                     Using of nested for loop (Right Triangle 6)
35.                     Pyramid 1
36.                     Pyramid 2
37.                     Sum and average using array
38.                     Find sum of odd and even numbers using array
39.                     Draw a circle with sound
40.                     Reversed sum of two reversed numbers
41.                     Triangle wave
42.                     The 3n+1 problem
43.                     String concept
44.                     Find string length with user define function
45.                     Copy a string using for loop
46.                     Concatenation of two strings
47.                     Moving a ball
48.                     Moving a colored ball
49.                     A nice while loop concept
50.                     Another program for Concatenation of two strings
51.                     Playing a sound
52.                     Pyramid 3
53.                     Counting characters, words, vowels and consonants in a text
54.                     Reverse a string
55.                     Find factorial of a number using array
56.                     Sum of two strings
57.                     Find equivalent binary number
58.                     Find equivalent hexadecimal number
59.                     Binary to decimal conversion
60.                     Hexadecimal to decimal conversion
61.                     Base conversion
62.                     Counting the occurrence time of each alphabet
63.                     Concept of atoi function
64.                     Find out a specific prime number
65.                     Prime numbers in a specific range
66.                     Sum of each column in a 2D array
67.                     Making a square matrix into lower triangular matrix
68.                     Pointer concept
69.                     Swap program
70.                     Swapping with pointer
71.                     Array with pointer
72.                     String with pointer
73.                     2D array with pointer

 

                                      Program with If – else if –else and switch

1.      Write a program to check whether an integer is odd or even
2.      Write a program to check whether two integers are even
3.      Write a program to check whether two integers are divisible by 3 or not.
4.      Write a program to check whether an character input is in lowercase or uppercase or digit or other.
5.      Writer a program to convert an uppercase character to it’s lowercase and vice versa.


                                                Programs  With Loops
1.Write a program to find all the even numbers between 1 and 100
2. Write a program to find all the odd numbers between 1 and 100
3. Write a program to find all the numbers whose are divisible by 3
4. Write a program to find all the numbers whose are divisible by both 3 and 5
5.      Write a program to find all the numbers whose are divisible by both 5 or 7
6.      Write a program to find the summation between 1 and n
7.      Write a program to find  the factorial of an integer .
8.      find 1+ x/1! + x2/2! + x3/3! +…….  +  xn/n! (where n and x is taken from keyboard)
9.      find ncr (where n and r is taken from keyboard)

10. find npr (where n and r is taken from keyboard)
11. output
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5 (where n is the input)

12.     output
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5 (where n is the input)

13. output
     1
     2 3
     4 5 6
     7 8 9 10
     11 12 13 14 15 (where n is the input)
   














14. output
1 1 1 1 1
2 2 2 2
3 3 3
4 4
            5  (where n is the input)
15. output
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1  (where n is the input)
16. output
1
         2 2
        3 3 3
       4 4 4 4
     5 5 5 5 5   (n is the input)

17. Find the reverse of an integer ( if input is 1234 the output will be 4321 )

Programs After array and functions
1.      Take 10 integers from keyboard and put them into an array , then add all the integers
2.     Take 10 integers from keyboard and put them into an array ,then find the average of those numbers.
3.     Strlen ( without using strlen.h header file)
4.     Strcat( without using strlen.h header file)
5.     Strcpy( without using strlen.h header file)
6.     Strcmp( without using strlen.h header file)
7.     atoi( without using strlen.h header file)
8.     addition of two strings ( without using strlen.h header file)
9.     Subtraction of two strings
  1. toupper of a string
  2. Find the reverse of a string .
  3. Reverse a string 
  4. Take two integers from keyboard ,reverse them , add the reversed integers and them again reverse the addition ( if two integers  are 15 and 87 , first reverse them 51 and 78 , add them 129 reverse it, 921 , which is the result.

14. Convert a decimal number to it’s equivalent binary number.
15. Convert a decimal number to it’s equivalent octal number.
16. Convert a decimal number to it’s equivalent hexadecimal number.
17. Convert a binary number to it’s equivalent decimal.
18. Find the number of vowel ,consonant  ,white spaces , and words from a             string .




List of Problems to be solved in the Lab (Using Programming Language C)
1
a)      Write a program in to take a floating point number as input and round it off the nearest integer.
b)      Write a program to convert and uppercase character to its lowercase and vice versa.
c)      Write a program to check whether and integer is divisible by 3 and 5 or not.
d)      Write a program to sort three integers.
2
Create the equivalence of four functions calculator. The program will request the user to enter a number, an operator and another number. It should then carry out the specific arithmetic operation: addition, subtraction, multiplication or division of two numbers ( switch should select the operation). Finally display the result.
3
a)      Write a program to calculate the factorial of a given integer using both for loop and while loop
b)      Write a program to calculate the npr.
c)      Write a program to calculate the ncr.
d)      Write a program to find the sum between a and b, where a and b are two integers taken from keyboard.
4
Write a program to take and integer n from keyboard. After that, take n integers and
a)      Find the sum of those integers
b)      Find the number of odd and even integers
c)      Find the sum of even numbers and sum of odd numbers
d)      Find the average of even numbers and average of odd numbers
e)      Find the maximum and minimum among those n numbers
4
a)      Write a program to calculate the sum of digits of and integer.
b)      Write a program to calculate the reverse of an integer.
5
a)      Write a program to check whether and integer is prime or not
b)      Write a program to find the nth Fibonacci number
c)      Find the LCM of two integers
d)      Find the GCD of two integers
6
a)      Write a program to calculate Y, where Y = 1 + x/1 + x2/2! + x3/3! + ….  + xn/n!
b)      Write a program to the first n prime numbers
7
Write a program to take an integer n and show the following outputs ( say n = 5)
a)      1
       1 2
       1 2 3
       1 2 3 4
       1 2 3 4 5
b)      1
       2 2
       3 3 3
       4 4 4 4
             5 5 5 5 5
c)      1
2 1
      3 2 1
      4 3 2 1
            5 4 3 2 1
d)      5
       5 4
       5 4 3
       5 4 3 2
             5 4 3 2 1
e)      5
4 4
       3 3 3
       2 2 2 2
             1 1 1 1 1

f)        1 2 3 4 5
1 2 3 4
1 2 3
1 2
            1
g)      1 1 1 1 1
2 2 2 2
3 3 3
4 4
            5
h)      5 4 3 2 1
5 4 3 2
5 4 3
5 4
            5
i)        5 5 5 5 5
4 4 4 4
3 3 3
2 2
            1
j)        1 2 3 4 5
1 2 3 4
1 2 3
1 2
            1
k)    1   2   3  4  5
6   7   8  9
10 11 12
13 14
15
l)      15 14 13 12 11
            10  9   8   7 
            6    5   4
            3   2
            1
m)             1
2        2
               3    3    3
            4    4    4    4
         5    5    5    5    5
 n)  1  1  1  1  1
        2  2  2  2
          3  3  3
            4  4
              5
8
Write a program to verify the following bit-wise logical (Boolean) operations: AND, OR, NOT, NAND, NOR, EX-OR AND EX-NOR by constructing suitable truth-tables.



9
Write a program to take an integer n, take n numbers from keyboard, store them in an array and
a)      Print the integers in reverse order
b)      Find a particular integer from the array using Binary Search and inform the number of comparison
c)      Reverse the array without using any second array
10.
Write a program to take an integer n, take n numbers from keyboard , store them in an array and sort them using
a)      Bubble sort
b)      Replacement Sort
c)      Insertion sort
d)      Merge sort
e)      Quick Sort
11.
Write a program to convert a decimal number into its equivalent Octal, binary and hexadecimal number.
12.
Write a program to add, subtract, and multiply two matrixes.
13.
Write a program to take a string and find the number of following items from the string:
a)      no of alphabets
b)      no of uppercase characters
c)      no of lowercase characters
d)      no of vowels
e)      no of consonants
f)        no of digits
g)      no of punctuation characters
14.
Write a program to take two strings ( A and B) and finding a substring (B) from the first string (A)
15.
Write a program to create the following functions ( don’t use string.h header file)
a)      strlen
b)      strcmp
c)      strcpy
d)      strcat
e)      strrev
f)        strncmp
g)      strncpy
See the string. h header file for their descriptions.
16.
Write a program to take n strings (array of strings, two dimensional arrays of characters) and sort them lexicographically using any of the sorting algorithms.
17.
Write a program to take two strings A and B and perform
a)      Addition
b)      Subtraction
c)      Multiplication
18.
Write a program to take n strings of same length and find a substring in any order.














Program of average of  n numbers
 


#include
char input[1000];
float temp; /* temporary storage for numbers entered */
int num_count; /* number to divide total by */
float total; /* Total of numbers entered */
float average; /* 'total' divided by 'num_count' */

int main()
{
/* Tell user what program does */
printf("I will find the average of however many numbers you enter.\n");
printf("Enter number now (00 to quit): ");

/* Accept first input from user */
fgets(input, sizeof(input), stdin);
temp = atof(input);

/* Initalize Variables */
num_count = 0;
total = 0.0;
average = 0.0;

while ( temp != 00.0 ) {
++num_count; /* increases with each number entered */
total += temp; /* adds all numbers entered to total */

printf("Enter next number now (00 to quit): ");
fgets(input, sizeof(input), stdin);
temp = atof(input);
}
average = ( total / num_count );
printf("You entered %d numbers. The average of those numbers is %f.\n", num_count, average);

return 0;
}

Program for Prime Number Generation

#include
main()
{
         int n,i=1,j,c;
         clrscr();
         printf("Enter Number Of Terms
");
         printf("Prime Numbers Are Follwing
");
         scanf("%d",&n);
         while(i<=n)
         {
            c=0;
            for(j=1;j<=i;j++)
            {
              if(i%j==0)
                  c++;
             }
           if(c==2)
           printf("%d    ",i)
           i++;
        }
        getch();
}

No comments:

Post a Comment

Total Pageviews