Skip to main content

C Language



0.0.0 Introduction

#include<> for link
stdio.h -->header file
conio.h -->header file
main() main function
void() do not return
printf for print
scanf for scan
clrscr(); clear screen [in turbo C]
getch(); close Program

the extention name of c is .c

variable:-
name initial format
number/integer int %d
long integert  longint %ld
Decimal number float %f
string char %s
character char %c

short cuts for turbo C:-
  exit- Alt+X save-F2 run-Ctrl+F9 compile- Alt+F9



0.1.0

C Language
The C Programming language is used to write programs. Using this language we can send instructions to the computer for achieving a particular task. C is one of such high label language.

C was developed by Dennis Ritchie at bell laboratory in USA in 1970-72. This language is a combination of languages BCPL(Basic Combined Programming Language) and B which were also developed by Bell.

Advantage of C
Various advantage of C is:-
1)      C is powerful and flexible language.
2)      C is portable language.
3)      Using C we can create tables of constant data with in the same file
4)      C program can be executed much faster than the  high label language
5)      We can create operating system using C . Ex—windows, linux, unix, etc.
Disadvantage of C
1)      In C, there are very few instrinsic operations and all heavy work is done through the library function call
2)      In C there is no mechanism for 3 type checking

Constants
Constant in C refer to fixed value that does not change during execution of programs. If a variable is declared as should not try to change its value.
Variable is used to represent.





Variable
1)      Primary variable-> integer,real,char etc
2)      Secondary variable-> Array, pointer, structure etc


Rules of variable names:
i)                    A variable name any combination alphabets, digits, or underscores.
ii)                   The first character in the variable name must be an alphabet or underscores
iii)                 No commas and blanks are allowed with in a variable name
iv)                 No special symbol or key words are use as variable name

C key words
Key words are words whose meaning has already been explained to the C compiler. The key words are also called “reserved word”
There are 32 key words are available in C
Auto
Double
Int
Struct
Break
Else
Long
Switch
Case
Enum
Register
Typed of
Char
Ex
Return
Union
Const
Float
Short
Unsigned
Continue
For
Signed
Void
Default
Go to
Sign of
Volatile
Do
If
Static
While

Compiler:
A compiler converts the code written in programming language into machine language

String:
A string constant is a one dimensional array of characters terminated by a null (‘\0’).
Ex- char name [15];
String format-> %s
String scan-> gets
Clear the input buffer-> fflush(stdin)
Array:
An array is a collection of elements of a single data type store in a memory location. It is a collection. It is a collection of element of the same type that are referenced by a common name. Each element in  an array can be referenced to be an array name and index number.
An array is a way to group together a number of variables of a single data type. Which have a single name followed by an index.
Element
Each variable  stored in an array called an array is called an element. The elements have an index. The index of the first array element is zero(0).
Array declaration
1) Type of the array (int, float, char, etc)
2) Name of the array.
3)Number of Dimension.
4)Size of array (number of element).
Sintax:
Data type array name [size];
Int roll[500];
Arrays are two type-
1)      One dimension
2)      Multi dimension(two,three,four……….)
Functions
What is function?
A function is a self contained block of statement that perform valid task of some kind. Every C program can be thought of as a collection of different function.
There are basically two types of function in C.
1)      Library function
2)      User define function
What is library function?
Library function are  prewritten and precompiled by the compiler vendor and come along with the compiler software as a library of function. It is not modified by the user.
Ex- printf(), scanf() etc
What is user define function?
The function defined by user for his/her requirement are called user define function.
Return:
Pointer is a special type of variable. Which contain another variable address. Pointer variable declared with ‘*’ sign.
Call by value:
In this method of function call the “value” of which of the actual arguments in the calling function is copied in to the corresponding of the called function. With this method, to change the mode to the formal argument in the called function have no effect value of the actual argument of the calling function.
Call by reference
In this method of function call the “address” of the actual arguments in the calling function is copied into the formal argument of the called function. With this method to change made to formal argument in the called function have effect on the calling function.

1.Odd or Even

#include<stdio.h>
#include<conio.h>
void main()
{
int a;
clrscr();  //in turbo C
printf("\nEnter a Number:-");
scanf("%d",&a);
if(a%2==0)
{
printf("\nEntered number is even");
}
else
{
printf("\nEntered number is odd");
}
getch();
}

O\P:- 
Enter a Number:- 2334
Entered number is even

2.Sum

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("\nEnter your 1st number:-");
scanf("%d",&a);
printf("\nEnter your your 2nd number:-");
scanf("%d",&b);
c=a+b;
printf("\Sum of those numbers:-%d",c);
getch();
}

O/P:-
Enter your 1st number:- 20
Enter your 2nd number:- 30
Sum of those numbers:- 50

3.Voter or non voter

#include<stdio.h>
#include<conio.h>
void main()
{
int a;
clrscr();
printf("\nEnter your age:-");
scanf("%d",&a);
if(a>=18)
{
printf("\nYou are voter.");
}
else
{
printf("\nyou are not voter");
}
getch();
}

O/P:
Enter your age:-67
you are voter

4.maximum of two numbers

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("\nEnter  your 1st Number:-");
scanf("%d",&a);
printf("\nEnter your 2nd Number:-"); 
scanf("%d",&b);
if(a>b)
{
printf("\nThe maximum number is:-%d",a);
}
else
{
printf("\nThe maximum number is:-%d",b);
}
getch();
}

O/P:
Enter  your 1st Number:-234
Enter your 2nd Number:-345
The maximum number is:-345

5.maximum of three numbers

#include<stdio.h>
#include<conio.h>
void main()
{
int a,bc,m;
clrscr();
printf("\nEnter your 1st number: ");
scanf("%d",&a);
printf("\nEnter your 2nd number: ");
scanf("%d",&b);
printf("\nEnter your 3rd number: ");
scanf("%d",&c);
m=a;
if(m<b);
{
m=b;
}
if(m<c)
{
m=c;
}
printf("\nThe maximum number is: %d",m);
getch();
}

O/P:
Enter your 1st number: 456
Enter your 2nd number: 567
Enter your 3rd number: 2345
The maximum number is:-2345

6.square value

#include<stdio.h>
#include<conio.h>
void main();
{
int a,b;
clrscr();
printf("\nEnter your number: ");
scanf("%d"&a);
b=a*a;
printf("\nThe square value of given number is: %d",b);
getch();
}

O/P:
Enter your number: 3
The square value of given number is: 9

7. leap year or not

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("\nEnter a year: ");
scanf("%d",&a);
if(a%4==0)

if(a%100==0)

if(a%400==0)
{
printf("\nThe year is leap year");
}
else
{
printf("\nThe year is not leap year");
}
else
{
printf("\nThe year is  leap year");
}
else
{
printf("\nThe year is not leap year");
}
getch();
}

O\P:
Enter a year: 1900
The year is not leap year

8.0.0 loop

loop(s) are three types:- i)for  ii)while   iii)do-while

8.1.0 for

     for(assign;testing;increment/decrement)
     {
     body
     }  


8.1.1

/* print the series 1,2,3,-----------up to ten */

#include<stdio.h>
#include<conio.h>
void main()
{
int i;
clrscr();
for(i=1;i<=10;i++)
{
printf("\t%d",i);
}
getch();
}

O/P:-
     1     2      3     4     5    6      7     8     9     10

8.1.2

/*print the series1,3,5,--------------upto 10 term */


#include<stdio.h>
#include<conio.h>
void main()
{
int i,a;
clrscr();
a=1;
for(i=0;i<10;i++)
{
prinf("\t%d",a);
a=a+2;
}
getch();
}

O/P:-
     1        3       5       7     9         11      13      15    17      19

8.1.3

/*print the series 100,95,90,------up to ten terms*/
#include<stdio.h>
#include<conio.h>
void main()
{
int i,a;

a=100;
for(i=0;i<10;i++)
{
printf("\t%d",a);
a=a-5;
}
return 0;
}

O/P:-
        100     95      90      85      80      75      70      65      60      55

8.1.4

/*print the series 100,95,90,------up to ten terms*/
#include<stdio.h>
#include<conio.h>
void main()
{
int i,a;

a=100;
for(i=0;i<10;i++)
{
printf("\t%d",a);
a=a-5*(i+1);
}
return 0;
}

O/P:-
      100     95      85      70      50      25      -5      -40     -80     -125

8.2.0 while

/* while(condition)
{
   statement(s);
   }  */

#include <stdio.h>
int main()
{
int i=1, j=1;
while(i <= 4 || j <= 3) 
{
printf("%d %d\n",i, j);
i++;
j++; 
 }
  return 0;
}

O\P:
1 1
2 2
3 3
4 4

8.3.0 do-while

/* do
  {
   statement(s);
   }
while( condition ); */

#include <stdio.h>
int main () {   /* local variable definition */
     int a = 10; /* do loop execution */
      do {
            printf("value of a: %d\n", a);
             a = a + 1; 
            }
while( a < 20 );
  return 0;
}

O/P:
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15
value of a: 16
value of a: 17
value of a: 18
value of a: 19

9.0.0 array

Array(s) are two types:- 1)one dimension array 2)Multiple(two,three,four...) dimension array



1) One dimension array:-
Datatype variable name [size]
int Roll [10]

2) Two dimension array:-
Datatype variable name [size][size]
int arr [3][3]

3) Three dimension array:-
Datatype variable name [size][size][size]
int student [3][3][3]

4) Four dimension array:-
datatype variable name [size][size][size][size]
int table [3][3][3][3]

9.1.0 1D array

/* input a string and display string langth */

#include<stdio.h>
#include<conio.h>
void main()
{
char str[30];
int l,i;

printf("\nenter your string:-");
gets(str);
l=0;
i=0;
while(str[i]!=NULL)
{
l++;
i++;
}
printf("\n the str length is:-  %d",l);
return 0;
}


O/P:

enter your string:-work hard to see your happy family

 the str length is:-  31

9.1.1.0

/*enter a string and display its length */

#include<stdio.h>
#include<conio.h>
void main()
{
    char str[30];
    int l=0,i=0;

    printf("\nenter your string;");
    gets(str);

    while(str[i]!=NULL)
    {

    i++;
}
    printf("\n the string length is:%d",i);
    void main();
}

O/P:

enter your string;bappa saikh

 the string length is:11

9.1.1.1

/*input a string and display string length without space and count how many space in that string */

#include<stdio.h>
#include<conio.h>
void main()
{
char str[30];
int l,i,s;
printf('\n enter your string:-   ")
gets(str);
l=0;
i=0;
s=0;
while(str[i]!=Null);
{
l++;
if(str[i]==' ')
{
s++;
}
i++;
}
printf("\nThe string length is:-    %d",s);
getch();
}


O/P:
enter your string;bappa saikh is a good boy

 the string length is:20
 total space is:4

9.1.2

/* input 5 students marks and display the marks using array */

#include<stdio.h>
#include<conio.h>
int main()
{
    int mar[5];
    int i;
    for(i=0;i<5;i++)
    {
        printf("\nenter %dth student's mark; ",i+1);
        scanf("%d",&mar[i]);
    }
    for(i=0;i<5;i++)
    {
        printf("\nThe %dth student's  mark:%d",i+1, mar[i]);

    }
    getch();
}

O/P:

enter 1th student's mark; 34

enter 2th student's mark; 45

enter 3th student's mark; 65

enter 4th student's mark; 75

enter 5th student's mark; 67

The 1th student's  mark:34
The 2th student's  mark:45
The 3th student's  mark:65
The 4th student's  mark:75
The 5th student's  mark:67

9.1.3

/* input few numbers and display maximum and minimum of those numbers*/
#include<stdio.h>
#include<conio.h>
void main()
{
int set[100];
int i,n,max,min;
clrscr();
printf("\nEnter total set of numbers:-\t");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter %dth set of number:-\t",i+1);
scanf("%d",&set[i]);
}
max=set[0];
min=set[0];
for(i=1;i<n;i++)
{
if(max<set[i])
{
max=set[i];
}
if(min>set[i])
{
min=set[i];
}
}
printf("\nThe maximum number is:-\t%d",max);
printf("\nThe minimum number is:-\t%d",min);
getch();
}




O/P:

Enter total set of numbers:-    10

Enter 1th set of number:-       1

Enter 2th set of number:-       2

Enter 3th set of number:-       3

Enter 4th set of number:-       4

Enter 5th set of number:-       5

Enter 6th set of number:-       6

Enter 7th set of number:-       7

Enter 8th set of number:-       8

Enter 9th set of number:-       9

Enter 10th set of number:-      10

The maximum number is:- 10
The minimum number is:- 1

9.1.4

/* input few set of numbers and display sum of even numbers and average */

#include<stdio.h>
#include<conio.h>
void main()
{
int set[100];
int i,n,a,t;
float avg;
printf("\nEnter total set of numbers:     ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter %dth set of number:     ",i+1);
scanf("%d",&set[i]);
}
t=0;
a=0;
for(i=0;i<n;i++)
{
if(set[i]%2==0)
{
t=t+set[i];
a=a+1;
}
}
avg=(float)t/a;
printf("\nThe total of even numbers is:    %d",t);
printf("\nThe average  of even numbers is:    %f",avg);
return 0;
}


O/P:

Enter total set of numbers:   10

Enter 1th set of number:  1

Enter 2th set of number:  2

Enter 3th set of number:  3

Enter 4th set of number:  4

Enter 5th set of number:  5

Enter 6th set of number:  6

Enter 7th set of number:  7

Enter 8th set of number:  8

Enter 9th set of number:  9

Enter 10th set of number:  10

The total number is:   30
The average number is:   6.000000

9.1.5

*/ input few set of numbers and display sum of odd numbers and average /*


#include<stdio.h>
#include<conio.h>
void main()
{
int set[100];
int i,n,a,t;
float avg;
printf("\nEnter total set of numbers:     ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter %dth set of number:     ",i+1);
scanf("%d",&set[i]);
}
t=0;
a=0;
for(i=0;i<n;i++)
{
if(set[i]%2==0)
{
t=t+set[i];
a=a+1;
}
}
avg=(float)t/a;
printf("\nThe total of odd numbers is:    %d",t);
printf("\nThe average  of odd numbers is:    %f",avg);
return 0;
}


O/P:


Enter total set of numbers:     5

Enter 1th set of number:     54

Enter 2th set of number:     67

Enter 3th set of number:     456

Enter 4th set of number:     45

Enter 5th set of number:     3456

The total of odd numbers is:    112
The average  of odd numbers is:    56.000000

9.1.6

/* input yor name and your father name and display it */
#include<stdio.h>
#include<conio.h>
void main()
{
char n[30];
char f[30];
printf("\nEnter your name: ");
gets(n);
fflush(stdin);
printf("\nEnter your father's name:       ");
gets(f);
printf("\nyour name is:   %s",n);
printf("\nyour father's name is:   %s",f);
return 0;
}

O/P:

Enter your name:        Rabin

Enter your father's name:  Pavan

your name is:   Rabin
your father's name is:   Pavan

9.2.0 2D array

/* input few student's roll,sub1,sub2,sub3  */
#include<stdio.h>
#include<conio.h>
void main()
{
int stu[100][4];
int i,n;
printf("\nEnter total student:   ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter %dth student's roll no:   ",i+1);
scanf("%d",&stu[i][0]);
printf("\nEnter %dth student's sub1:   ",i+1);
scanf("%d",&stu[i][1]);
printf("\nEnter %dth student's sub2:   ",i+1);
scanf("%d",&stu[i][2]);
printf("\nEnter %dth student's sub3:   ",i+1);
scanf("%d",&stu[i][3]);
}
printf("\nStudents Record:");
printf("\n\tRoll\tSub1\tSub2\tSub3");
for(i=0;i<n;i++)
{
printf("\n\t%d\t%d\t%d\t%d",stu[i][0],stu[i][1],stu[i][2],stu[i][3]);
}
return 0;
}
O/P:

Enter total student:   5

Enter 1th student's roll no:   56

Enter 1th student's sub1:   78

Enter 1th student's sub2:   67

Enter 1th student's sub3:   56

Enter 2th student's roll no:   2

Enter 2th student's sub1:   78

Enter 2th student's sub2:   89

Enter 2th student's sub3:   87

Enter 3th student's roll no:   49

Enter 3th student's sub1:   88

Enter 3th student's sub2:   90

Enter 3th student's sub3:   69

Enter 4th student's roll no:   97

Enter 4th student's sub1:   78

Enter 4th student's sub2:   56

Enter 4th student's sub3:   98

Enter 5th student's roll no:   66

Enter 5th student's sub1:   56

Enter 5th student's sub2:   78

Enter 5th student's sub3:   51

Students Record:
        Roll    Sub1    Sub2    Sub3
        56      78      67      56
        2       78      89      87
        49      88      90      69
        97      78      56      98
        66      56      78      51

9.3.0 3D array

#include<stdio.h>
#include<conio.h>

void main()
{
int i, j, k;
int arr[3][3][3]=
        {
            {
            {11, 12, 13},
            {14, 15, 16},
            {17, 18, 19}
            },
            {
            {21, 22, 23},
            {24, 25, 26},
            {27, 28, 29}
            },
            {
            {31, 32, 33},
            {34, 35, 36},
            {37, 38, 39}
            }
        };

printf(":::3D Array Elements:::\n\n");
for(i=0;i<3;i++)
{
    for(j=0;j<3;j++)
    {
        for(k=0;k<3;k++)
        {
        printf("%d\t",arr[i][j][k]);
        }
        printf("\n");
    }
    printf("\n");
}
getch();
}


O/P:
:::3D Array Elements:::

11      12      13
14      15      16
17      18      19

21      22      23
24      25      26
27      28      29

31      32      33
34      35      36
37      38      39

4D array

#include<stdio.h>
#include<conio.h>
void main()
{
int i, j, k,l;
int arr[3][3][3][3]=
{
{
{
{11, 12, 13},
{14, 15, 16},
{17, 18, 19}
},
{
{21, 22, 23},
{24, 25, 26},
{27, 28, 29}
},
{
{31, 32, 33},
{34, 35, 36},
{37, 38, 39}
}
},
{
            {
            {41, 42, 43},
            {44, 45, 46},
            {47, 48, 49}
            },
            {
            {51, 52, 53},
            {54, 55, 56},
            {57, 58, 59}
            },
            {
            {61, 62, 63},
            {64, 65, 66},
            {67, 68, 69}
            }
        },
{
            {
            {71, 72, 73},
            {74, 75, 76},
            {77, 78, 79}
            },
            {
            {81, 82, 83},
            {84, 85, 86},
            {87, 88, 89}
            },
            {
            {91, 92, 93},
            {94, 95, 96},
            {97, 98, 99}
            }
        }
};

printf(":::4D Array Elements:::\n\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
for(k=0;k<3;k++)
 {
for(l=0;l<3;l++)
{
printf("%d\t",arr[i][j][k][l]);
}
printf("\n");
}
printf("\n");
}
printf("\n");
}
getch();
}


O/P:
:::4D Array Elements:::

11      12      13
14      15      16
17      18      19

21      22      23
24      25      26
27      28      29

31      32      33
34      35      36
37      38      39


41      42      43
44      45      46
47      48      49

51      52      53
54      55      56
57      58      59

61      62      63
64      65      66
67      68      69


71      72      73
74      75      76
77      78      79

81      82      83
84      85      86
87      88      89

91      92      93
94      95      96
97      98      99

10.1.0 string length

#include <stdio.h>
#include<conio.h>
#include <string.h>
int main()
{
    char a[20]="Program";
    char b[20]={'P','r','o','g','r','a','m','\0'};
    char c[20];

    printf("Enter string: ");
    gets(c);

    printf("Length of string a = %d \n",strlen(a));

    //calculates the length of string before null charcter.
    printf("Length of string b = %d \n",strlen(b));
    printf("Length of string c = %d \n",strlen(c));

    return 0;
}

O/P:
Enter string: bappa saikh
Length of string a = 7
Length of string b = 7
Length of string c = 11

10.3.0 strcat strcpy

#include <stdio.h>
#include<conio.h>
#include <string.h>
int main ()
{
  char src[50], dest[50];
  strcpy(src,  "This is source");
     strcpy(dest, "This is destination ");
      strcat(dest, src);
        printf("Final destination string : |%s|", dest);
  return(0);
}


O/P:
Final destination string : |This is destination This is source|

10.4.0 strcmp

#include <stdio.h>
#include <string.h>
int main()
{
    char str1[] = "abcd", str2[] = "abCd", str3[] = "abcd";
    int result;
    // comparing strings str1 and str2
    result = strcmp(str1, str2);
    printf("strcmp(str1, str2) = %d\n", result);
    // comparing strings str1 and str3
    result = strcmp(str1, str3);
    printf("strcmp(str1, str3) = %d\n", result);
    return 0;
}
O/P:
strcmp(str1, str2) = 1
strcmp(str1, str3) = 0

10.5.0 strupr


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

int main()
{
    char str[ ] = "Modify This String To Upper";
    printf("%s\n",strupr(str));
    return  0;
}

O/P:
MODIFY THIS STRING TO UPPER

10.6.0 strlwr

#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
    char str[ ] = "MODIFY This String To LOwer";
    printf("%s\n",strlwr (str));
    return  0;
}

O/P:
modify this string to lower

10.7.0 strrev

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

int main()
{
   char name[30] = "Hello";

   printf("String before strrev( ) : %s\n",name);

   printf("String after strrev( )  : %s",strrev(name));

   return 0;
}


O/P:
String before strrev( ) : Hello
String after strrev( )  : olleH

11.0.0 return

           Return type<space>variable name(parameter);
Ex:-    void sum(int,int)

11.1.0

/* sum of two numbers */ #include<stdio.h> #include<conio.h> void sum(int,int); void main() { int a,b; printf("\n Enter 1st number: "); scanf("%d",&a); printf("\n Enter 2nd number: "); scanf("%d",&b); sum(a,b); return 0; } void sum(int x,int y) { int z; z=x+y; printf("\nThe sum is: %d",z); } O/P: Enter 1st number: 12 Enter 2nd number: 13 The sum is: 25

11.2.0 return

/* sum of two numbers */ #include<stdio.h> #include<conio.h> int sum(int,int); void main() { int a,b,c; printf("\n Enter 1st number: "); scanf("%d",&a); printf("\n Enter 2nd number: "); scanf("%d",&b); c=sum(a,b); printf("\nThe sum is: %d",c); return 0; } int sum(int x,int y) { int z; z=x+y; return z; } O/P: Enter 1st number: 12 Enter 2nd number: 13 The sum is: 25

11.3.0

/* square value */ #include<stdio.h> #include<conio.h> int sqr(int); void main() { int a,b; printf("\n Enter number: "); scanf("%d",&a); b=sqr(a); printf("\nThe square value is: %d",b); return 0; } int sqr(int x) { int z; z=x*x; return z; } O/P: Enter number: 12 The square value is: 144

12.0.0

/*call by referance*/ /* sum of two numbers*/
#include<stdio.h> #include<conio.h> void sum(int*,int*); void main() { int a,b; printf("\n Enter the 1st number: "); scanf("%d",&a); printf("\n Enter the 2nd number: "); scanf("%d",&b); sum(&a,&b); return 0; } void sum(int*x,int*y) { int z; z=*x+*y; printf("\nThe sum is: %d",z); } O/P: Enter the 1st number: 3454 Enter the 2nd number: 324 The sum is: 3778

12.0.1

/*display swaping value*/ #include<stdio.h> #include<conio.h> void swp(int*,int*); { int a,b; printf("\nEnter the 1st number: "); scanf("%d",&a); printf("\nEnter the 2nd number: "); scanf("%d",&b); swp(&a,&b); return 0; } void swp(int*x,int*y) { int z; z=*x; *x=*y; *y=z; printf("the swaping values are: %d\t%d",*x,*y); } O/P: Enter the 1st number: 11 Enter the 2nd number: 23 the swaping values are: 23 11

13.0.0

#include <stdio.h> #include <string.h> struct Books
{ char title[50]; char author[50]; char subject[100]; int book_id; }; int main( )
{ struct Books Book1; /* Declare Book1 of type Book */ struct Books Book2; /* Declare Book2 of type Book */ /* book 1 specification */ strcpy( Book1.title, "C Programming"); strcpy( Book1.author, "Nuha Ali"); strcpy( Book1.subject, "C Programming Tutorial"); Book1.book_id = 6495407; /* book 2 specification */ strcpy( Book2.title, "Telecom Billing"); strcpy( Book2.author, "Zara Ali"); strcpy( Book2.subject, "Telecom Billing Tutorial"); Book2.book_id = 6495700; /* print Book1 info */ printf( "Book 1 title : %s\n", Book1.title); printf( "Book 1 author : %s\n", Book1.author); printf( "Book 1 subject : %s\n", Book1.subject); printf( "Book 1 book_id : %d\n", Book1.book_id); /* print Book2 info */ printf( "Book 2 title : %s\n", Book2.title); printf( "Book 2 author : %s\n", Book2.author); printf( "Book 2 subject : %s\n", Book2.subject); printf( "Book 2 book_id : %d\n", Book2.book_id); return 0; } O/P: Book 1 title : C Programming Book 1 author : Nuha Ali Book 1 subject : C Programming Tutorial Book 1 book_id : 6495407 Book 2 title : Telecom Billing Book 2 author : Zara Ali Book 2 subject : Telecom Billing Tutorial Book 2 book_id : 6495700

14.0.0

/*input product making value input product's sell value */ #include<stdio.h> #include<conio.h> void main() { int a,b,c; printf("\nEnter your msking price: "); scanf("%d",&b); c=b-a; if(b>a) { printf("\nProfit is: %d",c); } else { printf("\nLoss is: %d",-c); } return 0; } O/P: Enter your msking price: 23 Enter your msking price: 45 Profit is: 22


Comments