SlideShare a Scribd company logo
1 of 24
qwertyuiopasdfghjklzxcvbnmq
wertyuiopasdfghjklzxcvbnmqw
ertyuiopasdfghjklzxcvbnmqwer
                C Programming File
tyuiopasdfghjklzxcvbnmqwerty
      PROGRAMMING AND PROBLEM SOLVING THROUGH
                    C LANGUAGE
uiopasdfghjklzxcvbnmqwertyui
opasdfghjklzxcvbnmqwertyuiop
                   SHERIL SHARMA


asdfghjklzxcvbnmqwertyuiopas
dfghjklzxcvbnmqwertyuiopasdf
ghjklzxcvbnmqwertyuiopasdfgh
jklzxcvbnmqwertyuiopasdfghjkl
zxcvbnmqwertyuiopasdfghjklzx
cvbnmqwertyuiopasdfghjklzxcv
bnmqwertyuiopasdfghjklzxcvbn
mqwertyuiopasdfghjklzxcvbnm
qwertyuiopasdfghjklzxcvbnmq
wertyuiopasdfghjklzxcvbnmqw
ertyuiopasdfghjklzxcvbnmrtyui
Index
P1. Program to print a sentence in output screen…………………………………………………………………………………………………………………… 2
P2. Program to enter two numbers and check which one is greater……………………………………………………………………………………….. 2
P3. Program to add two integers…………………………………………………………………………………………………………………………………………….. 3
P4. Program for showing one integer value, float value and character constant on output screen…………………………………………. 3
P5. Program to input a number and check whether it is even or odd………………………………………………………………………………………. 4
P6. Program to print the following pattern………………………………………………………………………………………………………………………………. 4
*
**
***
****
*****
P7. Program to print name 5 times using while loop………………………………………………………………………………………………………………… 5
P8. Program to print sum of first 10 integers using while loop…………………………………………………………………………………………………. 5
P9. Program to find out the roots of quadratic equation………………………………………………………………………………………………………….. 6
P10. Program to print the following pattern…………………………………………………………………………………………………………………………….. 7
1
23
456
7 8 9 10
11 12 13 14 15
P11. Program to print the following pattern…………………………………………………………………………………………………………………………….. 7
0
01
012
0123
01234
P12. Program to print the Fibonacci series to n number of places……………………………………………………………………………………………. 8
P13. Program to display marks of 5 students……………………………………………………………………………………………………………………………. 9
P14. Program to find average and sum of marks obtained by a class of 5 students…………………………………………………………………. 10
P15. Program to print a string…………………………………………………………………………………………………………………………………………………. 11
P16. Program to print the length of the string…………………………………………………………………………………………………………………………. 11
P17. Program to print the reverse of the string……………………………………………………………………………………………………………………….. 12
P18. Program to write input marks of 5 subjects and calculate the percentage………………………………………………………………………. 13
P19. Program to input the time and print the day time…………………………………………………………………………………………………………… 14
P20. Program to print factorial of a number……………………………………………………………………………………………………………………………. 14
P21. Write a program to accept three sides of a triangle and transfer them to a function to compute the area of a triangle….. 15
P22. Write a program to find average male and female height in the class……………………………………………………………………………… 16
P23. Write a program to accept a character and determine whether it is an alphabet, character or special symbol……………….. 17
P24. Program to print out powers of 2: 1, 2, 4, 8..up to 2^N……………………………………………………………………………………………………. 18
P25. Program to swap two numbers without a third variable………………………………………………………………………………………………….. 19
P26. Calculate Electricity Bill with if-else condition………………………………………………………………………………………………………………….. 20
P27. Program to print the alphabet set a to z and A to Z in decimal form and character form…………………………………………………. 21
P28. Program to print area of circle…………………………………………………………………………………………………………………………………………. 22
P29. Program to print the address of a variable along with its value……………………………………………………………………………………….. 22
P30. Program to read a series of words from a terminal using scanf function ……………………………………………………………………….. 23
P1. Program to print a sentence in output screen.
#include <stdio.h>

#include<conio.h>
void main()

{

clrscr();
printf("My name is Sheril");

getch();

}


Output:
My name is Sheril




P2. Program to enter two numbers and check which one is
greater.
#include<stdio.h>

#include<conio.h>

void main()

{

clrscr();

int a,b;

printf("Enter two numbers: ");

scanf(%d%d",&a,&b);

if(a>b)

{

printf("a is        greater than b");

printf("na is less than b");

}

getch();

}


Output:
Enter two numbers : 3 5

a is less than b


                                                          2
P3. Program to add two integers.
#include<stdio.h>

#include<conio.h>
void main()

{

clrscr();
int a,b,c;

printf("Enter an integer: ");

scanf("%d",&a);

printf("nEnter another integer: ");

scanf("%d",&b);

c=a+b;
printf("The sum of the two integers is: ");

printf("c=%d",c);

getch();
}


Output:
Enter an integer: 3

Enter another integer: 5

The sum of the two integers is: 8




P4. Program for showing one integer value, float value and
character constant on output screen.
#include<stdio.h>                             printf("Character Constant =%c",c);

#include<conio.h>                             getch();
void main()                                   }

{

clrscr();                                     Output:
                                              Interger Value =5
int a=5;

float b=8.5;                                  Float Value =8.5

char c='A';                                   Character Constant =A
printf("Interger Value =%d",a);

printf("Float Value =%f",b);

                                                                                    3
P5. Program to input a number and check whether it is
even or odd.
#include<stdio.h>

#include<conio.h>

void main()

{

clrscr();

int n;

printf("nEnter a number: ");

scanf("%d",&n);

if(n%2==0)
{

printf("Number is even");

}

else

printf("Number is odd");

getch();

}


Output:
Enter a number: 2 (or 3)

Number is even (or Number is odd)




P6. Program to print the following pattern
*
**
***
****
*****

         #include<stdio.h>          for(j=1;j<=i;j++)

         #include<conio.h>          printf("*");

         Void main()                printf("n");
         {                          }

         int i,j;                   getch();

         for(i=1;i<=5;i++)          }

         {


                                                        4
P7. Program to print name 5 times using while loop.
#include<stdio.h>

#include<conio.h>
void main()

{

clrscr();
int i=1;

while(i<=5)

{

printf("My name is Sheriln");

i++;

}
getch();

}


Output:
My name is Sheril

My name is Sheril

My name is Sheril

My name is Sheril

My name is Sheril




P8. Program to print sum of first 10 integers using while
loop.
#include<stdio.h>                        sum+=a;
#include<conio.h>                    }    printf("The sum is %d,sum);

void main()                      getch();

{                                }
int a=0, sum=0;

    while(a<10)                  Output:
                                 The sum is 55
    {

        a++;




                                                                        5
P9. Program to find out the roots of quadratic equation.
#include<stdio.h>

#include<conio.h>
#include<math.h>

Void main()

{
    int a,b,c;

    float dis,root1,root2;

    printf("nEnter values of a,b and c: ");

    scanf("%d%d%d",&a,&b,&c);

    dis=(b*b)-4*a*c;

    printf("ndis=%f",dis);
    root1=-b+sqrt(dis)/2.0*a;

    root2=-b-sqrt(dis)/2.0*a;

    if(dis<0)
      {

           printf("nThe roots are imaginary");

      }
    else if(dis==0)

      {

           printf("nThe roots are equal and real");
      }

    else

      {

           printf("nThe roots are real and distinct");

           printf("nThe roots are %f%f",root1,root2);

      }
    getch();

}




Output:
Enter values of a,b and c: 4 2 1

The roots are imaginary




                                                           6
P10. Program to print the following pattern
1
23
456
7 8 9 10
11 12 13 14 15

#include<stdio.h>

#include<conio.h>

Void main()
{

    int i,j,var=1;

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

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

           {

               printf("%d ",var);

               var+=1;

           }

          printf("n");

      }

    getch();
}




P11. Program to print the following pattern
0
01
012
0123
01234

#include<stdio.h>                   {

#include<conio.h>                   printf("%d",j);

Void main()                         }

{                                   printf("n");

int i,j;                            }

for(i=0;i<=5;i++)                   getch();

{                                   }

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



                                                      7
P12. Program to print the Fibonacci series to n number of
places
#include<stdio.h>

#include<conio.h>

Void main()

{

int a=-1,b=1,c=0,n;

printf("Enter the number of places: ");

scanf("%d",&n);

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

{
c=a+b;

printf("%d ",c);

a=b;

b=c;

}

getch();

}


Output:
Enter the number of places: 10

0 1 1 2 3 5 8 13 21 34 55




                                                            8
P13. Program to display marks of 5 students.
#include<stdio.h>

#include<conio.h>
main()

{

int marks[5];
int i=1;

for(i=1;i<=5;i++)

{

printf("nEnter marks of student %d: ",i);

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

}
printf("nThe marks of 5 students are: ");

for(i=1;i<=5;i++)

{
printf("%d ",marks[i]);

}

getch();
}


Output:
Enter marks of student 1: 12

Enter marks of student 2: 13

Enter marks of student 3: 14

Enter marks of student 4: 10

Enter marks of student 5: 15

The marks of 5 students are: 12 13 14 10 15




                                               9
P14. Program to find average and sum of marks obtained by
a class of 5 students.
#include<stdio.h>

#include<conio.h>

Void main()

{

    int avg,sum=0;

    int i,marks[5];

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

     {

         printf("nEnter the marks: ");
         scanf("%d",&marks[i]);

     }

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

    sum=sum+marks[i];

    avg=sum/5;

    printf("nAverage marks are: %dn",avg);

    getch();

}




Output:

Enter the marks: 10

Enter the marks: 12

Enter the marks: 14

Enter the marks: 15

Enter the marks: 12

Average marks are: 12




                                                       10
P15. Program to printa string.
#include<stdio.h>

#include<conio.h>
#include<string.h>

void main()

{
int c;

char name[20];

printf("Enter the name");

gets(name);

printf("The name entered is");

printf("%s",name);
getch();



}


Output:
Enter the name John Smith

The name entered is John Smith




P16. Program to print the length of the string.
#include<stdio.h>                          c=strlen(name);
#include<conio.h>                        printf("nThe length of the string is:
                                       %d",c);
#include<string.h>
                                           getch();
void main()
                                       }
{

    int c;
                                       Output:
    char name[20];                     Enter the name: Sheril
    printf("Enter the name: ");
                                       The name entered is: Sheril
    gets(name);
                                       The length of the string is: 6
    printf("The name entered is: ");

    printf("%s",name);




                                                                             11
P17. Program to print the reverse of the string.
#include <stdio.h>

#include <string.h>
#include <conio.h>

void main()

{
    char str[100], rstr[100];

    int i,k;

    printf("Enter the string to reverse=>");

    gets(str);

    for (i=strlen(str)-1,k=0; i>=0; i--,k++)

     {
         rstr[k]=str[i];

     }

    rstr[k]='0';
    printf("string <%s> reverse <%s>n",str,rstr);

    getch();

}


Output:
Enter the string to reverse=> This is a sample string

string < This is a sample string> reverse <gnirts elpmas a si sihT >




                                                                       12
P18. Program to write input marks of 5 subjects and
calculate the percentage.
#include<stdio.h>

#include<conio.h>

void main()

{

int a,b,c,d,e;

    float p;

    printf("nEnter the marks of 5 subjects: ");

    scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);

    p=(a+b+c+d+e)/5;
    printf("nThe percentage is: ");

    printf("%fnn",p);

    if(p>=60)

      printf("Ist division");

    else if(p<=59&&p>=50)

      printf("Second division");

    else if(p<=49&&p>=40)

      printf("Third division");

    else

      printf("Fail");

    getch();

}




Output:
Enter the marks of 5 subjects: 85 75 65 89 96

The percentage is: 82.000000

Ist division




                                                      13
P19. Program to input the time and print the day time
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int t;
printf("Enter the time in 24 hours clock formatn");
scanf("%d",&t);
if(t==0)
printf("It is midnightn");
else
if(t>0 && t<400)
printf("The time is after midnight and not yet morningn");
else
if(t>=400 && t<700)
printf("It is early morning");
else
if(t>=700 && t<1200)
printf("It is morning");
else
if(t==1200)
printf("It is exact afternoon");
else
if(t>1200 && t<300)
printf("It is afternoon");
else
if(t>=300 && t<=700)
printf("It is evening");
else
printf("It is Night");
getch();
}



Output:
Enter the time in 24 hours clock format

400

It is early morning




P20. Program to print factorial of a number.
#include<stdio.h>                                       n--;

#include<conio.h>                                  }

void main()                                       printf("The factorial is: %d",fact);
{                                                 getch();

    int fact=1,i=1,n;                         }

    printf("Enter the number:n");

    scanf("%d",&n);                           Output:
                                              Enter the number:
    while(n!=i)

      {                                       5

          fact=fact*n;                        The factorial is: 120
                                                                                         14
P21. Write a program to accept three sides of a triangle and
transfer them to a function to compute the area of a
triangle
#include <stdio.h> /*header file*/

#include <conio.h> /*header file*/
#include <math.h>

int main() /*main function*/

{
float tri_area(float a,float b, float c); /* new function*/

float s1;

float s2;

float s3;

float area;

printf("nEnter the three sides of a triangle");

scanf("%f%f%f",&s1,&s2,&s3);

area=tri_area(s1,s2,s3);

printf("n Area of triangle is : %f square units.", area); /*printing area*/

_getch();

}

float tri_area(float a,float b,float c)

{

float s;

float area;

s=(a+b+c)/2;

area=sqrt(s*(s-a)*(s-b)*(s-c)); /*heron’s formula*/

return(area);

}




Output:
Enter the three sides of a triangle 12 14 16

Area of triangle is : 81.332649 square units.




                                                                               15
P22. Write a program to find average male and female
height in the class
#include<stdio.h> /*header file*/    ftot+=fh[count];

#include<conio.h>                    }

int main() /*main function*/         favg+=ftot/5; /*Formula to find
                                     average*/
{
                                     printf("nThe average male height is
float mavg=0, favg=0;                %f",mavg);

int mh[5], fh[5], count;             printf("nThe average female height is
                                     %f",favg);
float mtot; float ftot;
                                     getch();
mtot=0,ftot=0;
                                     }
for(count=0;count<5;count++) /*for
loop*/

{
printf("nEnter the height of        Output:
%d",count+1);                        Enter the height of 1 male: 5
printf(" male: ");                   Enter the height of 2 male: 6
scanf("%d",&mh[count]);              Enter the height of 3 male: 5
mtot+=mh[count];                     Enter the height of 4 male: 6
}                                    Enter the height of 5 male: 6
mavg=mtot/5;                         Enter the height of 1 female: 5
printf("n");                        Enter the height of 2 female: 5
for(count=0;count<5;count++) /*for   Enter the height of 3 female: 6
loop*/
                                     Enter the height of 4 female: 5
{
                                     Enter the height of 5 female: 6
printf("nnEnter the height of
%d",count+1);                        The average male height is 5.600000
printf(" female: ");                 The average female height is 5.400000
scanf("%d",&fh[count]);




                                                                              16
P23. Write a program to accept a character and determine
whether it is an alphabet, character or special symbol
#include<stdio.h> /*header file*/

#include<conio.h>

int main() /*main function*/

{

    char ch; /*variable declaration*/

    printf("n Enter a character : ");

    scanf("%c",& ch);

    if(ch>=65 && ch<=90)

     {
         printf("nThe character is an upper case letter");

     }

    if(ch>=97 && ch<=122)

     {

         printf("nThe character is an lower case letter");

     }

    if(ch>=48 && ch<=57)

     {

         printf("nThe character is a digit");

     }

    if((ch>=0 && ch<48)||(ch>=57 && ch<65)||(ch>90 && ch<97)||(ch>122))

     {

         printf("nThe character is a special symbol");

     }

    getch();

}




Output:
Enter a character : a

The character is an lower case letter




                                                                          17
P24. Program to print out powers of 2: 1, 2, 4, 8..up to 2^N
#include <stdio.h>

#include<conio.h>
#define N 16

main()

{
    int n;              /* The current exponent */

    int val = 1;        /* The current power of 2    */



    printf("t     n   t   2^nn");

    printf("t================n");

    for (n=0; n<=N; n++)
{

printf("t%3d t %6dn", n, val);

val = 2*val;
getch();

}



}




Output:
      n      2^n                                          8    256

     ================                                     9    512

      0      1                                            10   1024

      1      2                                            11   2048

      2      4                                            12   4096

      3      8                                            13   8192

      4      16                                           14   16384

      5      32                                           15   32768

      6      64                                           16   65536

      7      128




                                                                       18
P25. Program to swap two numbers without a third
variable
#include<stdio.h>

#include<conio.h>

int swap(int *a,int *b)

{

*a=*a-*b;

*b=*a+*b;

*a=*b-*a;

}

main()
{

int a,b;

printf("n enter First Number :");

scanf("%d",&a);

printf("n enter Second Number :");

scanf("%d",&b);

swap(&a,&b);

printf("n first Number is : %d",a);

printf("n second Number is : %d",b);

getch();

}


Output:
enter First Number : 3

enter Second Number : 4

first Number is : 4
second Number is : 3




                                                   19
P26. Calculate Electricity Bill with if-else condition
<=100 Rs.4/units
> 100 and <=300 Rs.4.50/units
>300 and <=500 Rs.4.75/units
>500 Rs.5/units

#include<stdio.h>

#include<conio.h>
main ()

{

    int unit, total;

    printf("Enter Total Units: ");

    scanf ("%d", &unit);

    if (unit<=100)
      {

           total=unit*4;

      }
    else if (unit>100 && unit<=300)

      {

           total=unit*4.5;
      }

    else if (unit >300 && unit<=500)

      {
           total=unit*4.75;

      }

    else
      {

           total=unit*5;

      }
    printf("Total: %d", total);

    getch ();

}




Output:
Enter Total Units: 350

Total: 1662



                                                         20
P27. Program to print the alphabet set a to z and A to Z in
decimal form and character form
#include<stdio.h>

#include<conio.h>

main()

 {

     char c;

     printf("nn");

     for(c=65;c<=122;c+=1)

       {

            if(c>90&&c<97)
               continue;

            printf("|%4d - %c ", c,c);

       }

     printf("|n");

    getch();

}




Output:
| 65 - A | 66 - B | 67 - C | 68 - D | 69 - E | 70 - F | 71 - G | 72 - H

| 73 - I | 74 - J | 75 - K | 76 - L | 77 - M | 78 - N | 79 - O | 80 - P

| 81 - Q | 82 - R | 83 - S | 84 - T | 85 - U | 86 - V | 87 - W | 88 - X

| 89 - Y | 90 - Z | 97 - a | 98 - b | 99 - c | 100 - d | 101 - e | 102 - f

| 103 - g | 104 - h | 105 - i | 106 - j | 107 - k | 108 - l | 109 - m | 110 - n

| 111 - o | 112 - p | 113 - q | 114 - r | 115 - s | 116 - t | 117 - u | 118 - v

| 119 - w | 120 - x | 121 - y | 122 - z |




                                                                                  21
P28. Program to print area of circle
#include<stdio.h>

#include<conio.h>
Void main()

{

        float a,b;
        printf("To Print Area Of Circle in Centimetres");

        printf("nnEnter Radius of Circle = ");

        scanf("%f", & a);

        b= (3.14)*(a)*(a);

        printf("nnArea of Circle is %f ", b);

        getch();
}




Output:
To Print Area Of Circle in Centimetres

Enter Radius of Circle = 3

Area of Circle is 28.260000




P29. Program to print the address of a variable along with
its value
#include<stdio.h>                                     printf("%d is stored at addr
                                                   %u.n",x,&x);
#include<conio.h>
                                                      printf("%f is stored at addr
void main()                                        %u.n",p,&p);

 {                                                    printf("%f is stored at addr
                                                   %u.n",q,&q);
     char a;
                                                       getch();
     int x;
                                                   }
     float p, q;

     a='A';
                                                   Output:
     x=125;                                        A is stored at addr 2293575.
     p=10.25, q=18.76;
                                                   125 is stored at addr 2293568.
   printf("%c is stored at addr
%u.n",a,&a);                                      10.250000 is stored at addr 2293564.

                                                   18.760000 is stored at addr 2293560.
                                                                                          22
P30. Program to read a series of words from a terminal
using scanf function
#include<stdio.h>

#include<conio.h>

main()

    {

         char word1[40], word2[40], word3[40], word4[40];

         printf("Enter text: ");

         scanf("%s %s", word1, word2);

         scanf("%s", word3);

         scanf("%s", word4);

         printf("n");

         printf("word 1 = %snword2 = %sn", word1, word2);

         printf("word 3 = %snword4 = %sn", word3, word4);

         getch();

}


Output:
Enter text: this is a sample-text

word 1 = this

word2 = is

word 3 = a

word4 = sample-text




                                                              23

More Related Content

What's hot

The solution manual of c by robin
The solution manual of c by robinThe solution manual of c by robin
The solution manual of c by robinAbdullah Al Naser
 
Best C Programming Solution
Best C Programming SolutionBest C Programming Solution
Best C Programming Solutionyogini sharma
 
Core programming in c
Core programming in cCore programming in c
Core programming in cRahul Pandit
 
Let us C (by yashvant Kanetkar) chapter 3 Solution
Let us C   (by yashvant Kanetkar) chapter 3 SolutionLet us C   (by yashvant Kanetkar) chapter 3 Solution
Let us C (by yashvant Kanetkar) chapter 3 SolutionHazrat Bilal
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given numberMainak Sasmal
 
Program flowchart
Program flowchartProgram flowchart
Program flowchartSowri Rajan
 
Printing different pyramid patterns of numbers,alphabets and stars using C.
Printing different pyramid patterns of numbers,alphabets and stars using C.Printing different pyramid patterns of numbers,alphabets and stars using C.
Printing different pyramid patterns of numbers,alphabets and stars using C.Hazrat Bilal
 
LET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERSLET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERSKavyaSharma65
 
c-programming-using-pointers
c-programming-using-pointersc-programming-using-pointers
c-programming-using-pointersSushil Mishra
 
B.Com 1year Lab programs
B.Com 1year Lab programsB.Com 1year Lab programs
B.Com 1year Lab programsPrasadu Peddi
 
Itp practical file_1-year
Itp practical file_1-yearItp practical file_1-year
Itp practical file_1-yearAMIT SINGH
 
Common problems solving using c
Common problems solving using cCommon problems solving using c
Common problems solving using cArghodeepPaul
 

What's hot (20)

88 c-programs
88 c-programs88 c-programs
88 c-programs
 
The solution manual of c by robin
The solution manual of c by robinThe solution manual of c by robin
The solution manual of c by robin
 
C PROGRAMS
C PROGRAMSC PROGRAMS
C PROGRAMS
 
C programms
C programmsC programms
C programms
 
Best C Programming Solution
Best C Programming SolutionBest C Programming Solution
Best C Programming Solution
 
Core programming in c
Core programming in cCore programming in c
Core programming in c
 
Let us C (by yashvant Kanetkar) chapter 3 Solution
Let us C   (by yashvant Kanetkar) chapter 3 SolutionLet us C   (by yashvant Kanetkar) chapter 3 Solution
Let us C (by yashvant Kanetkar) chapter 3 Solution
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
 
C Programming
C ProgrammingC Programming
C Programming
 
Program flowchart
Program flowchartProgram flowchart
Program flowchart
 
C Programming lab
C Programming labC Programming lab
C Programming lab
 
C Programming
C ProgrammingC Programming
C Programming
 
Printing different pyramid patterns of numbers,alphabets and stars using C.
Printing different pyramid patterns of numbers,alphabets and stars using C.Printing different pyramid patterns of numbers,alphabets and stars using C.
Printing different pyramid patterns of numbers,alphabets and stars using C.
 
LET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERSLET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERS
 
c-programming-using-pointers
c-programming-using-pointersc-programming-using-pointers
c-programming-using-pointers
 
B.Com 1year Lab programs
B.Com 1year Lab programsB.Com 1year Lab programs
B.Com 1year Lab programs
 
Vcs15
Vcs15Vcs15
Vcs15
 
Itp practical file_1-year
Itp practical file_1-yearItp practical file_1-year
Itp practical file_1-year
 
Ansi c
Ansi cAnsi c
Ansi c
 
Common problems solving using c
Common problems solving using cCommon problems solving using c
Common problems solving using c
 

Viewers also liked

Viewers also liked (6)

New file and form 2
New file and form 2New file and form 2
New file and form 2
 
How to install windows 8
How to install windows 8How to install windows 8
How to install windows 8
 
C programs
C programsC programs
C programs
 
Ee2fbunit 7
Ee2fbunit 7Ee2fbunit 7
Ee2fbunit 7
 
Process of design
Process of designProcess of design
Process of design
 
System development life cycle (sdlc)
System development life cycle (sdlc)System development life cycle (sdlc)
System development life cycle (sdlc)
 

Similar to C

Similar to C (20)

'C' language notes (a.p)
'C' language notes (a.p)'C' language notes (a.p)
'C' language notes (a.p)
 
C Programming Example
C Programming ExampleC Programming Example
C Programming Example
 
C file
C fileC file
C file
 
Simple C programs
Simple C programsSimple C programs
Simple C programs
 
C-LOOP-Session-2.pptx
C-LOOP-Session-2.pptxC-LOOP-Session-2.pptx
C-LOOP-Session-2.pptx
 
C lab
C labC lab
C lab
 
PCA-2 Programming and Solving 2nd Sem.pdf
PCA-2 Programming and Solving 2nd Sem.pdfPCA-2 Programming and Solving 2nd Sem.pdf
PCA-2 Programming and Solving 2nd Sem.pdf
 
PCA-2 Programming and Solving 2nd Sem.docx
PCA-2 Programming and Solving 2nd Sem.docxPCA-2 Programming and Solving 2nd Sem.docx
PCA-2 Programming and Solving 2nd Sem.docx
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
 
C Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossainC Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossain
 
A10presentationofbiologyandpshyology.pptx
A10presentationofbiologyandpshyology.pptxA10presentationofbiologyandpshyology.pptx
A10presentationofbiologyandpshyology.pptx
 
Programming fundamentals
Programming fundamentalsProgramming fundamentals
Programming fundamentals
 
Programming in C Lab
Programming in C LabProgramming in C Lab
Programming in C Lab
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02
 
Cs291 assignment solution
Cs291 assignment solutionCs291 assignment solution
Cs291 assignment solution
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
 
Cpds lab
Cpds labCpds lab
Cpds lab
 
C programs
C programsC programs
C programs
 
C faq pdf
C faq pdfC faq pdf
C faq pdf
 
C lab programs
C lab programsC lab programs
C lab programs
 

More from Mukund Trivedi (20)

File organisation
File organisationFile organisation
File organisation
 
Evaluation
EvaluationEvaluation
Evaluation
 
Database
DatabaseDatabase
Database
 
Case tools
Case toolsCase tools
Case tools
 
Evaluation
EvaluationEvaluation
Evaluation
 
Dfd final
Dfd finalDfd final
Dfd final
 
Sad
SadSad
Sad
 
C++ file
C++ fileC++ file
C++ file
 
Ff40fnatural resources (1)
Ff40fnatural resources (1)Ff40fnatural resources (1)
Ff40fnatural resources (1)
 
Ff40fnatural resources
Ff40fnatural resourcesFf40fnatural resources
Ff40fnatural resources
 
F58fbnatural resources 2 (1)
F58fbnatural resources 2 (1)F58fbnatural resources 2 (1)
F58fbnatural resources 2 (1)
 
F58fbnatural resources 2
F58fbnatural resources 2F58fbnatural resources 2
F58fbnatural resources 2
 
F6dc1 session6 c++
F6dc1 session6 c++F6dc1 session6 c++
F6dc1 session6 c++
 
E212d9a797dbms chapter3 b.sc2 (2)
E212d9a797dbms chapter3 b.sc2 (2)E212d9a797dbms chapter3 b.sc2 (2)
E212d9a797dbms chapter3 b.sc2 (2)
 
E212d9a797dbms chapter3 b.sc2 (1)
E212d9a797dbms chapter3 b.sc2 (1)E212d9a797dbms chapter3 b.sc2 (1)
E212d9a797dbms chapter3 b.sc2 (1)
 
E212d9a797dbms chapter3 b.sc2
E212d9a797dbms chapter3 b.sc2E212d9a797dbms chapter3 b.sc2
E212d9a797dbms chapter3 b.sc2
 
C96e1 session3 c++
C96e1 session3 c++C96e1 session3 c++
C96e1 session3 c++
 
B1ce9 assignmentbsc
B1ce9 assignmentbscB1ce9 assignmentbsc
B1ce9 assignmentbsc
 
Af7ff syllabuslablist
Af7ff syllabuslablistAf7ff syllabuslablist
Af7ff syllabuslablist
 
106da session5 c++
106da session5 c++106da session5 c++
106da session5 c++
 

Recently uploaded

Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.MateoGardella
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterMateoGardella
 

Recently uploaded (20)

Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 

C

  • 1. qwertyuiopasdfghjklzxcvbnmq wertyuiopasdfghjklzxcvbnmqw ertyuiopasdfghjklzxcvbnmqwer C Programming File tyuiopasdfghjklzxcvbnmqwerty PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE uiopasdfghjklzxcvbnmqwertyui opasdfghjklzxcvbnmqwertyuiop SHERIL SHARMA asdfghjklzxcvbnmqwertyuiopas dfghjklzxcvbnmqwertyuiopasdf ghjklzxcvbnmqwertyuiopasdfgh jklzxcvbnmqwertyuiopasdfghjkl zxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcv bnmqwertyuiopasdfghjklzxcvbn mqwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnmq wertyuiopasdfghjklzxcvbnmqw ertyuiopasdfghjklzxcvbnmrtyui
  • 2. Index P1. Program to print a sentence in output screen…………………………………………………………………………………………………………………… 2 P2. Program to enter two numbers and check which one is greater……………………………………………………………………………………….. 2 P3. Program to add two integers…………………………………………………………………………………………………………………………………………….. 3 P4. Program for showing one integer value, float value and character constant on output screen…………………………………………. 3 P5. Program to input a number and check whether it is even or odd………………………………………………………………………………………. 4 P6. Program to print the following pattern………………………………………………………………………………………………………………………………. 4 * ** *** **** ***** P7. Program to print name 5 times using while loop………………………………………………………………………………………………………………… 5 P8. Program to print sum of first 10 integers using while loop…………………………………………………………………………………………………. 5 P9. Program to find out the roots of quadratic equation………………………………………………………………………………………………………….. 6 P10. Program to print the following pattern…………………………………………………………………………………………………………………………….. 7 1 23 456 7 8 9 10 11 12 13 14 15 P11. Program to print the following pattern…………………………………………………………………………………………………………………………….. 7 0 01 012 0123 01234 P12. Program to print the Fibonacci series to n number of places……………………………………………………………………………………………. 8 P13. Program to display marks of 5 students……………………………………………………………………………………………………………………………. 9 P14. Program to find average and sum of marks obtained by a class of 5 students…………………………………………………………………. 10 P15. Program to print a string…………………………………………………………………………………………………………………………………………………. 11 P16. Program to print the length of the string…………………………………………………………………………………………………………………………. 11 P17. Program to print the reverse of the string……………………………………………………………………………………………………………………….. 12 P18. Program to write input marks of 5 subjects and calculate the percentage………………………………………………………………………. 13 P19. Program to input the time and print the day time…………………………………………………………………………………………………………… 14 P20. Program to print factorial of a number……………………………………………………………………………………………………………………………. 14 P21. Write a program to accept three sides of a triangle and transfer them to a function to compute the area of a triangle….. 15 P22. Write a program to find average male and female height in the class……………………………………………………………………………… 16 P23. Write a program to accept a character and determine whether it is an alphabet, character or special symbol……………….. 17 P24. Program to print out powers of 2: 1, 2, 4, 8..up to 2^N……………………………………………………………………………………………………. 18 P25. Program to swap two numbers without a third variable………………………………………………………………………………………………….. 19 P26. Calculate Electricity Bill with if-else condition………………………………………………………………………………………………………………….. 20 P27. Program to print the alphabet set a to z and A to Z in decimal form and character form…………………………………………………. 21 P28. Program to print area of circle…………………………………………………………………………………………………………………………………………. 22 P29. Program to print the address of a variable along with its value……………………………………………………………………………………….. 22 P30. Program to read a series of words from a terminal using scanf function ……………………………………………………………………….. 23
  • 3. P1. Program to print a sentence in output screen. #include <stdio.h> #include<conio.h> void main() { clrscr(); printf("My name is Sheril"); getch(); } Output: My name is Sheril P2. Program to enter two numbers and check which one is greater. #include<stdio.h> #include<conio.h> void main() { clrscr(); int a,b; printf("Enter two numbers: "); scanf(%d%d",&a,&b); if(a>b) { printf("a is greater than b"); printf("na is less than b"); } getch(); } Output: Enter two numbers : 3 5 a is less than b 2
  • 4. P3. Program to add two integers. #include<stdio.h> #include<conio.h> void main() { clrscr(); int a,b,c; printf("Enter an integer: "); scanf("%d",&a); printf("nEnter another integer: "); scanf("%d",&b); c=a+b; printf("The sum of the two integers is: "); printf("c=%d",c); getch(); } Output: Enter an integer: 3 Enter another integer: 5 The sum of the two integers is: 8 P4. Program for showing one integer value, float value and character constant on output screen. #include<stdio.h> printf("Character Constant =%c",c); #include<conio.h> getch(); void main() } { clrscr(); Output: Interger Value =5 int a=5; float b=8.5; Float Value =8.5 char c='A'; Character Constant =A printf("Interger Value =%d",a); printf("Float Value =%f",b); 3
  • 5. P5. Program to input a number and check whether it is even or odd. #include<stdio.h> #include<conio.h> void main() { clrscr(); int n; printf("nEnter a number: "); scanf("%d",&n); if(n%2==0) { printf("Number is even"); } else printf("Number is odd"); getch(); } Output: Enter a number: 2 (or 3) Number is even (or Number is odd) P6. Program to print the following pattern * ** *** **** ***** #include<stdio.h> for(j=1;j<=i;j++) #include<conio.h> printf("*"); Void main() printf("n"); { } int i,j; getch(); for(i=1;i<=5;i++) } { 4
  • 6. P7. Program to print name 5 times using while loop. #include<stdio.h> #include<conio.h> void main() { clrscr(); int i=1; while(i<=5) { printf("My name is Sheriln"); i++; } getch(); } Output: My name is Sheril My name is Sheril My name is Sheril My name is Sheril My name is Sheril P8. Program to print sum of first 10 integers using while loop. #include<stdio.h> sum+=a; #include<conio.h> } printf("The sum is %d,sum); void main() getch(); { } int a=0, sum=0; while(a<10) Output: The sum is 55 { a++; 5
  • 7. P9. Program to find out the roots of quadratic equation. #include<stdio.h> #include<conio.h> #include<math.h> Void main() { int a,b,c; float dis,root1,root2; printf("nEnter values of a,b and c: "); scanf("%d%d%d",&a,&b,&c); dis=(b*b)-4*a*c; printf("ndis=%f",dis); root1=-b+sqrt(dis)/2.0*a; root2=-b-sqrt(dis)/2.0*a; if(dis<0) { printf("nThe roots are imaginary"); } else if(dis==0) { printf("nThe roots are equal and real"); } else { printf("nThe roots are real and distinct"); printf("nThe roots are %f%f",root1,root2); } getch(); } Output: Enter values of a,b and c: 4 2 1 The roots are imaginary 6
  • 8. P10. Program to print the following pattern 1 23 456 7 8 9 10 11 12 13 14 15 #include<stdio.h> #include<conio.h> Void main() { int i,j,var=1; for(i=1;i<=5;i++) { for(j=1;j<=i;j++) { printf("%d ",var); var+=1; } printf("n"); } getch(); } P11. Program to print the following pattern 0 01 012 0123 01234 #include<stdio.h> { #include<conio.h> printf("%d",j); Void main() } { printf("n"); int i,j; } for(i=0;i<=5;i++) getch(); { } for(j=0;j<=i;j++) 7
  • 9. P12. Program to print the Fibonacci series to n number of places #include<stdio.h> #include<conio.h> Void main() { int a=-1,b=1,c=0,n; printf("Enter the number of places: "); scanf("%d",&n); for(int i=0;i<=n;i++) { c=a+b; printf("%d ",c); a=b; b=c; } getch(); } Output: Enter the number of places: 10 0 1 1 2 3 5 8 13 21 34 55 8
  • 10. P13. Program to display marks of 5 students. #include<stdio.h> #include<conio.h> main() { int marks[5]; int i=1; for(i=1;i<=5;i++) { printf("nEnter marks of student %d: ",i); scanf("%d",&marks[i]); } printf("nThe marks of 5 students are: "); for(i=1;i<=5;i++) { printf("%d ",marks[i]); } getch(); } Output: Enter marks of student 1: 12 Enter marks of student 2: 13 Enter marks of student 3: 14 Enter marks of student 4: 10 Enter marks of student 5: 15 The marks of 5 students are: 12 13 14 10 15 9
  • 11. P14. Program to find average and sum of marks obtained by a class of 5 students. #include<stdio.h> #include<conio.h> Void main() { int avg,sum=0; int i,marks[5]; for(i=0;i<=4;i++) { printf("nEnter the marks: "); scanf("%d",&marks[i]); } for(i=0;i<=4;i++) sum=sum+marks[i]; avg=sum/5; printf("nAverage marks are: %dn",avg); getch(); } Output: Enter the marks: 10 Enter the marks: 12 Enter the marks: 14 Enter the marks: 15 Enter the marks: 12 Average marks are: 12 10
  • 12. P15. Program to printa string. #include<stdio.h> #include<conio.h> #include<string.h> void main() { int c; char name[20]; printf("Enter the name"); gets(name); printf("The name entered is"); printf("%s",name); getch(); } Output: Enter the name John Smith The name entered is John Smith P16. Program to print the length of the string. #include<stdio.h> c=strlen(name); #include<conio.h> printf("nThe length of the string is: %d",c); #include<string.h> getch(); void main() } { int c; Output: char name[20]; Enter the name: Sheril printf("Enter the name: "); The name entered is: Sheril gets(name); The length of the string is: 6 printf("The name entered is: "); printf("%s",name); 11
  • 13. P17. Program to print the reverse of the string. #include <stdio.h> #include <string.h> #include <conio.h> void main() { char str[100], rstr[100]; int i,k; printf("Enter the string to reverse=>"); gets(str); for (i=strlen(str)-1,k=0; i>=0; i--,k++) { rstr[k]=str[i]; } rstr[k]='0'; printf("string <%s> reverse <%s>n",str,rstr); getch(); } Output: Enter the string to reverse=> This is a sample string string < This is a sample string> reverse <gnirts elpmas a si sihT > 12
  • 14. P18. Program to write input marks of 5 subjects and calculate the percentage. #include<stdio.h> #include<conio.h> void main() { int a,b,c,d,e; float p; printf("nEnter the marks of 5 subjects: "); scanf("%d%d%d%d%d",&a,&b,&c,&d,&e); p=(a+b+c+d+e)/5; printf("nThe percentage is: "); printf("%fnn",p); if(p>=60) printf("Ist division"); else if(p<=59&&p>=50) printf("Second division"); else if(p<=49&&p>=40) printf("Third division"); else printf("Fail"); getch(); } Output: Enter the marks of 5 subjects: 85 75 65 89 96 The percentage is: 82.000000 Ist division 13
  • 15. P19. Program to input the time and print the day time #include<stdio.h> #include<conio.h> void main() { clrscr(); int t; printf("Enter the time in 24 hours clock formatn"); scanf("%d",&t); if(t==0) printf("It is midnightn"); else if(t>0 && t<400) printf("The time is after midnight and not yet morningn"); else if(t>=400 && t<700) printf("It is early morning"); else if(t>=700 && t<1200) printf("It is morning"); else if(t==1200) printf("It is exact afternoon"); else if(t>1200 && t<300) printf("It is afternoon"); else if(t>=300 && t<=700) printf("It is evening"); else printf("It is Night"); getch(); } Output: Enter the time in 24 hours clock format 400 It is early morning P20. Program to print factorial of a number. #include<stdio.h> n--; #include<conio.h> } void main() printf("The factorial is: %d",fact); { getch(); int fact=1,i=1,n; } printf("Enter the number:n"); scanf("%d",&n); Output: Enter the number: while(n!=i) { 5 fact=fact*n; The factorial is: 120 14
  • 16. P21. Write a program to accept three sides of a triangle and transfer them to a function to compute the area of a triangle #include <stdio.h> /*header file*/ #include <conio.h> /*header file*/ #include <math.h> int main() /*main function*/ { float tri_area(float a,float b, float c); /* new function*/ float s1; float s2; float s3; float area; printf("nEnter the three sides of a triangle"); scanf("%f%f%f",&s1,&s2,&s3); area=tri_area(s1,s2,s3); printf("n Area of triangle is : %f square units.", area); /*printing area*/ _getch(); } float tri_area(float a,float b,float c) { float s; float area; s=(a+b+c)/2; area=sqrt(s*(s-a)*(s-b)*(s-c)); /*heron’s formula*/ return(area); } Output: Enter the three sides of a triangle 12 14 16 Area of triangle is : 81.332649 square units. 15
  • 17. P22. Write a program to find average male and female height in the class #include<stdio.h> /*header file*/ ftot+=fh[count]; #include<conio.h> } int main() /*main function*/ favg+=ftot/5; /*Formula to find average*/ { printf("nThe average male height is float mavg=0, favg=0; %f",mavg); int mh[5], fh[5], count; printf("nThe average female height is %f",favg); float mtot; float ftot; getch(); mtot=0,ftot=0; } for(count=0;count<5;count++) /*for loop*/ { printf("nEnter the height of Output: %d",count+1); Enter the height of 1 male: 5 printf(" male: "); Enter the height of 2 male: 6 scanf("%d",&mh[count]); Enter the height of 3 male: 5 mtot+=mh[count]; Enter the height of 4 male: 6 } Enter the height of 5 male: 6 mavg=mtot/5; Enter the height of 1 female: 5 printf("n"); Enter the height of 2 female: 5 for(count=0;count<5;count++) /*for Enter the height of 3 female: 6 loop*/ Enter the height of 4 female: 5 { Enter the height of 5 female: 6 printf("nnEnter the height of %d",count+1); The average male height is 5.600000 printf(" female: "); The average female height is 5.400000 scanf("%d",&fh[count]); 16
  • 18. P23. Write a program to accept a character and determine whether it is an alphabet, character or special symbol #include<stdio.h> /*header file*/ #include<conio.h> int main() /*main function*/ { char ch; /*variable declaration*/ printf("n Enter a character : "); scanf("%c",& ch); if(ch>=65 && ch<=90) { printf("nThe character is an upper case letter"); } if(ch>=97 && ch<=122) { printf("nThe character is an lower case letter"); } if(ch>=48 && ch<=57) { printf("nThe character is a digit"); } if((ch>=0 && ch<48)||(ch>=57 && ch<65)||(ch>90 && ch<97)||(ch>122)) { printf("nThe character is a special symbol"); } getch(); } Output: Enter a character : a The character is an lower case letter 17
  • 19. P24. Program to print out powers of 2: 1, 2, 4, 8..up to 2^N #include <stdio.h> #include<conio.h> #define N 16 main() { int n; /* The current exponent */ int val = 1; /* The current power of 2 */ printf("t n t 2^nn"); printf("t================n"); for (n=0; n<=N; n++) { printf("t%3d t %6dn", n, val); val = 2*val; getch(); } } Output: n 2^n 8 256 ================ 9 512 0 1 10 1024 1 2 11 2048 2 4 12 4096 3 8 13 8192 4 16 14 16384 5 32 15 32768 6 64 16 65536 7 128 18
  • 20. P25. Program to swap two numbers without a third variable #include<stdio.h> #include<conio.h> int swap(int *a,int *b) { *a=*a-*b; *b=*a+*b; *a=*b-*a; } main() { int a,b; printf("n enter First Number :"); scanf("%d",&a); printf("n enter Second Number :"); scanf("%d",&b); swap(&a,&b); printf("n first Number is : %d",a); printf("n second Number is : %d",b); getch(); } Output: enter First Number : 3 enter Second Number : 4 first Number is : 4 second Number is : 3 19
  • 21. P26. Calculate Electricity Bill with if-else condition <=100 Rs.4/units > 100 and <=300 Rs.4.50/units >300 and <=500 Rs.4.75/units >500 Rs.5/units #include<stdio.h> #include<conio.h> main () { int unit, total; printf("Enter Total Units: "); scanf ("%d", &unit); if (unit<=100) { total=unit*4; } else if (unit>100 && unit<=300) { total=unit*4.5; } else if (unit >300 && unit<=500) { total=unit*4.75; } else { total=unit*5; } printf("Total: %d", total); getch (); } Output: Enter Total Units: 350 Total: 1662 20
  • 22. P27. Program to print the alphabet set a to z and A to Z in decimal form and character form #include<stdio.h> #include<conio.h> main() { char c; printf("nn"); for(c=65;c<=122;c+=1) { if(c>90&&c<97) continue; printf("|%4d - %c ", c,c); } printf("|n"); getch(); } Output: | 65 - A | 66 - B | 67 - C | 68 - D | 69 - E | 70 - F | 71 - G | 72 - H | 73 - I | 74 - J | 75 - K | 76 - L | 77 - M | 78 - N | 79 - O | 80 - P | 81 - Q | 82 - R | 83 - S | 84 - T | 85 - U | 86 - V | 87 - W | 88 - X | 89 - Y | 90 - Z | 97 - a | 98 - b | 99 - c | 100 - d | 101 - e | 102 - f | 103 - g | 104 - h | 105 - i | 106 - j | 107 - k | 108 - l | 109 - m | 110 - n | 111 - o | 112 - p | 113 - q | 114 - r | 115 - s | 116 - t | 117 - u | 118 - v | 119 - w | 120 - x | 121 - y | 122 - z | 21
  • 23. P28. Program to print area of circle #include<stdio.h> #include<conio.h> Void main() { float a,b; printf("To Print Area Of Circle in Centimetres"); printf("nnEnter Radius of Circle = "); scanf("%f", & a); b= (3.14)*(a)*(a); printf("nnArea of Circle is %f ", b); getch(); } Output: To Print Area Of Circle in Centimetres Enter Radius of Circle = 3 Area of Circle is 28.260000 P29. Program to print the address of a variable along with its value #include<stdio.h> printf("%d is stored at addr %u.n",x,&x); #include<conio.h> printf("%f is stored at addr void main() %u.n",p,&p); { printf("%f is stored at addr %u.n",q,&q); char a; getch(); int x; } float p, q; a='A'; Output: x=125; A is stored at addr 2293575. p=10.25, q=18.76; 125 is stored at addr 2293568. printf("%c is stored at addr %u.n",a,&a); 10.250000 is stored at addr 2293564. 18.760000 is stored at addr 2293560. 22
  • 24. P30. Program to read a series of words from a terminal using scanf function #include<stdio.h> #include<conio.h> main() { char word1[40], word2[40], word3[40], word4[40]; printf("Enter text: "); scanf("%s %s", word1, word2); scanf("%s", word3); scanf("%s", word4); printf("n"); printf("word 1 = %snword2 = %sn", word1, word2); printf("word 3 = %snword4 = %sn", word3, word4); getch(); } Output: Enter text: this is a sample-text word 1 = this word2 = is word 3 = a word4 = sample-text 23