All C program

C Notes

History of C
  • The C programming language is a general-purpose, high-level language 
  • that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs.
  •  C was originally first implemented on the DEC PDP-11 computer in 1972.
  •  In 1978, Brian Kernighan and Dennis Ritchie produced the first publicly available description of C, now known as the K&R standard. 
  • The UNIX operating system, the C compiler, and essentially all UNIX applications programs have been written in C.
  • Today's most popular Linux OS and RBDMS MySQL have been written in C
  •  The C has now become a widely used professional language for various reasons.
    •  Easy to learn 
    •  Structured language 
    • It produces efficient programs. 
    • It can handle low-level activities. 
    •  It can be compiled on a variety of computer platforms. 
C Environment Setup :

  • The C Compiler
    • The source code written in the source file is the human-readable source for your program. It needs to be "compiled", to turn into machine language so that your CPU can actually execute the program as per the instructions given.
    •  This C programming language compiler will be used to compile your source code into the final executable program. 
    • We assume you have basic knowledge about a programming language compiler. The most frequently used and the free available compiler is the GNU C/C++ compiler, otherwise, you can have compilers either from HP or Solaris if you have respective Operating Systems.
    •  The following section guides you on how to install the GNU C/C++ compiler on various OS. I'm mentioning C/C++ together because the GNU GCC compiler works for both C and C++ programming languages.


Installation on Windows 
  • To install GCC on Windows you need to install MinGW. 
  • To install MinGW, go to the MinGW homepage, www.mingw.org, and follow the link to the MinGW download page.
  •  Download the latest version of the MinGW installation program, which should be named MinGW- .exe.
  •  While installing MinWG, at a minimum, you must install GCC-core, GCC-g++, Binutils, and the MinGW runtime, but you may wish to install more. 
  • Add the bin subdirectory of your MinGW installation to your PATH environment variable, so that you can specify these tools on the command line by their simple names. 
  • When the installation is complete, you will be able to run GCC, g++, ar, ranlib, dlltool, and several other GNU tools from the Windows command line.

 simple C  code that would print the words "Hello World":
#include int main()
 { 
printf("Hello, World! \n"); 
 return 0; 



various parts of the above program are -
  • The first line of the program #include is a preprocessor command, which tells a C compiler to include stdio.h file before going to actual compilation. 
  • The next line in main() is the main function where program execution begins. 
  • The next line /*...*/ will be ignored by the compiler and it has been put to add additional comments in the program. So such lines are called comments in the program. 
  • The next line printf(...) is another function available in C that causes the message "Hello, World!" to be displayed on the screen. 
  • The next line return 0; terminates main()function and returns the value 0.



Compile & Execute C Program 
  • Let’s look at how to save the source code in a file, and how to compile and run it.
  •  Following are the simple steps: 
    • Open a text editor and add the above-mentioned code.
    • Save the file as hello.c 
    • Open a command prompt and go to the directory where you saved the file.
    • Type GCC hello.c and press enter to compile your code. 
    • If there are no errors in your code, the command prompt will take you to the next line and would generate a.out executable file. 
    • Now, type a.out to execute your program. 
    • You will be able to see "Hello World" printed on the screen 

Make sure that the GCC compiler is in your path and that you are running it in the directory containing the source file hello.c.


Tokens in C 
  • A-C program consists of various tokens and a token is either a keyword, an identifier, a constant, a string literal, or a symbol. For example, the following C statement consists of five tokens: 
    • printf("Hello, World! \n"); 
  • The individual tokens are: 
    • printf ( "Hello, World! \n" ) ; 
Semicolons ; 
  • In the C program, the semicolon is a statement terminator. That is, each individual statement must be ended with a semicolon. It indicates the end of one logical entity. 
  • For example, following are two different statements: 
    • printf("Hello, World! \n");
    •  return 0; 
Comments 
  • Comments are like helping text in your C program and they are ignored by the compiler. They start with /* and terminate with the characters */ as shown below:
    •  /* my first program in C */ 
  • You cannot have comments within comments and they do not occur within a string or character literals.
 Identifiers
  • A C identifier is a name used to identify a variable, function, or any other user-defined item. An identifier starts with a letter A to Z or a to z or an underscore _ followed by zero or more letters, underscores, and digits (0 to 9). 
  • C does not allow punctuation characters such as @, $, and % within identifiers. C is a case-sensitive programming language. Thus, Manpower and manpower are two different identifiers in C. Here are some examples of acceptable identifiers: 
    • mohd zara abc move_name a_123 
    • myname50 _temp j a23b9 retVal
Keywords 
  • The following list shows the reserved words in C. These reserved words may not be used as constant or variable or any other identifier names.

1.      Auto

2.      else

3.      long

4.      switch

5.      switch

6.      enum

7.      register

8.      typedef

9.      case

10. extern

11.  return

12.  union

13.  char

14.  float

15.  short

16. unsigned

17.  const

18.  for

19.  signed

20.  void

21. continue

22.  goto

23.  sizeof

24.  volatile

25.  default

26.  if

27.  static

28.  while

29.  do

30.  int

31. struct_packed

32.  double



Whitespace in C 
  • A line containing only whitespace, possibly with a comment, is known as a blank line, and a C compiler totally ignores it. 
  • Whitespace is the term used in C to describe blanks, tabs, newline characters, and comments. Whitespace separates one part of a statement from another and enables the compiler to identify where one element in a statement, such as an int, ends and the next element begins. Therefore, in the following statement: 
    • int age; 
  • There must be at least one whitespace character (usually a space) between int and age for the compiler to be able to distinguish them. On the other hand, in the following statement: 
    • fruit = apples + oranges; // get the total fruit
  •  No whitespace characters are necessary between fruit and =, or between = and apples, although you are free to include some if you wish for readability purposes.

C Programs

INDEX

note: click on the topic names to go to the particular topic
Sn. Topic Names
1 Addition of two numbers
2 Subtraction of two numbers
3 Multiplication of two numbers
4 Division of two numbers
5 To find the Entered number is even or odd
6 To find the Entered number is Factorial
7 To find the Square of a number using a while loop
8 To find the largest no in three numbers
9 Program to find Roots of Quadratic Equations
10 Condition for real and equal roots
11 Transposed of a Matrix
12 Input short cut for 4 by 4 matrix
13 Wap to check if a given matrix is an identity matrix
14 Multiple times printing pattern
15 My first program in a file
16 Program for file name entered through the keyboard
17 computer screen is the pass or fail
18 Lower case character to upper case character
19 To convert lower case string to upper case
20 find Entered character is upper case o lower case or digit or special Symbol
21 To find a Grade depends upon the marks out of 100
22 To print numbers start from 1 to N
23 To check no is divisible by 5 or not
24 To print all even numbers present in the given range
25 simple array
26 positive no
27 largest no
28 ascending order
29 descending order
30 even odd
31 2d array
32 Occurrence
33 Addition of 2d array
34 Multiplication of 2d array
34 Multiplication of 3d array
36 Multiplication of 4d array
37 To check if a given matrix is an identity matrix
38 Multiple times printing pattern
39 To take the info of 50 and marks of 3 subject from the user and to show its result on a computer screen
40 lower case character to upper case character
41 To convert lower case string to upper case
42 To find Entered character is upper case pr lower case or digit or special symbol







//my first program


 1. Addition of two numbers

//addition of two no

#include <stdio.h>

#include <conio.h>

void main()

{

int a,b,c;

printf("Enter two numbers for adition");

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

c=a+b;

        Printf("sum is              :", c) ;

getch();

}






 2. Substation of two numbers

//Substation of two no

#include <stdio.h>

#include <conio.h>

void main()

{

int a,b,c;

printf("Enter two numbers for substration ");

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

c=a-b;

       Printf("substration is              :", c) ;

getch();

}








3. Multiplication of two numbers

//multiplication of two no

#include <stdio.h>

#include <conio.h>

void main()

{

int a,b,c;

printf("Enter two numbers for multiplication");

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

c=a*b;

          Printf("multiplication is              :", c) ;

getch();

}









4. Division of two numbers

//division of two no

#include <stdio.h>


#include <conio.h>


void main()


{


int a,b,c;


print("Enter two numbers for division);


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


c=a+b;


          Printf("division is              :", c) ;


getch();


}









 5. To find the Entered number is even or odd

// To find entered no is even or odd

#include <stdio.h>

#include <conio.h>

void main ()

{

int a[10],j,i;

clrscr();

printf("enter a number");

scanf("%d",&i);

if(i%2==0)

{

printf("Entered no is even");

}

else

printf("odd no");

getch();

}








6. To find the Entered number is Factorial

//To find the entered no's Factorial

#include <stdio.h>

#include <conio.h>

void main()

{

int i,n,c=1;

printf("enter any no to find its factoril");

scanf("%d",&n);

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

{

c=c*i;

}

printf("%d",c)

}








7. To find the Square of a number using a while loop

// To find a square of a number using the while loop

#include <stdio.h>

#include <conio.h>

void main()

{

int i=1,n,c;

printf("enter any no");

scanf("%d",&n);

while(i<=n)

{

c=i*n;

i++;

}

printf("%d",c);

getch();

}









8. To find the largest no in three numbers


//To find the largest no in three nos

#include <stdio.h>

#include <conio.h>

void main ()

{

int a, b, c, big;

clrscr();

printf("Enter three nos");

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

big=a;

if(b>big)

big=b;

if(c>big)

big=c;

printf("largest no=%d",big);

getch();

}








9. Program to find Roots of Quadratic Equations

//Program to Find Roots of a Quadratic Equation

#include <math.h>

#include <stdio.h>

int main() {

    double a, b, c, discriminant, root1, root2, realPart, imagPart;

    printf("Enter coefficients a, b and c: ");

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

    discriminant = b * b - 4 * a * c;

    // condition for real and different roots

    if (discriminant > 0) {

        root1 = (-b + sqrt(discriminant)) / (2 * a);

        root2 = (-b - sqrt(discriminant)) / (2 * a);

        printf("root1 = %.2lf and root2 = %.2lf", root1, root2);

    }








10. Condition for real and equal roots

    // condition for real and equal roots

    else if (discriminant == 0) {

        root1 = root2 = -b / (2 * a);

        printf("root1 = root2 = %.2lf;", root1);

    }


    // if roots are not real

    else {

        realPart = -b / (2 * a);

        imagPart = sqrt(-discriminant) / (2 * a);

        printf("root1 = %.2lf+%.2lfi and root2 = %.2f-%.2fi", realPart, imagPart, realPart, imagPart);

    }


    return 0;








11. Transposed of a Matrix

//Transposed of a Matrix

#include <stdio.h>

#include <conio.h>

void main()

{

int a[3][3],i,j,temp;

    clrscr();

printf("Enter the elements of 3*3matrix");

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

{

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

{

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

}

}

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

{

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

{

if(i<j);

{

temp=a[i][j];

a[i][j]=a[j][i];

a[j][i]=temp;

}

}

}

printf("\ntrnspose of matrix");

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

{

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

{

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

}

printf("\n");

}

getch();

}








12. Input short cut foe 4 by 4 matrix

// input shortcut for 4 by 4 matrix 

#include <stdio.h>

#include <conio.h>

void main()

{

int a[4][4],b[4][4],i,j;

clrscr();

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

{

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

{

printf("Enter 12 elements");

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

}

}

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

{

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

{

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

}

}

getch();

}








13. Wap to check if a given matrix is an identtity matrix 

// C  to check if a given matrix is an identity matrix

#include <stdio.h>

 

int main (void)

{

int a[10][10];

int i = 0, j = 0, row = 0, col = 0;

 

printf ("Enter the order of the matrix (mxn):\n");

printf ("where m = number of rows; and\n");

printf ("      n = number of columns\n");

scanf ("%d %d", &row, &col);

 

int flag = 0;

 

print ("Enter the elements of the matrix\n");

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

{

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

{

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

}

}

 

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

{

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

{

if (i == j && a[i][j] != 1)

{

flag = -1;

break;

}

else if (i != j && a[i][j] != 0)

{

flag = -1;

break;

}

}

}

 

if (flag == 0)

{

printf ("It is an IDENTITY MATRIX\n");

}

else

{

printf ("It is NOT an identity matrix\n");

}

 

return 0;

}








14. Multiple times printing pattern

 // multiple times printing patterns

#include<stdio.h>

int main()

{

    int i,j, k, c;

    printf("enter any no");

    scanf("%d",&c);

    for(k=0;k<=c;k++)

   {

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

    {

        for(j=5; j>=i; j--)

        {

            printf("%d \t",j);

        }

        printf("\n");

    }

    for(i=5; i>=1; i--)

    {

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

        {

            printf("%d \t",j);

        }

        printf("\n ");

    }

  }

    return 0;

}








15. My first program in a file

//my first program in a file

#include<stdio.h>

#include<conio.h>

void main()

{

FILE *fp;

fp=fopen("HRUSHIKESH.txt","w");

fprintf(fp, "my name is HRUSHIKESH");

fclose(fp);

getch();

}








16.Program for file name entered through keyboard

// program for file name entered through the keyboard

#include<stdio.h>

#include<conio.h>

void main()

{

FILE *fp;

char n[20];

printf("enter name of file");

scanf("%s",n);

clrscr();

fp=fopen("n","w");

fprintf(fp, "my name is HRUSHIKESH");

fclose(fp);

getch();

}








17.To take info of 50 and marks of 3 subject from the user and to show its result on

17.computer screen is he pass or fail

 //To take info of 50 and marks of 3 subject from the user and to show its result on computer screen is he pass or fail

#include <stdio.h>

#include <conio.h>

void main()

{

struct student

{

char name[20];

int rno;

float m1,m2,m3;

};

struct student s[50] ;

int I;

float per;

clrscr();

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

{

printf("Enter name of student");

gets(s[i].name);

printf("enter roll no of student");

scanf("%d",&s[i].rno);

                printf("enter marks of 3 subject of student");

                        scanf("%f\n%f\n%f",&s[i].m1,&s[i].m2,&s[i].m3);

         }

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

{

printf("%s\n%d\n%f\n%f\n%f",s[i].name,s[i].rno,s[i].m1,s[i].m2,s[i].m3);

if(s[i].m1>=40&&s[i].m2>=40&&s[i].m3>=40)

{

per=(s[i].m1+s[i].m2+s[i].m3)/3.0;

printf("Result : Passssss");

printf("%f",per);

break;

}

else

printf("Result : fail");

}

getch();

}








18. Lower case character to upper case character  

// lower case character  to upper case character 

#include <stdio.h>

#include<conio.h>

void main()

{

char ch;

clrscr();

printf("Enter any lower case charecter");

scanf("%c",&ch);

ch=ch-32;

printf("upper case charecter=%c",ch);

getch();

}








19. To convert lower case string to upper case

//To convert lower case string to upper case

#include <stdio.h>

#include <string.h>

int main() 

{

   char s[100];

   int I;

   printf("\nEnter a string : ");

   gets(s);

   for (i = 0; s[i]!='\0'; i++) 

   {

       if(s[i] >= 'a' && s[i] <= 'z')

        {

          s[i] = s[i] - 32;

       }

   }

   printf("\nString in Upper Case = %s", s);

   return 0;

}








20.To find Entered character is upper case o lowere case or digit or special Symbol

// To find Entered character is upper case or lower case or digit or special symbol

#include <stdio.h>

#include <conio.h>

int main()

{

char ch;

clrscr();

printf("Ennter any character ");

scanf("%c",&ch);

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

{

printf("Upper case charecter");

}

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

{

printf("lower case charecter");

}

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

{

printf("Its a digit");

}

if(ch>=0&&ch<=47||ch>=58&&ch<=64||ch>=91&&ch<=96||ch>=123&&ch<=255)

{

printf("Its a spacial symbol");

}

getch();

return 0;

}








21. To find a Grade depends upon the marks out of100

//To find a Grade depends upon the marks out of 100

 #include <stdio.h>

#include <conio.h>

void main ()

{

int marks;

clrscr();

printf("Enter the mmarks out of 100\n");

scanf("%d",&marks);

if(marks<=34)

{

printf("GREAD F");

}

else if(marks<=44)

{

printf("GREAD E");

}

else if(marks<=59)

{

printf("GREAD D");

}

else if(marks<=69)

{

printf("GREAD C");

}

else if(marks<=79)

{

printf("GREAD B");

}

                else if(marks<=89)

                {

printf("GREAD A");

                }

            else 

            {

printf("GREAD S");

            }

getch();

}








22. To print numbers starts from 1 to N

// To print numbers starts from 1 to N,

   N is any number

#include <stdio.h>

#include <conio.h>

void main()

{

int  number, I;

printf("Enter any Number\n");

scanf("%d",&number);

printf("The number displayed are\n");

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

{

printf("%d",i);

}

getch();

}









23. To check no is divisible by 5 or not

To check no is divisible by 5 or not

#include <stdio.h>


#include <conio.h>


void main()


{


int number, I;


printf("Enter any number");


scanf("%d",&number);


if(number%5==0)


{


printf("%d is divisible by 5 ",number);


}


else


{


printf("No is not Divisible by 5");


}


getch();


}













24. To print all even numbers present in a given range

//To print all even numbers present in a given range


#include <stdio.h>


#include <conio.h>


void main()


{


int n,i,a;


clrscr();


printf("Enter any number");


scanf("%d",&n);


printf("Even nos renging from  0 to %d are",n);


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


{


    


    if(i%2==0&&i!=0)


{


printf("%d"i);


}


}


    


getch();


}















25. simple array

 //simple array


#include <stdio.h>

#include <conio.h>

main ()

{

int i, a[10],b[10], sum=0;

printf("enter 10 elements");

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

{

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

}

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

{

sum=sum+a[i];

}

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

}








26. positive no

//positive no


#include <stdio.h>

#include <conio.h>

main ()

{

int i, a[10], c=0;

printf("Enter 10 elements");

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

{

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

}


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

{

if(a[i]>0)

{

c++;

}

}


printf("positive nos are=%d",c);

getch();

}









27. largest no

//largest no


#include <stdio.h>

#include <conio.h>

main ()

{

int i, a[10], max=0;

printf("Enter 10 elements");

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

{

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

}


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

{

if(max<a[i])

{

max=a[i];

}

}


printf("largest no is=%d",max);

getch();

}










28. ascending order

//ascending order


#include <stdio.h>

#include <conio.h>

main ()

{

int i, a[10],asc,t, j;


printf("Enter 10 elements");

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

{

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

}


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

{

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

{

if(a[i]<a[j])

{

t=a[i];

a[i]=a[j];

a[j]=t;

}

}

}

printf("acending order=");

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

{

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

}

getch();

}


    










29. descending order

//descending order


#include <stdio.h>

#include <conio.h>

main ()

{

int i, a[10],asc,t, j;


printf("Enter 10 elements");

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

{

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

}


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

{

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

{

if(a[i]>a[j])

{

t=a[i];

a[i]=a[j];

a[j]=t;

}

}

}

printf("descending  order=");

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

{

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

}

getch();

}


    








30. even odd

//even odd


#include <stdio.h>

#include <conio.h>

main ()

{

int i, a[10],asc=0,t, j, c=0;


printf("Enter 10 elements");

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

{

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

}


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

{

if(a[i]%2==0)

{

c++;

}

else

{

asc++;


}

}


printf(" even%d\n",c);

printf("odd %d\n",asc);


getch();

}


    












31.2d array

//2d array


#include<stdio.h>


#include<conio.h>


void main()


{


int a[2][2],i,j,b[2][2],c[2][2];


clrscr();


//input


printf("Enter elemets of 2*2 matrix");


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


{


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


{


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


}


}


//output


printf("Elemets of matrix are\n");


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


{


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


{


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


}


}


  getch();


}















32. occurrence

//occurrence


# include<stdio.h>

#include<conio.h>

void main()

{

  int a[10],i,j,count=0,num;

  clrscr ();

// input

  printf("enter the 10 elements");

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

{

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

  }

printf("enter any no");

scanf("%d",&num);

//output

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

   {

     if(a[i]==num)

    {

       count=count+1;

       

     }

   }

//output

  printf(" it occures=%dtimes\n",count);

getch();

}














33. addition of 2d array

// addition of 2d array

#include<stdio.h>

#include<conio.h>

main()

{

int a[2][2],i,j,b[2][2],c[2][2];

clrscr();

            //input

printf("Enter elemets of 2*2 matrix1\n");

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

    {

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

        {

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

        }

    }

printf("Enter elemets of 2*2 matrix2\n");

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

    {

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

        {

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

        }

    }

   

    //process

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

    {

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

        {

c[i][j]=a[i][j]+b[i][j];

        }

     }

                      //output

printf("Elemets of matrix are\n");

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

    {

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

        {

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

        }

    }

getch();

}














34. multiplication of 2d array

//multiplication of 2d array

#include<stdio.h>

#include<conio.h>

main()

{

int a[2][2],i,j,b[2][2],c[2][2],k;

clrscr();

            //input

printf("Enter elemets of 2*2 matrix1\n");

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

    {

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

        {

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

        }

    }

printf("Enter elemets of 2*2 matrix2\n");

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

    {

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

        {

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

        }

    }

   

    //process

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

    {

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

      {

    c[i][j]=0;

    for(k=0;k<=1;k++)

        {

c[i][j]=c[i][j]+(a[i][k]*b[k][j]);

        }

     }

    }                  //output

printf("Elemets of matrix are\n");

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

    {

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

        {

        printf("%d\t",c[i][j]);

        }

        printf("\n");

    }

getch();

}















35. multiplication of 3d array

// multiplication of 3d array

#include<stdio.h>

#include<conio.h>

main()

{

int a[3][3],i,j,b[3][3],c[3][3],k;

clrscr();

            //input

printf("Enter elemets of 3*3 matrix1\n");

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

    {

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

        {

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

        }

    }

printf("Enter elemets of 3*3 matrix2\n");

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

    {

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

        {

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

        }

    }

   

    //process

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

    {

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

      {

    c[i][j]=0;

    for(k=0;k<=2;k++)

        {

c[i][j]=c[i][j]+(a[i][k]*b[k][j]);

        }

     }

    }                  //output

printf("Elemets of matrix are\n");

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

    {

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

        {

        printf("%d\t",c[i][j]);

        }

        printf("\n");

    }

getch();

}

















36. multiplication of 4d array

// multiplication of 4d array

#include<stdio.h>

#include<conio.h>

main()

{

int a[4][4],i,j,b[4][4],c[4][4],k;

clrscr();

            //input

printf("Enter elemets of 4*4 matrix1\n");

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

    {

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

        {

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

     

        }

      

    }

printf("Enter elemets of 4*4 matrix2\n");

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

    {

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

        {

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

        }

     

    }

   

    //process

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

    {

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

      {

    c[i][j]=0;

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

        {

c[i][j]=c[i][j]+(a[i][k]*b[k][j]);

        }

     }

    }                  //output

printf("Elemets of matrix are\n");

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

    {

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

        {

        printf("%d\t",c[i][j]);

        }

        printf("\n");

    }

getch();

}

















 

37. to check if a given matrix is an identity matrix

// C  to check if a given matrix is an identity matrix

#include <stdio.h>

 

int main (void)

{

int a[10][10];

int i = 0, j = 0, row = 0, col = 0;

 

printf ("Enter the order of the matrix (mxn):\n");

printf ("where m = number of rows; and\n");

printf ("      n = number of columns\n");

scanf ("%d %d", &row, &col);

 

int flag = 0;

 

printf ("Enter the elements of the matrix\n");

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

{

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

{

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

}

}

 

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

{

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

{

if (i == j && a[i][j] != 1)

{

flag = -1;

break;

}

else if (i != j && a[i][j] != 0)

{

flag = -1;

break;

}

}

}

 

if (flag == 0)

{

printf ("It is an IDENTITY MATRIX\n");

}

else

{

printf ("It is NOT an identity matrix\n");

}

 

return 0;

}












38. multiple times printing pattern

 // multiple times printing patterns


#include<stdio.h>


int main()


{


    int i,j, k, c;


    printf("enter any no");


    scanf("%d",&c);


    


    for(k=0;k<=c;k++)


   {


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


    {


        for(j=5; j>=i; j--)


        {


            printf("%d \t",j);


        }


        printf("\n");


    }




    for(i=5; i>=1; i--)


    {


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


        {


            printf("%d \t",j);


        }


        printf("\n ");


    }


  }


    return 0;


}










 






39. To take the info of 50 and marks of 3 subject from the user and to show its result on a computer screen

 //To take info of 50 and marks of 3 subject from the user and to show its result on computer screen is he pass or fail


#include <stdio.h>


#include <conio.h>


void main()


{


struct student


{


char name[20];


int rno;


float m1,m2,m3;


};


struct student s[50] ;


int I;


float per;



clrscr();


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


{


printf("Enter name of student");


gets(s[i].name);



printf("enter roll no of student");


scanf("%d",&s[i].rno);



            printf("enter marks of 3 subject of student");


            scanf("%f\n%f\n%f",&s[i].m1,&s[i].m2,&s[i].m3);



}


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


{


printf("%s\n%d\n%f\n%f\n%f",s[i].name,s[i].rno,s[i].m1,s[i].m2,s[i].m3);


if(s[i].m1>=40&&s[i].m2>=40&&s[i].m3>=40)


{


per=(s[i].m1+s[i].m2+s[i].m3)/3.0;


printf("Result : Passssss");


printf("%f",per);


break;


}


else


printf("Result : fail");


}


getch();


}











40. lower case character to upper case character

 // lower case character to upper case character


#include <stdio.h>


#include<conio.h>


void main()


{


char ch;


clrscr();


printf("Enter any lower case charecter");


scanf("%c",&ch);


ch=ch-32;


printf("upper case charecter=%c",ch);


getch();


}













41. To convert lower case string to upper case

//To convert lower case string to upper case


#include <stdio.h>


#include <string.h>


int main() 


{


   char s[100];


   int I;


   printf("\nEnter a string : ");


   gets(s);


   for (i = 0; s[i]!='\0'; i++) 


   {


       if(s[i] >= 'a' && s[i] <= 'z')


       {


          s[i] = s[i] - 32;


       }


   }


   printf("\nString in Upper Case = %s", s);


   return 0;


}













42.To find Entered character is uppar case pr lower case or digit or special symbol

// To find Entered character is upper case pr lower case or digit or special symbol


#include <stdio.h>


#include <conio.h>


int main()


{


char ch;


clrscr();


printf("Ennter any character ");


scanf("%c",&ch);


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


{


printf("Upper case charecter");


}


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


{


printf("lower case charecter");


}


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


{


printf("Its a digit");


}


if(ch>=0&&ch<=47||ch>=58&&ch<=64||ch>=91&&ch<=96||ch>=123&&ch<=255)


{


printf("Its a spacial symbol");


}


getch();


return 0;


}















Comments