compuhelpindia@gmail.com | +91-9915005347 | +91-8283825347 Sector 46-C, Chandigarh · Since 1999 Apply Now

C Programming HelpDesk

COMPUHELP HelpDesk

C Programming HelpDesk

Interview Q&A, solved assignments & practice on this site

101Interview Q&A
161Solved Programs
PDFUnsolved
LabPractice

C Interview Questions

C programming interview Q&A.

What is a pointer on pointer?

It’s a pointer variable which can hold the address of another pointer variable. It de-refers twice to point to the data held by the designated pointer variable. Eg: int x = 5, *p=&x, **q=&p; Therefore ‘x’ can be accessed by **q.

Distinguish between malloc() & calloc() memory allocation.

Both allocates memory from heap area/dynamic memory. By default calloc fills the allocated memory with 0’s.

What is keyword auto for?

By default every local variable of the function is automatic (auto). In the below function both the variables ‘i’ and ‘j’ are automatic variables.

What are the valid places for the keyword break to appear.

Break can appear only with in the looping control and switch statement. The purpose of the break is to bring the control out from the said blocks.

Explain the syntax for for loop.

for(expression-1;expression-2;expression-3) { //set of statements } When control reaches for expression-1 is executed first. Then following expression-2, and if expression-2 evaluates to non-zero ‘set of statements’ and expression-3 is executed, follows expression-2.

What is difference between including the header file with-in angular braces < > and double quotes “ “

If a header file is included with in < > then the compiler searches for the particular header file only with in the built in include path. If a header file is included with in “ “, then the compiler searches for the particular header file first in the current working directory, if not found then in the built in include path.

What are the valid places for the keyword break to appear.

Break can appear only with in the looping control and switch statement. The purpose of the break is to bring the control out from the said blocks.

How a negative integer is stored.

Get the two’s compliment of the same positive integer. Eg: 1011 (-5) Step-1 − One’s compliment of 5 : 1010 Step-2 − Add 1 to above, giving 1011, which is -5

What is a static variable?

A static local variables retains its value between the function call and the default value is 0. The following function will print 1 2 3 if called thrice. void f() { static int i; ++i; printf(“%d “,i); } If a global variable is static then its visibility is limited to the same source code.

What is a NULL pointer?

A pointer pointing to nothing is called so. Eg: char *p=NULL;

What is the purpose of extern storage specifier?

Used to resolve the scope of global symbol. Eg: main() { extern int i; Printf(“%d”,i); } int i = 20;

Explain the purpose of the function sprintf().

Prints the formatted output onto the character array.

What is the meaning of base address of the array?

The starting address of the array is called as the base address of the array.

When should we use the register storage specifier?

If a variable is used most frequently then it should be declared using register storage specifier, then possibly the compiler gives CPU register for its storage to speed up the look up of the variable.

S++ or S = S+1, which can be recommended to increment the value by 1 and why?

S++, as it is single machine instruction (INC) internally.

What is a dangling pointer?

A pointer initially holding valid address, but later the held address is released or freed. Then such a pointer is called as dangling pointer.

What is the purpose of the keyword typedef?

It is used to alias the existing type. Also used to simplify the complex declaration of the type.

What is lvalue and rvalue?

The expression appearing on right side of the assignment operator is called as rvalue. Rvalue is assigned to lvalue, which appears on left side of the assignment operator. The lvalue should designate to a variable not a constant.

What is the difference between actual and formal parameters?

The parameters sent to the function at calling end are called as actual parameters while at the receiving of the function definition called as formal parameters.

Can a program be compiled without main() function?

Yes, it can be but cannot be executed, as the execution requires main() function definition.

What is the advantage of declaring void pointers?

When we do not know what type of the memory address the pointer variable is going to hold, then we declare a void pointer for such.

Where an automatic variable is stored?

Every local variable by default being an auto variable is stored in stack memory.

What is a nested structure?

A structure containing an element of another structure as its member is referred so.

What is the difference between variable declaration and variable definition?

Declaration associates type to the variable whereas definition gives the value to the variable.

What is a self-referential structure?

A structure containing the same structure pointer variable as its element is called as self-referential structure.

Does a built-in header file contains built-in function definition?

No, the header file only declares function. The definition is in library which is linked by the linker.

Explain modular programming.

Dividing the program in to sub programs (modules/function) to achieve the given task is modular approach. More generic functions definition gives the ability to re-use the functions, such as built-in library functions.

What is a token?

A C program consists of various tokens and a token is either a keyword, an identifier, a constant, a string literal, or a symbol.

What is a preprocessor?

Preprocessor is a directive to the compiler to perform certain things before the actual compilation process begins.

Explain the use of %i format specifier w.r.t scanf().

Can be used to input integer in all the supported format.

How can you print a (backslash) using any of the printf() family of functions.

Escape it using (backslash).

Does a break is required by default case in switch statement?

Yes, if it is not appearing as the last case and if we do not want the control to flow to the following case after default if any.

When to user -> (arrow) operator.

If the structure/union variable is a pointer variable, to access structure/union elements the arrow operator is used.

What are bit fields?

We can create integer structure members of differing size apart from non-standard size using bit fields. Such structure size is automatically adjusted with the multiple of integer size of the machine.

What are command line arguments?

The arguments which we pass to the main() function while executing the program are called as command line arguments. The parameters are always strings held in the second argument (below in args) of the function which is array of character pointers. First argument represents the count of arguments (below in count) and updated automatically by operating system. main( int count, char *args[]) { }

What are the different ways of passing parameters to the functions? Which to use when?

Call by value − We send only values to the function as parameters. We choose this if we do not want the actual parameters to be modified with formal parameters but just used. Call by reference − We send address of the actual parameters instead of values. We choose this if we do want the actual parameters to be modified with formal parameters.

What is the purpose of built-in stricmp() function.

It compares two strings by ignoring the case.

Describe the file opening mode “w+”.

Opens a file both for reading and writing. If a file is not existing it creates one, else if the file is existing it will be over written.

Where the address of operator (&) cannot be used?

It cannot be used on constants. It cannot be used on variable which are declared using register storage class.

Is FILE a built-in data type?

No, it is a structure defined in stdio.h.

What is reminder for 5.0 % 2?

Error, It is invalid that either of the operands for the modulus operator (%) is a real number.

How many operators are there under the category of ternary operators?

There is only one operator and is conditional operator (? : ).

Which key word is used to perform unconditional branching?

goto

What is a pointer to a function? Give the general syntax for the same.

A pointer holding the reference of the function is called pointer to a function. In general it is declared as follows. T (*fun_ptr) (T1,T2…); Where T is any date type. Once fun_ptr refers a function the same can be invoked using the pointer as follows. fun_ptr(); [Or] (*fun_ptr)();

Explain the use of comma operator (,).

Comma operator can be used to separate two or more expressions. Eg: printf(“hi”) , printf(“Hello”);

What is a NULL statement?

A null statement is no executable statements such as ; (semicolon). Eg: int count = 0; while( ++count Above does nothing 10 times.

What is a static function?

A function’s definition prefixed with static keyword is called as a static function. You would make a function static if it should be called only within the same source code.

Which compiler switch to be used for compiling the programs using math library with gcc compiler?

Opiton –lm to be used as > gcc –lm <file.c>

Which operator is used to continue the definition of macro in the next line?

Backward slash () is used. E.g. #define MESSAGE "Hi, Welcome to C"

Which operator is used to receive the variable number of arguments for a function?

Ellipses (…) is used for the same. A general function definition looks as follows void f(int k,…) { }

Which operator is used to receive the variable number of arguments for a function?

Ellipses (…) is used for the same. A general function definition looks as follows void f(int k,…) { }

Which built-in library function can be used to re-size the allocated dynamic memory?

realloc() .

Define an array.

Array is collection of similar data items under a common name.

What are enumerations?

Enumerations are list of integer constants with name. Enumerators are defined with the keyword enum .

Which built-in function can be used to move the file pointer internally?

fseek()

What is a variable?

A variable is the name storage.

Who designed C programming language?

Dennis M Ritchie.

C is successor of which programming language?

B

What is the full form of ANSI?

American National Standards Institute.

Which operator can be used to determine the size of a data type or variable?

sizeof

Can we assign a float variable to a long integer variable?

Yes, with loss of fractional part.

Is 068 a valid octal number?

No, it contains invalid octal digits.

What it the return value of a relational operator if it returns any?

Return a value 1 if the relation between the expressions is true, else 0.

How does bitwise operator XOR works.

If both the corresponding bits are same it gives 0 else 1.

What is an infinite loop?

A loop executing repeatedly as the loop-expression always evaluates to true such as while(0 == 0) { }

Can variables belonging to different scope have same name? If so show an example.

Variables belonging to different scope can have same name as in the following code snippet. int var; void f() { int var; } main() { int var; }

What is the default value of local and global variables?

Local variables get garbage value and global variables get a value 0 by default.

Can a pointer access the array?

Pointer by holding array’s base address can access the array.

What are valid operations on pointers?

The only two permitted operations on pointers are Comparision ii) Addition/Substraction (excluding void pointers)

What is a string length?

It is the count of character excluding the ‘’ character.

What is the built-in function to append one string to another?

strcat() form the header string.h

Which operator can be used to access union elements if union variable is a pointer variable?

Arrow (->) operator.

Explain about ‘stdin’.

stdin in a pointer variable which is by default opened for standard input device.

Name a function which can be used to close the file stream.

fclose().

What is the purpose of #undef preprocessor?

It be used to undefine an existing macro definition.

Define a structure.

A structure can be defined of collection of heterogeneous data items.

Name the predefined macro which be used to determine whether your compiler is ANSI standard or not?

__STDC__

What is typecasting?

Typecasting is a way to convert a variable/constant from one type to another type.

What is recursion?

Function calling itself is called as recursion.

Which function can be used to release the dynamic allocated memory?

free().

What is the first string in the argument vector w.r.t command line arguments?

Program name.

How can we determine whether a file is successfully opened or not using fopen() function?

On failure fopen() returns NULL, otherwise opened successfully.

What is the output file generated by the linker.

Linker generates the executable file.

What is the maximum length of an identifier?

Ideally it is 32 characters and also implementation dependent.

What is the default function call method?

By default the functions are called by value.

Functions must and should be declared. Comment on this.

Function declaration is optional if the same is invoked after its definition.

When the macros gets expanded?

At the time of preprocessing.

Can a function return multiple values to the caller using return reserved word?

No, only one value can be returned to the caller.

What is a constant pointer?

A pointer which is not allowed to be altered to hold another address after it is holding one.

To make pointer generic for which date type it need to be declared?

Void

Can the structure variable be initialized as soon as it is declared?

Yes, w.r.t the order of structure elements only.

Is there a way to compare two structure variables?

There is no such. We need to compare element by element of the structure variables.

Which built-in library function can be used to match a patter from the string?

Strstr()

What is difference between far and near pointers?

In first place they are non-standard keywords. A near pointer can access only 2^15 memory space and far pointer can access 2^32 memory space. Both the keywords are implementation specific and are non-standard.

Can we nest comments in a C code?

No, we cannot.

Which control loop is recommended if you have to execute set of statements for fixed number of times?

for – Loop.

What is a constant?

A value which cannot be modified is called so. Such variables are qualified with the keyword const.

Can we use just the tag name of structures to declare the variables for the same?

No, we need to use both the keyword ‘struct’ and the tag name.

Can the main() function left empty?

Yes, possibly the program doing nothing.

Can one function call another?

Yes, any user defined function can call any function.

Apart from Dennis Ritchie who the other person who contributed in design of C language.

Brain Kernighan

Solved Assignments of C

Solved C programs by topic — if/else, loops, arrays, pointers, structures, files.

Assignments of If and If..Else Statements (13 programs)
#include<stdio.h>
    int main()
    {
    int marks;
    printf("Enter marks");
    scanf("%d",&marks);
    if(marks>=80 && marks<=100)
    {
    printf("A Grade");
    }
    else if(marks>=60 && marks<80)
    {
    printf("B Grade");
    }
    else if(marks>=40 && marks<60)
    {
    printf("C Grade");
    }
    else if(marks>=0 && marks<40)
    {
    printf("Fail");
    }
    }
#include<stdio.h>
    int main()
    {
    int num;
    printf("Enter any number");
    scanf("%d",&num);
    if(num>0)
    {
    printf("Number is Positive");
    }
    else if(num<0)
    {
    printf("Number is Negative");
    }
    else if(num==0)
    {
    printf("Number is Zero");
    }
    }
#include<stdio.h>
    int main()
    {
    int num;
    printf("Enter any number");
    scanf("%d",&num);
    if(num%2==0)
    {
    printf("Number is even");
    }
    else 
    {
    printf("Number is odd");
    }
    }
#include<stdio.h>
    int main()
    {
    char ch;
    printf("Enter any character");
    scanf("%c",&ch);
if(ch=='a'||ch=='A'||ch=='e'||ch=='E'||ch=='i'||ch=='I'||ch=='o'||ch=='O'||ch=='u'||ch=='U')
    {
    printf("character is vowel");
    }
    else 
    {
    printf("character is consonant");
    }
    }
#include<stdio.h>
     int main()
    {
    char ch;
    printf("Enter any character");
    scanf("%c",&ch);
    if(ch=='a'||ch=='A'||ch=='e'||ch=='E'||ch=='i'||ch=='I'||ch=='o'||ch=='O'||ch=='u'||ch=='U')
    {
    printf("character is vowel");
    }
    else if(ch=='@'||ch=='!'||ch=='#'||ch=='%'||ch=='&'||ch=='*')
    {
    printf("character is special");
    }
    else
    {
    printf("character is consonant");
    }
     
    }
#include<stdio.h>
    int main()
    {
    int num;
    printf("Print any number between 1 to 7:");
    scanf("%d",&num);
    if(num==1)
    {
    printf("Day is Monday");
    }
    else if(num==2)
    {
    printf("Day is Tuesday");
    }
    else if(num==3)
    {
    printf("Day is Wednesday");
    }
    else if(num==4)
    {
    printf("Day is Thursday");
    }
    else if(num==5)
    {
    printf("Day is Friday");
    }
    else if(num==6)
    {
    printf("Day is Saturday");
    }
    else if(num==7)
    {
    printf("Day is Sunday");
    }
    }
#include<stdio.h>
    int main()
    {
    int num;
    printf("Print any number between 0 and 9:");
    scanf("%d",&num);
    if(num==0)
    {
    printf("You entered Zero");
    }
    else if(num==1)
    {
    printf("You entered One");
    }
    else if(num==2)
    {
    printf("You entered Two");
    }
    else if(num==3)
    {
    printf("You entered Three");
    }
    else if(num==4)
    {
    printf("You entered Four");
    }
    else if(num==5)
    {
    printf("You entered Five");
    }
    else if(num==6)
    {
    printf("You entered Six");
    }
    else if(num==7)
    {
    printf("You entered Seven");
    }
    else if(num==8)
    {
    printf("You entered Eight");
    }
    else if(num==9)
    {
    printf("You entered Nine");
    }
    else
    {
    printf("wrong input");
    }
    }
#include<stdio.h>
 int main()
    {
    int num;
    printf("Print any number between 1 and 12:");
    scanf("%d",&num);
    if(num==1)
    {
    printf("You entered January");
    }
    else if(num==2)
    {
    printf("You entered February");
    }
    else if(num==3)
    {
    printf("You entered March");
    }
    else if(num==4)
    {
    printf("You entered April");
    }
    else if(num==5)
    {
    printf("You entered May");
    }
    else if(num==6)
    {
    printf("You entered June");
    }
    else if(num==7)
    {
    printf("You entered July");
    }
    else if(num==8)
    {
    printf("You entered August");
    }
    else if(num==9)
    {
    printf("You entered September");
    }
    else if(num==10)
    {
    printf("You entered October");
    }
        else if(num==11)
    {
    printf("You entered November");
    }
        else if(num==12)
    {
    printf("You entered December");
    }
    else
    {
    printf("wrong input");
    }
    }
#include<stdio.h>
    #include<stdlib.h>
    
    int main()
    {
    int choice,num1,num2,res;
    printf("nPress 1 for addition");
    printf("nPress 2 for subtraction");
    printf("nPress 3 for multiplication");
    printf("nPress 4 for division");
    printf("nPress 5 for exit");
    scanf("%d",&choice);
    printf("nEnter first number:");
    scanf("%d",&num1);
    printf("nEnter second number:");
    scanf("%d",&num2);
    if(choice==1)
    {
    res=num1+num2;
    printf("The sum is: %d",res);
    }
    else if(choice==2)
    {
    res=num1-num2;
    printf("The sum is: %d",res);
    }
    else if(choice==3)
    {
    res=num1*num2;
    printf("The sum is: %d",res);
    }
    else if(choice==4)
    {
    res=num1/num2;
    printf("The sum is: %d",res);
    }
    else if(choice==5)
    {
    exit(0);
    }
    }
#include<stdio.h>
    int main()
    {
    int a, b ,c;
    printf("nEnter first number:");
    scanf("%d",&a);
    printf("nEnter second number:");
    scanf("%d",&b);
    printf("nEnter third number:");
    scanf("%d",&c);
    
    if(a>b)
    {
    	if(a>c)
        {
    		printf("First number is greater");
        }
    	else
    	{
   			printf("nThird number is greater");
    	}
     }
    else
    {
    	if(b>c)
    	{
    		printf("nSecond number is greater");
    	}
    	else
        {
		    printf("Third number is greater");
         }
    }
#include<stdio.h>
   	  int main()
      {
        int year;
        printf("Enter the year: ");
        scanf("%d",&year);
        if( ((year%4==0) && (year%100 !=0)) || (year%400==0))
        {
          printf("Year is Leap year");
      	}
      	else
      	{
          printf("Not a leap year");
      	}
      	return 0;
      }//end of main
#include<stdio.h>
   	  int main()
      {
        /* Input character from user */
        printf("Enter any character: ");
        scanf("%c", &ch);
    
    
        /* Alphabet check */
        if((ch >= 'a' && ch = 'A' && ch = '0' && ch <= '9')
        {
            printf("'%c' is digit.", ch);
        }
        else
        {
            printf("'%c' is special character.", ch);
        }
      	return 0;
      }//end of main
include<stdio.h>
   	int main()
    {
        int month;

        /* Input month number from user */
        printf("Enter month number (1-12): ");
        scanf("%d", &month);
    
        if(month == 1)
        {
            printf("31 days");
        }
        else if(month == 2)
        {
            printf("28 or 29 days");
        }
        else if(month == 3)
        {
            printf("31 days");
        }
        else if(month == 4)
        {
            printf("30 days");
        }
        else if(month == 5)
        {
            printf("31 days");
        }
        else if(month == 6)
        {
            printf("30 days");
        }
        else if(month == 7)
        {
            printf("31 days");
        }
        else if(month == 8)
        {
            printf("31 days");
        }
        else if(month == 9)
        {
            printf("30 days");
        }
        else if(month == 10)
        {
            printf("31 days");
        }
        else if(month == 11)
        {
            printf("30 days");
        }
        else if(month == 12)
        {
            printf("31 days");
        }
        else
        {
            printf("Invalid input! Please enter month number between (1-12).");
        }
      	return 0;
      }//end of main
Assignments of Switch Statement (7 programs)
#include<stdio.h>
    int main()
    {
    int num;
    printf("enter any number between 0 to 9:");
    scanf("%d",&num);
    switch(num)
    {
    case 0:
    printf("You entered ZERO");
    break;
    case 1:
    printf("You entered ONE");
    break;
    case 2:
    printf("You entered TWO");
    break;
    case 3:
    printf("You entered THREE");
    break;
    case 4:
    printf("You entered FOUR");
    break;
    case 5:
    printf("You entered FIVE");
    break;
    case 6:
    printf("You entered SIX");
    break;
    case 7:
    printf("You entered SEVEN");
    break;
    case 8:
    printf("You entered EIGHT");
    break;
    case 9:
    printf("You entered NINE");
    break;
    default:
    printf("wrong input");
    }
   }
#include<stdio.h>
    int main()
    {
    int num;
    printf("enter any number between 1 to 12:");
    scanf("%d",&num);
    switch(num)
    {
    case 1:
    printf("You entered JANUARY");
    break;
    case 2:
    printf("You entered FEBURARY");
    break;
    case 3:
    printf("You entered MARCH");
    break;
    case 4:
    printf("You entered APRIL");
    break;
    case 5:
    printf("You entered MAY");
    break;
    case 6:
    printf("You entered JUNE");
    break;
    case 7:
    printf("You entered JULY");
    break;
    case 8:
    printf("You entered AUGUST");
    break;
    case 9:
    printf("You entered SEPTEMBER");
    break;
     case 10:
    printf("You entered OCTOBER");
    break;
    case 11:
    printf("You entered NOVEMBER");
    break;
    case 12:
    printf("You entered DECEMBER");
    break;
    default:
    printf("wrong input");
    }
   }
#include<stdio.h>
    int main()
    {
    int num;
    printf("enter any number between 1 to 7:");
    scanf("%d",&num);
    switch(num)
    {
    case 1:
    printf("You entered SUNDAY");
    break;
    case 2:
    printf("You entered MONDAY");
    break;
    case 3:
    printf("You entered TUESDAY");
    break;
    case 4:
    printf("You entered WEDNESDAY");
    break;
    case 5:
    printf("You entered THURSDAY");
    break;
    case 6:
    printf("You entered FRIDAY");
    break;
    case 7:
    printf("You entered SATURDAY");
    break;
    default:
    printf("wrong input");
    }
   }
#include<stdio.h>
    int main()
    {
    char ch;
    printf("Enter any character in lowercase:");
    scanf("%c",&ch);
    switch(ch)
    {
    case 'a':
    printf("Character is vowel");
    break;
    case 'e':
    printf("Character is vowel");
    break;
    case 'i':
    printf("Character is vowel");
    break;
    case 'o':
    printf("Character is vowel");
    break;
    case 'u':
     printf("Character is vowel");
    break;
    default:
    printf("character is consonant");
   }
   return 0;
 }
#include<stdio.h>
    #include<stdlib.h> 
    int main()
    {
    int num1,num2,res;
    int value;
    printf("Enter first number:");
    scanf("%d",&num1);
    printf("Enter second number:");
    scanf("%d",&num2);
    printf("n Press 1 for addition");
    printf("n Press 2 for subtraction");
    printf("n Press 3 for division");
    printf("n Press 4 for multiplication");
    printf("n Press 5 for EXIT");
    printf("n");
    scanf("%d",&value);
    switch(value)
    {
    case 1:
    res=num1+num2;
    printf("The sum is:%d",res);
    break;
    
    case 2:
    res=num1-num2;
    printf("The subtraction is:%d",res);
    break;
   
    case 3:
    res=num1/num2;
    printf("The division is:%d",res);
    break;
    
    case 4:
    res=num1*num2;
    printf("The multiplication is:%d",res);
    break;
    
    case 5:
    exit(0);
    break;
    
    default:
    printf("Wrong input.Try Again!");
    }
    return 0;  
  }
#include<stdio.h>
       #include<stdlib.h>
       int main()
       {
       int x=0,y=1,z,i,fac=1;
       int value;
       printf("n Press 1 for fibbonacci series");
       printf("n Press 2 for factorial");
       printf("n Press 3 for printing even series");
       printf("n Press 4 for printing odd series");
       printf("n Press 5 for EXIT");
       printf("n");
       scanf("%d",&value);
       switch(value)
       {
       case 1:
       printf("Fibbonacci series is:");
       printf("%d %d",x,y);
       for(i=1;i<=8;i++)
       {
       z=x+y;
       x=y;
       y=z;
       printf(" %d",z);
       }
       break;
       case 2:
       for(i=1;i<=5;i++)
       {
       fac=fac*i;
       }
       printf("factorial of 5 is:%d",fac);
       break;
       case 3:
       printf("even series is:");
       for(i=0;i<=10;i=i+2)
       {
       printf("%d ",i);
       }
       break;
       case 4:
       printf("odd series is:");
       for(i=1;i<=10;i=i+2)
       {
       printf("%d ",i);
       }
       case 5:
       exit(0);
       break;
       default:
       printf("wrong input,Please try again");
       }}
#include<stdio.h>
       #include<stdlib.h>
       int main()
       {
       int value,n;
       char a;
       int x=0,y=1,z,i,fac=1;
       printf("n Press 1 for even numbers");
       printf("n Press 2 for odd numbers");
       printf("n Press 3 for square of the number");
       printf("n Press 4 for character series");
       printf("n Press 5 for EXIT");
       printf("n");
       scanf("%d",&value);
       switch(value)
       {
       case 1:
       printf("Enter nth number:");
       scanf("%d",&n);
       printf("even series is:");
       for(i=0;i<=n;i=i+2)
       {
       printf("%d ",i);
       }
       break;
       case 2:
       printf("Enter nth number:");
       scanf("%d",&n);
       printf("odd series is:");
       for(i=1;i<=n;i=i+2)
       {
       printf("%d ",i);
       }
       break;
       case 3:
       printf("Enter nth number:");
       scanf("%d",&n);
       printf("the square is: %d",n*n);
       break;
       case 4:
       printf("n Enter any character in lowercase:");
       scanf("%s",&a);
       for(i=97;a<=122;a++)
       {
       printf("%c ",a);
       }
       break;
       case 5:
       exit(0);
       break;
       default:
       {
       printf("wrong input");
       }
       break;
       }}
Assignments of For Loop (17 programs)
#include<stdio.h>
    int main()
    {
    int i;
    for(i=1;i<=10;i++)
    {
    printf("*");
    }
    }
#include<stdio.h>
    int main()
    {
    int i;
    for(i=1;i<=7;i++)
    {
    printf("*");
    printf("n");
    }
    }
#include<stdio.h>
    int main()
    {
    int i;
    for(i=1;i<=6;i++)
    {
    printf("    *");
    printf("nCOMPUHELPn");
    }
    }
#include<stdio.h>
    int main()
    {
    int i;
    for(i=0;i<=9;i++)
    {
    printf("%d ",i);
    }
    }
#include<stdio.h>
    int main()
    {
    int i;
    for(i=9;i>=0;i--)
    {
    printf("%d ",i);
    }
    }
#include<stdio.h>
    int main()
    {
    int i;
    for(i=5;i<=20;i++)
    {
    printf("%d ",i);
    }
    }
#include<stdio.h>
    int main()
    {
    int i;
    for(i=45;i>=7;i--)
    {
    printf("%d ",i);
    }
    }
#include<stdio.h>
    int main()
    {
    int i;
    for(i=1;i<=20;i+=2)
    {
    printf("%dn",i);
    }
    }
#include<stdio.h>
    int main()
    {
    int i;
    for(i=0;i<=20;i+=2)
    {
    printf("%dn",i);
    }
    }
#include<stdio.h>
    int main()
    {
    int i,num;
    printf("Enter number ");
    scanf("%d",&num);
    for(i=1;i<=num;i+=2)
    {
    printf("%dn",i);
    }
    }
#include<stdio.h>
    int main()
    {
    int i,num;
    printf("Enter number ");
    scanf("%d",&num);
    for(i=0;i<=num;i+=2)
    {
    printf("%dn",i);
    }
    }
#include<stdio.h>
    int main()
    {
    int i;
    for(i=0;i<=50;i+=3)
    {
    printf("%dn",i);
    }
    }
#include<stdio.h>
    int main()
    {
    int i,num,a=0,b=1,res=0;
    printf("Enter the number till you want to print the fibonacci series : ");
    scanf("%d",&num);
    printf("%d %d",a,b);
    for(i=0;res<=num;i++)
    {
    res=a+b;
    a=b;
    b=res;
    printf(" %d",res);
    }
   }
#include<stdio.h>
    int main()
    {
    int i,num,prod=1;
    printf("Enter the number till you want to print the series : ");
    scanf("%d",&num);
    for(i=0;prod<=num;i++)
    {
     printf(" %d",prod);
     prod=2*prod;
    }
    }
#include<stdio.h>
    int main()
    {
    int i,num,fact=1;
    printf("Enter the number whose factorial you want to print: ");
    scanf("%d",&num);
    for(i=1;i<=num;i++)
    {
    fact=fact*i;
     printf("%d*",i);
    }
    printf("b=%d",fact);
    }
#include<stdio.h>
    int main()
    {
    int i,num,sum=0;
    printf("Enter the number whose sum of series you want to print: ");
    scanf("%d",&num);
    for(i=1;i<=num;i++)
    {
    sum=sum+i;
    printf("%d+",i);
    }
    printf("b=%d",sum);
    }
#include<stdio.h>
    int main()
    {
    int m,n,i,res=1;
    printf("Enter the value for m and n");
	scanf("%d%d",&m,&n);
	for(i=1;i<=n;i++)
	{
 	res=res*m;
	}
	printf("%d",res);
    }
Assignments of Nested For Loop (24 programs)
#include<stdio.h>
    int main()
    {
    int row,col;
    for(row=1;row<=3;row++)
    {
    for(col=1;col<=3;col++)
    {
    printf("*");
    }
    printf("n");
    }
    }
#include<stdio.h>
    int main()
    {
    int row,col,k=1;
    for(row=1;row<=3;row++)
    {
    for(col=1;col<=3;col++)
    {
    printf("%d",k);
    }
    printf("n");
    }
    }
#include<stdio.h>
    int main()
    {
    int row,col;
    for(row=1;row<=3;row++)
    {
    for(col=1;col<=3;col++)
    {
    printf("%d",col);
    }
    printf("n");
    }
    }
#include<stdio.h>
    int main()
    {
    int row,col;
    for(row=1;row<=3;row++)
    {
    for(col=1;col<=3;col++)
    {
    printf("%d",row);
    }
    printf("n");
    }
    }
#include<stdio.h>
    int main()
    {
    int row,col,k=1;
    for(row=1;row<=3;row++)
    {
    for(col=1;col<=3;col++)
    {
    printf("%d",k);
    k++;
    }
    printf("n");
    }
    }
#include<stdio.h>
    int main()
    {
    int row,col;
    for(row=3;row>=1;row--)
    {
    for(col=1;col<=3;col++)
    {
    printf("%d",row);
    }
    printf("n");
    }
    }
#include<stdio.h>
    int main()
    {
    int row,col,k=9;
    for(row=3;row>=1;row--)
    {
    for(col=1;col<=3;col++)
    {
    printf("%d",k);
    k--;
    }
    printf("n");
    }
    }
#include<stdio.h>
    int main()
    {
    int row,col;
    for(row=3;row>=1;row--)
    {
    for(col=3;col>=1;col--)
    {
    printf("%d",col);
    }
    printf("n");
    }
    }
#include<stdio.h>
    int main()
    {
    int row,col;
    for(row=1;row<=3;row++)
    {
    for(col=1;col<=row;col++)
    {
    printf("*");
    }
    printf("n");
    }
    }
#include<stdio.h>
    int main()
    {
    int row,col;
    for(row=3;row>=1;row--)
    {
    for(col=1;col<=row;col++)
    {
    printf("*");
    }
    printf("n");
    }
    }
#include<stdio.h>
    int main()
    {
    int row,col;
    for(row=1;row<=3;row++)
    {
    for(col=1;col<=row;col++)
    {
    printf("%d",col);
    }
    printf("n");
    }
    }
#include<stdio.h>
    int main()
    {
    int row,col;
    for(row=1;row<=3;row++)
    {
    for(col=1;col<=row;col++)
    {
    printf("%d",row);
    }
    printf("n");
    }
    }
#include<stdio.h>
    int main()
    {
    int row,col;
    for(row=3;row>=1;row--)
    {
    for(col=3;col>=row;col--)
    {
    printf("%d",row);
    }
    printf("n");
    }
    }
#include<stdio.h>
    int main()
    {
    int row,col;
    for(row=1;row<=3;row++)
    {
    for(col=3;col>=row;col--)
    {
    printf("%d",row);
    }
    printf("n");
    }
    
    }
#include<stdio.h>
    int main()
    {
    int row,col;
    for(row=3;row>=1;row--)
    {
    for(col=row;col<=3;col++)
    {
    printf("%d",col);
    }
    printf("n");
    }
    }
#include<stdio.h>
    int main()
    {
    int row,col;
    for(row=3;row>=1;row--)
    {
    for(col=3;col>=row;col--)
    {
    printf("%d",col);
    }
    printf("n");
    }
    }
#include<stdio.h>
    int main()
    {
    int row,col,k;
    for(row=1;row<=3;row++)
    {
    for(k=row;k>=2;k--)
    {
    printf(" ");
    }
    for(col=3;col>=row;col--)
    {
    printf("*");
    }
    printf("n");
    }
    }
#include<stdio.h>
    int main()
    {
    int row,col,k;
    for(row=3;row>=1;row--)
    {
    for(k=2;k>=row;k--)
    {
    printf(" ");
    }
    for(col=1;col<=row;col++)
    {
    printf("%d",col);
    }
    printf("n");
    }
    }
#include<stdio.h>
    int main()
    {
    int row,col,k;
    for(row=1;row=2;k--)
    {
    printf(" ");
    }
    for(col=row;col<=3;col++)
    {
    printf("%d",row);
    }
    printf("n");
    }
    }
#include<stdio.h>
    int main()
    {
    int row,col;
    for(row=1;row<=3;row++)
    {
    for(col=1;col<=row;col++)
    {
    printf("* ");
    }
    printf("n");
    }
    }
#include<stdio.h>
    int main()
    {
    int i,j,k;
     for(i=1;i=i;k--)
     {
        printf(" ");
     }
      for(j=1;j<=i;j++)
      {
        printf("* ");
      }
      printf("n");
      }
    }
#include<stdio.h>
    int main()
    {
    int row,col;
    //65 is ASCII value of A
    for(row=65;row<=67;row++)
    {
    for(col=65;col<=row;col++)
    {
    printf("%c ",col);
    }
    printf("n");
    }

    }
#include<stdio.h>
    int main()
    {
    int row,col;
    //65 is ASCII value of A
    for(row=65;row=row;col--)
    {
    printf("%c ",col);
    }
    printf("n");
    }
    }
#include<stdio.h>
    int main()
    {
    int i,j,k;
     //65 is ASCII value of A
     for(i=65;i=i;k--)
     {
        printf(" ");
     }
      for(j=65;j<=i;j++)
      {
        printf("%c ",j);
      }
      printf("n");
      }
    }
Assignments of While and Do While Loops (11 programs)
#include<stdio.h>
    int main()
    {
    int i, m,n=0;
    printf("enter nth number:");
    scanf("%d",&n);
    while(m<=n)
    {
    printf("%d ",m);
    m++;
    }
    }
#include<stdio.h>
    int main()
    {
    int i,m;
    printf("enter starting number:");
    scanf("%d",&m);
    while(m>=0)
    {
    printf("%d ",m);
    m--;
    }
    }
#include<stdio.h>
    int main()
    {
    int i,n,cnt=1;
    printf("enter any number:");
    scanf("%d",&n);
    while(cnt<=10)
    {
    printf("n%d*%d=%d",n,cnt,n*cnt);
    cnt++;
    }
    }
#include<stdio.h>
    int main()
    {
    int i,num,x=0,y=1,z=1;
    printf("enter any number:");
    scanf("%d",&num);
    printf("%d %d",x,y);
    do
    {
    z=x+y;
    printf(" %d",z);
    x=y;
    y=z;
    }
    while(z<=(num-x));
    }
#include<stdio.h>
    int main()
    {
    int num=1,m1,m2,m3;
    float avg=0;
    while(num<=5)
    {
    printf("nEnter your marks in maths:");
    scanf("%d",&m1);
     printf("nEnter your marks in english:");
    scanf("%d",&m2);
     printf("nEnter your marks in hindi:");
    scanf("%d",&m3);
    avg=(m1+m2+m3)/3;
    printf("The average marks is:%f",avg);
    printf("n");
    num++;
    }
    }
#include<stdio.h>
    int main()
    {
    int num=0,rev=0;
    printf("enter a number:");
    scanf("%d",&num);
    printf("The reverse of the number is:");
    while(num>=1)
    {
    rev=num%10;
    num=num/10;
    printf("%d",rev);
    }
    }
#include<stdio.h>
    int main()
    {
    int num=0, fac=1;
    printf("enter the number:");
    scanf("%d",&num);
    printf("The factorial of the number is:");
    while(num>=1)
    {
    fac=fac*num;
    printf("%d*",num);
    num--;
    }
    printf("b=%d",fac);
    }
#include<stdio.h>
    int main()
    {
    int i,m,n,res=1,count=1;
    printf("enter the number:");
    scanf("%d",&m);
    printf("Enter the power:");
    scanf("%d",&n);
    while(count<=n)
    {
    res=res*m;
    count++;
    }
    printf("the result is:%d",res);
    }
#include<stdio.h>
    int main()
    {
      int n,r,sum=0,temp;
      printf("Enter the number: ");
      scanf("%d",&n);
      temp=n;
    while(n>0)
    {
      r=n%10;
      sum=(sum*10)+r;
      n=n/10;
    }
    if(temp==sum)
    {
    	printf("palindrome number ");
    }
    else
    {
        printf("not palindrome");
    }
    return 0;
    }
//Code to check whether a number is armstrong number or not
        #include<stdio.h>
    int main()
    {
    	int n,r,sum=0,temp;
    	printf("enter the number=");
    	scanf("%d",&n);
    	temp=n;
    	while(n>0)
    	{
    		r=n%10;
    		sum=sum+(r*r*r);
    		n=n/10;
    	}
    	if(temp==sum)
    		printf("armstrong  number ");
    	else
   			printf("not armstrong number");
    	return 0;
    }//end of main
//Code to check whether a number is prime number or not
	    #include<stdio.h>
	int main()
	{
   		int n,m=0,i,flag=0;

    	printf("Enter number to check prime number or not");
    	scanf("%d",&n);
    	i=2;
    	m=n/2;
    	while( i<=m)
    	{
        	// check for non prime number
        	if(n%i==0)
        	{
            	flag=1;
           	 break;
        	}
        	i++;
    	}
    	if (flag==0)
    	{
        	printf("%d is a prime number.",n);
    	}
    	else
    	{
        	printf("%d is not a prime number.",n);
    	}
		return 0;
    }//end of main
Assignments of Character (9 programs)
//program to accept a character from the user
    #include<stdio.h>
    int main()
    {
    char ch;
    printf("Enter a character :");
    scanf("%c",&ch);
    printf("n The character is %c",ch);
    return 0;
    }
//Program to accept a character in lower case and display it in uppercase.
     #include<stdio.h>
    int main()
    {
    char ch;
    printf("Enter a character :");
    scanf("%c",&ch);
    ch=ch-32;
    printf("n The character is %c",ch);
    return 0;
   }
//program to accept a character from the user and display its ASCII value.
     #include<stdio.h>
    int main()
    {
    char ch;
    printf("Enter a character :");
    scanf("%c",&ch);
    printf("n The ASCII value of %c is %d ",ch,ch);
    return 0;
   }
// program to accept a character in uppercase and display it in lowercase.
       #include<stdio.h>
    int main()
    {
    char ch;
    printf("Enter a character in upper case :");
    scanf("%c",&ch);
    ch=ch+32;
    printf("n The character in lower case is %c",ch);
    return 0;
   }
// program to display the ASCII values of 0 and 9.
        #include<stdio.h>
    int main()
    {
    char ch1,ch2;
    ch1='0';
    ch2='9';
    printf("n The ASCII value of 0 is %d",ch1);
    printf("n The ASCII value of 9 is %d",ch2);
    return 0;
   }
// program to display the ASCII values fron 0 to 9.
        #include<stdio.h>
    int main()
    {
    char ch;
    ch='0';
    int i;
    for(i=0;i<=9;i++)
    {
        printf("n The ASCII of %c is %d",ch,ch);
        ch++;
    }
    return 0;
   }
/*program to display the ASCII values of all characters from A to Z.*/
        #include<stdio.h>
    int main()
    {
    char ch;
    ch='A';
    int i;
    for(i=1;i<=26;i++)
    {
        printf("n The ASCII of %c is %d",ch,ch);
        ch++;
    }
    return 0;
   }
/* program to accept a character using getch(),getche()
and getchar() functions and display the character.*/
        #include<stdio.h>
    int main()
    {
     char ch;
   printf("n Accepting a character using getch() :");
   ch=getch();
   printf("n The character is %c",ch);

   printf("n Accepting a character using getche() :");
   ch=getche();
   printf("n The character is %c",ch);

   printf("n Accepting a character using getchar() :");
   ch=getchar();
   printf("n The character is %c",ch);

    return 0;
   }
/* program to let the user press any key on the keyboard until x
 but count only how many upper case character keys are pressed on the keyboard?*/
        #include<stdio.h>
    int main()
    {
     char ch;
     int keys=0;
     printf("n Press any key including upper case alphabets:");
     while(1)
     {
        ch=getche();
        if((ch>=65)&&(ch<=90))
        {
            keys++;
        }
        if((ch=='x')||(ch=='X'))
        {
            break;
        }
    }//end of while loop
    printf("n The uppercase character keys are pressed (%d) Times",keys);
    getch();
    return 0;
   }
Assignments of Single Dimensional Array (12 programs)
#include<stdio.h>
    int main()
    {
     int arr[5],i;
     printf("Enter array elements ");
     for(i=0;i<=4;i++)
     {
     scanf("%d",&arr[i]);
     }
     for(i=0;i<=4;i++)
     {
     printf("n Element is %d",arr[i]);
     }
     return 0;
     }
#include<stdio.h>
    int main()
    {
     int arr[5],i;
     printf("Enter array elements ");
     for(i=0;i<=4;i++)
     {
     scanf("%d",&arr[i]);
     }
     for(i=4;i>=0;i--)
     {
     printf("n Element is %d",arr[i]);
     }
     return 0;
     }
#include<stdio.h>
    int main()
    {
     int arr[5],arr1[5],i;
      printf("Enter array elements ");
      for(i=0;i<=4;i++)
      {
      scanf("%d",&arr[i]);
      }
      printf("n The copy of array elements is :n");
      for(i=0;i<=4;i++)
      {
      arr1[i]=arr[i];
      printf("n Element is %d",arr1[i]);
      }
     return 0;
     }
#include<stdio.h>
    int main()
    {
      int arr[5],arr1[5],i,j;
      printf("Enter array elements ");
      for(i=0;i=0;i--)
      {
           arr1[j]=arr[i];
      printf("n Element is %d",arr1[j]);
      j++;
      }
     return 0;
     }
#include<stdio.h>
    int main()
    {
      int arr[5],i,sum=0;
      printf("Enter array elements ");
      for(i=0;i<=4;i++)
      {
      scanf("%d",&arr[i]);
      }
      printf("nThe sum of array elements is :n");
      for(i=0;i<=4;i++)
      {
      sum=sum+arr[i];
      printf("%d+",arr[i]);
      }
      printf("b=%d",sum);
      return 0;
     }
#include<stdio.h>
    int main()
    {
      int arr1[5],arr2[5],sum[5],i;
      printf("Enter array elements in first array ");
      for(i=0;i<=4;i++)
      {
      scanf("%d",&arr1[i]);
      }
      printf("Enter array elements in second array ");
      for(i=0;i<=4;i++)
      {
      scanf("%d",&arr2[i]);
      }
      printf("n The sum of array elements is :n");
      for(i=0;i<=4;i++)
      {
      sum[i]=arr1[i]+arr2[i];
      printf(" %d",sum[i]);
      }
      return 0;
     }
#include<stdio.h>
    int main()
    {
      int arr1[5],arr2[5],diff[5],i;
      printf("Enter array elements in first array ");
      for(i=0;i<=4;i++)
      {
      scanf("%d",&arr1[i]);
      }
      printf("Enter array elements in second array ");
      for(i=0;i<=4;i++)
      {
      scanf("%d",&arr2[i]);
      }
      printf("n THE DIFFERENCE OF EACH ELEMENT OF THE TWO ARRAYS IS:n");
      for(i=0;i<=4;i++)
      {
       diff[i]=arr1[i]-arr2[i];
       printf(" %d",diff[i]);
      }
      return 0;
     }
#include<stdio.h>
    int main()
    {
      int arr[5],i,large=0,loc;
      printf("Enter the elements of an array ");
      for(i=0;i<=4;i++)
      {
      scanf("%d",&arr[i]);
      }
      printf("The elements of an array is:n ");
      for(i=0;i<=4;i++)
      {
      printf("nElement is %d",arr[i]);
      if(arr[i]>large)
      {
      large=arr[i];
      loc=i+1;
      }
      }
      printf("n The element is :%d",large);
      printf("n The location is: %d",loc);
      return 0;
     }
#include<stdio.h>
    int main()
    {
      int arr[5],i,small,loc;
      printf("Enter the elements of an array ");
      for(i=0;i<=4;i++)
      {
      scanf("%d",&arr[i]);
      }
      small=arr[0];
      printf("The elements of an array is:n ");
      for(i=0;i<=4;i++)
      {
      printf("nElement is %d",arr[i]);
      if(small>arr[i])
      {
      small=arr[i];
      loc=i+1;
      }
      }
      printf("n The smallest element is :%d",small);
      printf("n The location is: %d",loc);
      return 0;
     }
#include<stdio.h>
    int main()
    {
      int arr[5],i,j,temp;
      printf("Enter the elements of an array ");
      for(i=0;i<=4;i++)
      {
      scanf("%d",&arr[i]);
      }
      
      for(i=0;i<=4;i++)
      {
      for(j=i+1;j<5;j++)
      {
      if(arr[i]>arr[j])
      {
      temp=arr[i];
      arr[i]=arr[j];
      arr[j]=temp;
        }
       }
      }
      printf("nThe sorted array is: n");
     for(i=0;i<=4;i++)
      {
      printf(" %d",arr[i]);
      }
      return 0;
     }
#include<stdio.h>
    int main()
    {
      int arr[5],i,j,temp;
      printf("Enter the elements of an array ");
      for(i=0;i<=4;i++)
      {
      scanf("%d",&arr[i]);
      }

      for(i=0;i<=4;i++)
      {
      for(j=i+1;j<5;j++)
      {
      if(arr[i]<arr[j])
      {
      temp=arr[i];
      arr[i]=arr[j];
      arr[j]=temp;
        }
       }
      }
      printf("nThe sorted array is: n");
     for(i=0;i<=4;i++)
      {
      printf(" %d",arr[i]);
      }
      return 0;
     }
#include<stdio.h>
    int main()
    {
      int arr[5],i,n,flag=0;
      printf("Enter the elements of an array ");
      for(i=0;i<=4;i++)
      {
      scanf("%d",&arr[i]);
      }
       printf("The elements of an array is: n");
      for(i=0;i<=4;i++)
      {
      printf(" %d",arr[i]);
      }
      printf("n Enter any number which you want to search: ");
      scanf("%d",&n);
      for(i=0;i<=4;i++)
      {
      if(arr[i]==n)
      {
      flag=1;
      printf("n Number is found at %d location",i+1);
       }
      }
      if(flag==0)
      {
      printf("Number is not found");
      }
      return 0;
     }
Assignments of Two Dimensional Array (16 programs)
#include<stdio.h>
    int main()
    {
    int arr[3][3],i,j;
    printf("Enter array elements:");
    for(i=0;i<3;i++)
    {
    for(j=0;j<3;j++)
    {
    scanf("%d",&arr[i][j]);
    }}
    printf("The array elements are:");
    printf("n");
    for(i=0;i<3;i++)
    {
    for(j=0;j<3;j++)
    {
    printf("%d",arr[i][j]);
    }
    printf("n");
    }
     return 0;
     }
#include<stdio.h>
    int main()
    {
    int arr[2][2],arr1[2][2],i,j;
    printf("Enter array elements:");
    for(i=0;i<2;i++)
    {
    for(j=0;j<2;j++)
    {
    scanf("%d",&arr[i][j]);
    }}
    printf("n The copy of the matrix is:");
    printf("n");
    for(i=0;i<2;i++)
    {
    for(j=0;j<2;j++)
    {
    arr1[i][j]=arr[i][j];
    printf("%d",arr1[i][j]);
    }
    printf("n");
    }
     return 0;
     }
#include<stdio.h>
     int main()
     {
     int arr[2][2],arr1[2][2],i,j;
     printf("Enter array elements:");
     for(i=0;i<2;i++)
     {
     for(j=0;j<2;j++)
     {
     scanf("%d",&arr[i][j]);
     }}
     printf("n The reverse copy of the matrix is:");
     printf("n");
     for(i=1;i>=0;i--)
     {
     for(j=1;j>=0;j--)
     {
     arr1[i][j]=arr[i][j];
     printf("%d",arr1[i][j]);
     }
     printf("n");
     }
     return 0;
     }
#include<stdio.h>
     int main()
     {
     int arr[2][2],arr1[2][2],i,j;
     printf("Enter array elements:");
     for(i=0;i<2;i++)
     {
     for(j=0;j<2;j++)
     {
     scanf("%d",&arr[i][j]);
     }}
     printf("n The reverse copy of the matrix is:");
     printf("n");
     for(i=1;i>=0;i--)
     {
     for(j=1;j>=0;j--)
     {
     arr1[i][j]=arr[i][j];
     printf("%d",arr1[i][j]);
     }
     printf("n");
     }
     return 0;
     }
#include<stdio.h>
     int main()
     {
     int arr[2][2],i,j;
     printf("Enter the elements of the matrix:");
     for(i=0;i<2;i++)
     {
     for(j=0;j<2;j++)
     {
     scanf("%d",&arr[i][j]);
     }}
     printf("n The reverse of the matrix is:");
     printf("n");
     for(i=1;i>=0;i--)
     {
     for(j=1;j>=0;j--)
     {
     printf("%d",arr[i][j]);
     }
     printf("n");
     }
     return 0;
     }
#include<stdio.h>
     int main()
     {
     int arr[2][2],i,j,sum=0;
     printf("Enter the elements of the matrix:");
     for(i=0;i<2;i++)
     {
     for(j=0;j<2;j++)
     {
     scanf("%d",&arr[i][j]);
     }}
     printf("n The sum of elements is:");
     printf("n");
     for(i=0;i<2;i++)
     {
     for(j=0;j<2;j++)
     {
     sum=sum+arr[i][j];
     printf("%d+",arr[i][j]);
     }}
     printf("b=%d",sum);
     return 0;
     }
#include<stdio.h>
     int main()
     {
     int arr1[3][3],arr2[3][3],arr3[3][3],i,j;
     printf("Enter the elements first matrix:");
     for(i=0;i<3;i++)
     {
     for(j=0;j<3;j++)
     {
     scanf("%d",&arr1[i][j]);
     }}
     printf("n Enter the element of second matrix:");
   
     for(i=0;i<3;i++)
     {
     for(j=0;j<3;j++)
     {
     scanf("%d",&arr2[i][j]);
     }}
     printf("n The sum of two matrices is:");
     printf("n");
     for(i=0;i<3;i++)
     {
     for(j=0;j<3;j++)
     {
     arr3[i][j]=arr1[i][j]+arr2[i][j];
     printf("%d",arr3[i][j]);
     }
     printf("n");
     }
	 return 0;
     }
#include<stdio.h>
    int main()
    {
    int arr1[3][3],arr2[3][3],arr3[3][3],i,j;
    printf("Enter the elements first matrix:");
    for(i=0;i<3;i++)
    {
    for(j=0;j<3;j++)
    {
    scanf("%d",&arr1[i][j]);
    }}
    printf("n Enter the element of second matrix:");
   
    for(i=0;i<3;i++)
    {
    for(j=0;j<3;j++)
    {
    scanf("%d",&arr2[i][j]);
    }}
    printf("n The subtraction of two matrices is:");
    printf("n");
    for(i=0;i<3;i++)
    {
    for(j=0;j<3;j++)
    {
    arr3[i][j]=arr1[i][j]-arr2[i][j];
    printf("%d",arr3[i][j]);
    }
    printf("n");
    }
    return 0;
    }
#include<stdio.h>
    int main()
    {
    int arr1[3][3],arr2[3][3],arr3[3][3],i,j;
    printf("Enter the elements first matrix:");
    for(i=0;i<3;i++)
    {
    for(j=0;j<3;j++)
    {
    scanf("%d",&arr1[i][j]);
    }}
    printf("n Enter the element of second matrix:");
   
    for(i=0;i<3;i++)
    {
    for(j=0;j<3;j++)
    {
    scanf("%d",&arr2[i][j]);
    }}
    printf("n The subtraction of two matrices is:");
    printf("n");
    for(i=0;i<3;i++)
    {
    for(j=0;j<3;j++)
    {
    arr3[i][j]=arr1[i][j]/arr2[i][j];
    printf("%d",arr3[i][j]);
    }
    printf("n");
    }
    return 0;
    }
#include<stdio.h>
    int main()
    {
    int arr[2][2],arr1[2][2],arr2[2][2],i,j,k;
    printf("Enter the elements of first matrix:");
    for(i=0;i<2;i++)
    {
    for(j=0;j<2;j++)
    {
    scanf("%d",&arr[i][j]);
    }}
    for(i=0;i<2;i++)
    {
    for(j=0;j<2;j++)
    {
    printf("%d",arr[i][j]);
    }
    printf("n");
    }
    printf("n Enter the elements of the second matrix:");
    for(i=0;i<2;i++)
    {
    for(j=0;j<2;j++)
    {
    scanf("%d",&arr1[i][j]);
    }}
    for(i=0;i<2;i++)
    {
    for(j=0;j<2;j++)
    {
     printf("%d",arr1[i][j]);
    }
    printf("n");
    }
    printf("nThe multiplication is");
    printf("n");
    for(i=0;i<2;i++)
    {
    for(j=0;j<2;j++)
    {
    arr2[i][j]=0;
    for(k=0;k<2;k++)
    {
    arr2[i][j]=arr2[i][j]+arr[i][k]*arr1[k][j];
    }
    printf("%d",arr2[i][j]);
    }
    printf("n");
    }
	return 0;
    }
#include<stdio.h>
    int main()
    {
    int arr[2][2],i,j,large=0,k,l;
    printf("Enter the element:");
    for(i=0;i<2;i++)
    {
    for(j=0;j<2;j++)
    {
    scanf("%d",&arr[i][j]);
    }}
    printf("n The elements of the matrix are: ");
    printf("n");
    for(i=0;i<2;i++)
    {
    for(j=0;j<2;j++)
    {
    printf("%d",arr[i][j]);
    }
    printf("n");
    }
    for(i=0;i<2;i++)
    {
    for(j=0;j<2;j++)
    {
    if(arr[i][j]>large)
    {
    large=arr[i][j];
    k=i+1;
    l=j+1;
    }}}
    printf("The greatest element is %d and present in %d row and in %d column",large,k,l);
	return 0;
    }
#include<stdio.h>
    int main()
    {
    int arr[2][2],i,j,small,k,l;
    printf("Enter the element:");
    for(i=0;i<2;i++)
    {
    for(j=0;j<2;j++)
    {
    scanf("%d",&arr[i][j]);
    }}
    printf("n The elements of the matrix are: ");
    printf("n");
    for(i=0;i<2;i++)
    {
    for(j=0;j<2;j++)
    {
    printf("%d",arr[i][j]);
    }
    printf("n");
    }
    small=arr[0][0];
    for(i=0;i<2;i++)
    {
    for(j=0;j<2;j++)
    {
    if(arr[i][j]<small)
    {
    small=arr[i][j];
    k=i+1;
    l=j+1;
    }}}
   printf("The smallest element is %d and present in %d row and in %d column",small,k,l);
	return 0;
    }
#include<stdio.h>
    int main()
    {
    int arr[2][2],i,j,k,l;
    int small;
    printf("Enter the element:");
    for(i=0;i<2;i++)
    {
    for(j=0;j<2;j++)
    {
    scanf("%d",&arr[i][j]);
    }}
    printf("n The elements of the matrix are: ");
    printf("n");
    for(i=0;i<2;i++)
    {
    for(j=0;j<2;j++)
    {
    printf("%d",arr[i][j]);
    }
    printf("n");
    }
    printf("n The transpose of the matrix is:"); 
    printf("n");
    for(i=0;i<2;i++)
    {
    for(j=0;j<2;j++)
    {
    printf("%d",arr[j][i]);
    }
    printf("n");
    }    
	return 0;
    }
#include<stdio.h>
    int main()
    {
    int arr[2][2],i,j,k,l;
    int small;
    printf("Enter the element:");
    for(i=0;i<2;i++)
    {
    for(j=0;j<2;j++)
    {
    scanf("%d",&arr[i][j]);
    }}
    printf("n The elements of the matrix are: ");
    printf("n");
    for(i=0;i<2;i++)
    {
    for(j=0;j<2;j++)
    {
    printf("%d",arr[i][j]);
    }
    printf("n");
    }
    printf("n The transpose of the matrix is:"); 
    printf("n");
    for(i=0;i<2;i++)
    {
    for(j=0;j<2;j++)
    {
    printf("%d",arr[j][i]);
    }
    printf("n");
    }    
	return 0;
    }
#include<stdio.h>
     int main()
     {
     int arr[3][3],i,j,n,flag=1;
     printf("Enter the array elements: n");
     for(i=0;i<3;i++)
     {
     for(j=0;j<3;j++)
     {
        scanf("%d",&arr[i][j]);
     }}
     printf("n The elements of array is: ");
     printf("n");
     for(i=0;i<3;i++)
     {
     for(j=0;j<3;j++)
     {
        printf("%d",arr[i][j]);
     }
        printf("n");
     }
     printf("n Enter any no.which you want to search: ");
     scanf("%d",&n);
     for(i=0;i<3;i++)
     {
     for(j=0;j<3;j++)
     {
     if(arr[i][j]==n)
     {
        flag=0;
        printf("Number is found at %d row and %d column",i+1,j+1);
     }}}
     if(flag==1)
     {
        printf("number is not found");
     }
	 return 0;
     }
#include<stdio.h>
     int main()
     {
     int arr[3][3],i,j,n,flag=1;
     printf("Enter the array elements: n");
     for(i=0;i<3;i++)
     {
     for(j=0;j<3;j++)
     {
        scanf("%d",&arr[i][j]);
     }}
     printf("n The elements of array is: ");
     printf("n");
     for(i=0;i<3;i++)
     {
     for(j=0;j<3;j++)
     {
        printf("%d",arr[i][j]);
     }
        printf("n");
     }
     printf("n Enter any no.which you want to search: ");
     scanf("%d",&n);
     for(i=0;i<3;i++)
     {
     for(j=0;j<3;j++)
     {
     if(arr[i][j]==n)
     {
        flag=0;
        printf("Number is found at %d row and %d column",i+1,j+1);
     }}}
     if(flag==1)
     {
        printf("number is not found");
     }
	 return 0;
     }
Assignments of Character Array (10 programs)
#include<stdio.h>
	 int main()
	 {
        char name[30];
    	printf("Enter a string ");
    	//scanf("%s",name);
    	//scanf()function cannot read spaces
    	gets(name);//read the string with spaces
    	printf("You entered: %s",name);
	 }
#include<stdio.h>
         int main()
	{
          char name[20];
          int i,j;
    	  printf("Enter a string");
    	  gets(name);
    	  for(i=0;name[i]!='';i++);
    	  //Loop with i will count the length of a string
          //So, i will store the length of a string
    	  for(j=i-1;j>  =0;j--)
    	  {
        	 printf("%c",name[j]);
          }
          }
#include<stdio.h>
     int main()
     {
       char name[20];
       int i;
       printf("Enter a string ");
       gets(name);
       for(i=0;name[i]!='';i++);
       printf("The length of the string is: %d",i);
       return 0;
     }
#include<stdio.h>
     int main()
     {
       char name[20];
       int i;
       printf("Enter a string in uppercase: ");
       gets(name);
       printf("nThe string in lowercase: ");
       for(i=0;name[i]!='';i++)
       {
         if((name[i]>='A')&&(name[i]<='Z'))
         {
            name[i]=name[i]+32;
         }
       }
       puts(name);
       return 0;
     }
#include<stdio.h>
     int main()
     {
       char name[20];
       int i;
       printf("Enter a string in lowercase: ");
       gets(name);
       printf("nThe string in uppercase: ");
       for(i=0;name[i]!='';i++)
       {
         if((name[i]>='a')&&(name[i]<='z'))
         {
            name[i]=name[i]-32;
         }
       }
       puts(name);
       return 0;
     }
#include<stdio.h>
     int main()
     {
        char name[20];
        int i,cnt=0;
    	printf("Enter a string in lowercase:");
    	gets(name);
    	printf("nThe vowels are: ");
    	for(i=0;name[i]!='';i++)
    	{
	  if((name[i]=='a')||(name[i]=='e')||(name[i]=='i')||(name[i]=='o')||(name[i]=='u')||(name[i]=='A')||(name[i]=='E')||(name[i]=='I')||(name[i]=='O')||(name[i]=='U'))
           {
    		printf("%c",name[i]);
    		cnt++;
    	   }
         }
    	 printf("n The number of vowel is:%d",cnt);
       return 0;
     }
#include<stdio.h>
     int main()
     {
       char name[20];
       int i,cnt=0;
       printf("Enter a string:");
       gets(name);
       printf("nThe consonants are: ");
       for(i=0;name[i]!='';i++)
       {
         if((name[i]!='a')&&(name[i]!='e')&&(name[i]!='i')&&(name[i]!='o')&&(name[i]!='u')&&(name[i]!='A')&&(name[i]!='E')&&(name[i]!='I')&&(name[i]!='O')&&(name[i]!='U'))
          {
            printf("%c",name[i]);
            cnt++;
          }
        }
        printf("n The number of consonants  are:%d",cnt);
        return 0;
      }
#include<stdio.h>
     int main()
     {
        char name[20],name1[20];
    	int i,cnt=0;
    	printf("Enter a string ");
    	gets(name);
    	printf("nThe copy of string: ");
    	for(i=0;name[i]!='';i++)
   		{
   			name1[i]=name[i];
    		printf("%c",name[i]);
    	}
        return 0;
      }
#include<stdio.h>
     int main()
     {
        char name[50];
    	int i,wrd=0;
    	printf("Enter a sentence: ");
    	gets(name);
    	printf("The number of words are: ");
    	for(i=0;name[i]!='';i++)
    	{
    		if(name[i]==' ')
    		wrd++;
   		}
        printf("%d",wrd+1);
        return 0;
     }
#include<stdio.h>
     int main()
     {
        char str1[20],str2[20],str3[50];
    	int i,j;
      printf("Enter first string:");
      gets(str1);
   	printf("Enter second  string:");
   	 gets(str2);
   	 for(i=0;str1[i]!='';i++)
	    {
    		str3[i]=str1[i];
   	}
   	for(j=0;str2[j]!='';j++)
    	{
    		str3[i]=str2[j];
    		i++;
    	}
    	str3[i]='';
    	printf("n%s",str3);
        return 0;
     }
Assignments of Pointer (7 programs)
#include<stdio.h>
 int main()
 {
   int num1,num2,res;
   int *aptr,*bptr,*cptr;
   printf("Enter first number ");
   scanf("%d",&num1);
   printf("Enter second number ");
   scanf("%d",&num2);
   aptr=&num1;
   bptr=&num2;
   cptr=&res;
   *cptr=(*aptr)+(*bptr);
   printf("n sum is %d",*cptr);
 }
#include<stdio.h>
 int main()
 {
        int num1,num2,temp;
   int *aptr,*bptr;
   printf("Enter first number ");
   scanf("%d",&num1);
   printf("Enter second number ");
   scanf("%d",&num2);
   printf("n Values before swapping is : num1=%d, num2=%d",num1,num2);
   aptr=&num1;
   bptr=&num2;
  temp=*aptr;
  *aptr=*bptr;
  *bptr=temp;
   printf("n Values after swapping is : num1=%d, num2=%d",*aptr,*bptr);
 }
#include<stdio.h>
 int main()
 {
       int arr[5],i,*ptr;
   for(i=0;i<5;i++)
   {
      printf("Enter array elements ");
      scanf("%d",&arr[i]);
   }
   printf("n The reverse of elements are: n");
   for(i=4;i>=0;i--)
   {
      ptr=&arr[i];
      printf(" %d",*ptr);
   }
   return 0;
   }
#include<stdio.h>
 int main()
 {
      int arr[5],i,*ptr,sum=0;
   for(i=0;i<5;i++)
   {
      printf("Enter array elements ");
      scanf("%d",&arr[i]);
   }
   printf("n The sum of array elements is: ");
   for(i=0;i<=4;i++)
   {
      ptr=&arr[i];
      sum=sum+(*ptr);
   }
   printf(" %d",sum);
   return 0;
   }
#include<stdio.h>
 int main()
 {
     int arr1[5],arr2[5],sum[5],i;
     int *ptr1,*ptr2,*res;
      printf("Enter array elements in first array ");
      for(i=0;i<=4;i++)
      {
        scanf("%d",&arr1[i]);
      }
      printf("Enter array elements in second array ");
      for(i=0;i<=4;i++)
      {
        scanf("%d",&arr2[i]);
      }
      printf("n The sum of array elements is :n");
      for(i=0;i<=4;i++)
      {
        ptr1=&arr1[i];
        ptr2=&arr2[i];
        res=&sum[i];
        *res=*ptr1+(*ptr2);
        printf(" %d",*res);
      }
   return 0;
   }
#include<stdio.h>
 int main()
 {
     int i,num,*ptr;
     printf("Enter the number for the limit of series: ");
     scanf("%d",&num);
     for(i=0;i<=num;i++)
     {
       ptr=&i;
       printf(" %d",*ptr);
     }
    return 0;
  }
#include<stdio.h>
 int main()
 {
     int arr[3][3],i,j,sum=0;
	 int *ptr;
	 printf("Enter array elements: n");
	 for(i=0;i<3;i++)
	 {
 	 	for(j=0;j<3;j++)
 	 	{
 		   scanf("%d",&arr[i][j]);
 	 	}
	 }
	 for(i=0;i<3;i++)
	 {
 	   for(j=0;j<3;j++)
  	   {
 		  ptr=&arr[i][j];
		  sum=sum+(*ptr);
 	   }
     }
   	 printf("nThe sum of array elements is: %d",sum);
    return 0;
  }
Assignments of Function (14 programs)
#include<stdio.h>
 void sum() //definition or body of sum()
 {
      int num1,num2,num3,num4,res;
      printf("Enter first number: ");
      scanf("%d",&num1);
      printf("Enter second number: ");
      scanf("%d",&num2);
      printf("Enter third number: ");
      scanf("%d",&num3);
      printf("Enter fourth number: ");
      scanf("%d",&num4);
      res=num1+num2+num3+num4;
      printf("n The sum of all numbers is %d",res);
  }
  int main()
  {
   printf("Calling sum function: n");
      //function with no arguments and no return type
      sum();//calling sum() function
    return 0;
 }
#include<stdio.h>
 int num1,num2,res;//global declaration
    void input()
    {
      printf("Enter first number: ");
      scanf("%d",&num1);
      printf("Enter second number: ");
      scanf("%d",&num2);
    }//end of input function
    void sum()
    {
      res=num1+num2;
      printf("n The sum of numbers is %d",res);
    }//end of sum function
    void subtract()
    {
      if(num1>num2)
      {
       res=num1-num2;
      }
      else
      {
      res=num2-num1;
      }
      printf("n The subtraction of numbers is %d",res);
    }//end of subtract function
    void multiply()
    {
      res=num1*num2;
      printf("n The multiplication of numbers is %d",res);
    }//end of multiply function
    void division()
    {
      res=num1/num2;
      printf("n The division of numbers is %d",res);
    }//end of division function

    int main()
    {
         char ch;
         printf("nPress + for addition n");
         printf("nPress - for subtraction n");
         printf("nPress * for multiplication n");
         printf("nPress / for division n");
         scanf("%c",&ch);
         switch(ch)
         {
         case '+':
         input();
         sum(); //calling sum function
         break;
         case '-':
         input();
         subtract();//calling subtract() function
         break;
         case '*':
         input();
         multiply();//calling multiply() function
         break;
         case '/':
         input();
         division();//calling division() function
         break;
         default:
         printf("Invalid choice");
         }
        return 0;
    }//end of main
#include<stdio.h>
   void odd(int n)
   {
        int i;
        printf("n The odd series is : ");
        for(i=1;i<=n;i+=2)
        {
            printf("%d ",i);
        }//end of loop
    }//end of function
    int main()
    {
        int num;
        printf("Enter the nth number: ");
        scanf("%d",&num);
        odd(num);
        return 0;
    }//end of main
#include<stdio.h>
   void even(int n)
   {
        int i;
        printf("n The even series is : ");
        for(i=0;i<=n;i+=2)
        {
            printf("%d ",i);
        }//end of loop
    }//end of function
    int main()
    {
        int num;
        printf("Enter the nth number: ");
        scanf("%d",&num);
        even(num);
        return 0;
    }//end of main
#include<stdio.h>
 void display(char ch1,int n)
 {
    int i;
    for(i=1;i<=n;i++)
    {
        printf(" %c",ch1);
    }
 }
 int main()
 {
    char ch;
    int num;
    printf("Enter a character: ");
    scanf("%c",&ch);
    printf("Enter the limit: ");
    scanf("%d",&num);
    display(ch,num);
    return 0;
 }//end of main
#include<stdio.h>
 void series(int a,int b)
{
    int i;
    printf("n The series is : ");
    for(i=a;i<=b;i++)
    {
        printf("%d ",i);
    }
}

int main()
{
    int m,n;
    printf("Enter starting value: ");
    scanf("%d",&m);
    printf("Enter ending value: ");
    scanf("%d",&n);
    series(m,n);
    return 0;
}//end of main
#include<stdio.h>
 void is_pos_neg(int n)
 {
    if(n>0)
        printf("Number is positive");
    else if(n<0)
        printf("Number is negative");
    else
        printf("You entered zero");
 }

 int main()
 {
    int num;
    printf("Enter any number:");
    scanf("%d",&num);
    is_pos_neg(num);
    return 0;
 }//end of main
#include<stdio.h>
 void fibonacci(int n)
 {
    int i,j=0,k=1,m;
    printf("%d %d",j,k);
    for(i=1;i<=n;i++)
    {
        m=j+k;
        j=k;
        k=m;
        if(m<=n)
            printf(" %d",m);
    }//end of loop
 }//end of function
 int main()
 {
    int num;
    printf("Enter ending value: ");
    scanf("%d",&num);
    fibonacci(num);
    return 0;
 }//end of main
#include<stdio.h>
 void to_upper(char a)
 {
    int i;
    printf("The alphabet in uppercase is: ");
    if((a>='a')&&(a<='z'))
    {
         a=a-32;
    }//end of if
    printf("%c",a);
 }//end of function
 int main()
 {
    char ch;
    printf("Enter an alphabet in lowercase: ");
    scanf("%c",&ch);
    to_upper(ch);
    return 0;
 }//end of main
#include<stdio.h>
 void to_lower(char a)
 {
    int i;
    printf("The alphabet in lowercase is: ");
    if((a>='A')&&(a<='Z'))
    {
         a=a+32;
    }//end of if
    printf("%c",a);
 }//end of function
 int main()
 {
    char ch;
    printf("Enter an alphabet in Uppercase: ");
    scanf("%c",&ch);
    to_lower(ch);
    return 0;
 }//end of main
#include<stdio.h>
 void series(int n)
 {
    int i,j,sum=0;
    printf("Series: ");
    for(i=1;i<=n;i++)
    {
        j=i*i;
        sum=sum+j;
        printf("%d+",j);
    }
    printf("b=%d",sum);
 }//end of function

 int main()
 {
    int num;
    printf("Enter a number: ");
    scanf("%d",&num);
    series(num);
    return 0;
 }//end of main
#include<stdio.h>
 int factorial(int n)
 {
    int i,fac=1;
    printf("The factorial is: ");
    for(i=n;i>=1;i--)
    {
        fac=fac*i;
        printf("%d*",i);
    }
    return(fac);
 }//end of function

 int main()
 {
    int num,ans;
    printf("Enter a number: ");
    scanf("%d",&num);
    ans=factorial(num);
    printf("b=%d",ans);
    return 0;
 }//end of main
#include<stdio.h>
 void swap(int a,int b)
 {
    int c;
    printf("nThe value of numbers before swapping is: ");
    printf("n First: %d",a);
    printf("n Second : %d",b);
    c=a;
    a=b;
    b=c;
    printf("nThe value of numbers after swapping is:");
    printf("n First: %d",a);
    printf("n Second: %d",b);
 }//end of function

 int main()
 {
    int x,y;
    printf("Enter First number: ");
    scanf("%d",&x);
    printf("Enter Second number: ");
    scanf("%d",&y);
    swap(x,y);
    return 0;
 }//end of main
#include<stdio.h>
 int fact(int value)
 {
    int ans;
    if((value==0)||(value==1))
        return(1);
    else
        ans=value*fact(value-1);
    return(ans);
 }//end of function

 int main()
 {
   int i,n,fac;
    printf("Enter any number: ");
    scanf("%d",&n);
    fac=fact(n);
    printf("The factorial is:  ");
    for(i=n;i>=1;i--)
    {
        printf("%d*",i);
    }
    printf("b=%d",fac);
    return 0;
 }//end of main
Assignments of Structure (8 programs)
#include<stdio.h>
  struct Student
{
    char name[10];
    int rollno;
    float fee;
};
int main()
{
   struct Student st;
   printf("Enter name: ");
   gets(st.name);
   printf("Enter rollno: ");
   scanf("%d",&st.rollno);
   printf("Enter fee: ");
   scanf("%f",&st.fee);
   printf("------------------");
   printf("nName is %s",st.name);
   printf("nRollno is %d",st.rollno);
   printf("nFee is %f",st.fee);
    return 0;
 }//end of main
#include<stdio.h>
  struct Student
{
    int rollno;
    int marks[5];
};
int main()
{
   struct Student st;
   int i;
   printf("Enter rollno: ");
   scanf("%d",&st.rollno);
   for(i=0;i<5;i++)
   {
   printf("Enter marks in %d subject: ",(i+1));
   scanf("%d",&st.marks[i]);
   }
   printf("------------------");
   printf("nRollno is %d",st.rollno);
   for(i=0;i<5;i++)
   {
   printf("nMarks in %d subject are: %d ",(i+1),st.marks[i]);
   }
    return 0;
 }//end of main
#include<stdio.h>
  struct Student
{
    char name[20];
    int marks[9];
};
int main()
{
   struct Student st;
   int i,sum=0;
   float avg;
   printf("Enter name: ");
   gets(st.name);
   for(i=0;i<9;i++)
   {
        printf("Enter marks in %d subject: ",(i+1));
        scanf("%d",&st.marks[i]);
        sum=sum+st.marks[i];
   }
    avg=sum/9;
    printf("nName is %s",st.name);
    printf("nAverage is: %f",avg);
   return 0;
 }//end of main
#include<stdio.h>
  struct employee
{
  char name[10];
  int salary;
  int id;
};

int main()
{
int i;
struct employee emp[5];
for(i=0;i<5;i++)
{
 printf("Enter name ");
 //gets(emp[i].name);
 scanf("%s",emp[i].name);
 printf("Enter salary ");
 scanf("%d",&emp[i].salary);
 printf("Enter id ");
 scanf("%d",&emp[i].id);
}
for(i=0;i<5;i++)
{
  printf("n Name is %s",emp[i].name);
  printf("n Salary is %d",emp[i].salary);
  printf("n Id is %d",emp[i].id);
  printf("n--------------------------");
 }
   return 0;
 }//end of main
#include<stdio.h>
 struct student
{
  char name[10];
  int subject[5];
};
int main()
{
  struct student st[5];
  int sum,avg,i,j;
  for(i=0;i<5;i++)
  {
  sum=0;
  printf("Enter name ");
  scanf("%s",st[i].name);
  printf("nEnter the marks of %d studentnn",i+1);
  for(j=0;j<5;j++)
  {
   printf("Enter the marks of %d subject ",j+1);
   scanf("%d",&st[i].subject[j]);
   sum=sum+st[i].subject[j];

  }
   avg=sum/5;
  printf("n Average marks of %d student is %dnn",i+1,avg);
  printf("n");
  }
   return 0;
 }//end of main
#include<stdio.h>
 struct student
{
  char name[10];
  int subject[5];
};
int main()
{
  struct student st,*ptr;
  ptr=&st;
  int sum=0,avg,i;
  printf("Enter name: ");
  gets(ptr->name);
  for(i=0;i<5;i++)
  {
   printf("Enter the marks of %d subject: ",i+1);
   scanf("%d",&ptr->subject[i]);
   sum=sum+ptr->subject[i];
  }
  avg=sum/5;
  printf("n Average of five subjects is %d",avg);
   return 0;
 }//end of main
#include<stdio.h>
 struct student
{
  char name[10];
  int subject[5];
};
int main()
{
  struct student st[5],*ptr;

  int sum,avg,i,j;
  for(i=0;i<5;i++)
  {
      ptr=&st[i];
      sum=0;
      printf("Enter name: ");
      scanf("%s",&ptr->name);
      printf("nEnter the marks of %d studentn",i+1);
      for(j=0;j<5;j++)
      {
        printf("nEnter the marks of %d subject: ",j+1);
        scanf("%d",&ptr->subject[j]);
        sum=sum+ptr->subject[j];
      }
    avg=sum/5;
    printf("n Average marks of %d student is %d",i+1,avg);
    printf("nn-----------------------------------n");
  }
   return 0;
 }//end of main
#include<stdio.h>
 struct student
{
    int rollno;
    char name[10];
    int fee;
}st;
void display(struct student *st)
{
    printf("n Name is %s",st->name);
    printf("n Rollno is %d",st->rollno);
    printf("n Fee is %d",st->fee);
}

int main()
{
    printf("Enter name : ");
    scanf("%s",&st.name);
    printf("Enter rollno : ");
    scanf("%d",&st.rollno);
    printf("Enter fee : ");
    scanf("%d",&st.fee);
    display(&st);
    return 0;
 }//end of main
Assignments of File Handling (13 programs)
#include<stdio.h>
 int main()
{
    FILE *fptr;
    fptr=fopen("first.txt","w");
    fprintf(fptr,"Welcome to Compuhelp");
    printf("Data Saved");
    fclose(fptr);
    return 0;
 }//end of main
#include<stdio.h>
 int main()
{
    FILE *fptr;
    int num;
    fptr=fopen("first.txt","w");
    printf("Enter a number: ");
    scanf("%d",&num);
    fprintf(fptr,"%d",num);
    printf("Data saved");
    fclose(fptr);
    return 0;
 }//end of main
#include<stdio.h>
 int main()
{
    FILE *fptr;
    int num;
    fptr=fopen("first.txt","w");
    printf("Enter a number ");
    scanf("%d",&num);
    fprintf(fptr,"%d",num);
    printf("Data saved");
    fclose(fptr);
    fptr=fopen("first.txt","r");
    fscanf(fptr,"%d",&num);
    printf("nnValue of num= %d",num);
    fclose(fptr);
    return 0;
 }//end of main
#include<stdio.h>
 #include<stdlib.h>
 int main()
 {
    
    FILE *fptr;
    int num;
    fptr=fopen("first.txt","w");
    printf("Enter a number ");
    scanf("%d",&num);
    fprintf(fptr,"%d",num);
    printf("Data saved");
    fclose(fptr);
    fptr=fopen("first.txt","r");
    fscanf(fptr,"%d",&num);
    printf("n Now writing into another file");
    fptr=fopen("second.txt","w");
    fprintf(fptr,"%d",num);
    fclose(fptr);
    return 0;
 }//end of main
#include<stdio.h>
 #include<stdlib.h>
 int main()
 {
    FILE *fptr;
    char ch;
    fptr=fopen("string.txt","w");
    if(fptr==NULL)
    {
        printf("Error in opening file ");
        exit(1);
    }
    fprintf(fptr,"welcome you in COMPUHELP");
    printf("Data savedn");
    fclose(fptr);
    fptr=fopen("string.txt","r");
    while(ch!=EOF)
    {
        ch=fgetc(fptr);
        printf("%c",ch);
    }
    fclose(fptr);
    return 0;
 }//end of main
#include<stdio.h>
 #include<stdlib.h>
 int main()
 {
    FILE *fptr;
    char ch;
    int count=0;
    fptr=fopen("string.txt","w");
    if(fptr==NULL)
    {
        printf("Error in opening file ");
        exit(1);
    }
    fprintf(fptr,"welcome you in COMPUHELP");
    printf("Data savedn");
    fclose(fptr);
    fptr=fopen("string.txt","r");
    while(ch!=EOF)
    {
        ch=fgetc(fptr);
        printf("%c",ch);
        count++;
    }
    printf("n The number of characters are: %d",count);
    fclose(fptr);
    return 0;
 }//end of main
#include<stdio.h>
 #include<stdlib.h>
 int main()
 {
    FILE *fptr;
    char ch;
    int count=0;
    fptr=fopen("string.txt","w");
    if(fptr==NULL)
    {
        printf("Error in opening file ");
        exit(1);
    }
    fprintf(fptr,"welcome you in COMPUHELP");
    printf("Data savedn");
    fclose(fptr);
    fptr=fopen("string.txt","r");
    while(ch!=EOF)
    {
        ch=fgetc(fptr);
        if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u'||ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U')
        {
            count++;
            printf("%c ",ch);
        }
    }
    printf("n The number of vowels are: %d",count);
    fclose(fptr);
    return 0;
 }//end of main
#include<stdio.h>
 #include<stdlib.h>
 int main()
 {
    FILE *fptr;
    char ch;
    int upr=0,lwr=0;
    fptr=fopen("string.txt","w");
    if(fptr==NULL)
    {
        printf("Error in opening file ");
        exit(1);
    }
    fprintf(fptr,"welcome you in COMPUHELP");
    printf("Data savedn");
    fclose(fptr);
    fptr=fopen("string.txt","r");
    while(ch!=EOF)
    {
        ch=fgetc(fptr);
        if(ch>=65 && ch<=90)
        {
            upr++;
            //printf("%c ",ch);
        }
        if(ch>=97 && ch<=122)
        {
            lwr++;
            //printf("%c ",ch);
        }
    }
    printf("n The number of Uppers are: %d",upr);
    printf("n The number of Lowers are: %d",lwr);
    fclose(fptr);
    return 0;
 }//end of main
#include<stdio.h>
 #include<stdlib.h>
 int main()
 {
    FILE *fptr;
    ch;
    int space=0,word=0;
    fptr=fopen("string.txt","w");
    if(fptr==NULL)
    {
        printf("Error in opening file ");
        exit(1);
    }
    fprintf(fptr,"welcome you in COMPUHELP");
    printf("Data savedn");
    fclose(fptr);
    fptr=fopen("string.txt","r");
    while(ch!=EOF)
    {
        ch=fgetc(fptr);
        if(ch==' ')
        {
            space++;
            word++;
        }
    }
    printf("n The number of Spaces are: %d",space);
    printf("n The number of Words are: %d",(word+1));
    fclose(fptr);

    return 0;
 }//end of main
#include<stdio.h>
 #include<stdlib.h>
 int main()
 {
    FILE *fptr;
    char ch;
    int line=0;
    fptr=fopen("string.txt","w");
    if(fptr==NULL)
    {
        printf("Error in opening file ");
        exit(1);
    }
    fprintf(fptr,"welcome you in COMPUHELPn Thanks to Join CompuhelpnThanksnBye");
    printf("Data savedn");
    fclose(fptr);
    fptr=fopen("string.txt","r");
    while(ch!=EOF)
    {
        ch=fgetc(fptr);
        if(ch=='n')
        {
            line++;
        }
    }
    printf("n The number of Lines are: %d",(line+1));
    fclose(fptr);
    return 0;
 }//end of main
#include<stdio.h>
 int main()
 {
    FILE *fptr;
    int num[10];
    int i,even=0,odd=0;

    fptr=fopen("first.txt","w");
    printf("Enter number's ");
    for(i=0;i<10;i++)
    {
        scanf("%d",&num[i]);
    }
    for(i=0;i<10;i++)
    {
        fprintf(fptr,"%d ",num[i]);
    }
    printf("Data saved");
    fclose(fptr);
    fptr=fopen("first.txt","r");
    for(i=0;i<10;i++)
    {
        fscanf(fptr,"%d",&num[i]);
        if(num[i]%2==0)
        {
            even++;
        }
        else
        {
            odd++;
        }
    }
    printf("n Number of even numbers are %d",even);
    printf("n Number of odd numbers are %d",odd);
    fclose(fptr);
    return 0;
 }//end of main
#include<stdio.h>
 #include<stdlib.h>
 int main()
 {
    FILE *fptr;
    char ch,ch1,name[50];
    int line=0;
    fptr=fopen("string.txt","w");
    if(fptr==NULL)
    {
    printf("Error in opening file ");
    exit(1);
    }
    printf("Enter a string ");
    gets(name);
    fprintf(fptr,"%s",name);
    printf("Data savedn");
    fclose(fptr);
    fptr=fopen("string.txt","r");
    printf("Enter another character ");
    scanf("%c",&ch1);
    while(ch!=EOF)
    {
        ch=fgetc(fptr);
        if(ch==ch1)
        {
            ch=ch-32;
            printf("%c",ch);
        }
        else
        {
            printf("%c",ch);
        }
    }
    fclose(fptr);
    return 0;
 }//end of main
#include<stdio.h>
 #include<stdlib.h>
 struct student
{
    char name[20];
    int rollno;
    float fee;
};//end of structure
int main()
{
    struct student st;
    FILE *fptr;
    char ch,ch1,name[50];
    int line=0;
    fptr=fopen("data.txt","w");
    if(fptr==NULL)
    {
        printf("Error in opening file ");
        exit(1);
    }
    printf("Enter a name ");
    gets(st.name);
    printf("Enter rollno ");
    scanf("%d",&st.rollno);
    printf("Enter fee ");
    scanf("%f",&st.fee);
    fprintf(fptr,"%s",st.name);
    fprintf(fptr,"n%d",st.rollno);
    fprintf(fptr,"n%f",st.fee);
    printf("nData saved");
    fclose(fptr);
    return 0;
 }//end of main

Unsolved C Assignments (PDF)

Practice sheets for self-assessment in lab. Contact COMPUHELP faculty for the latest PDF.

C Programming Training

Logic building in C at Sector 46-C.

Apply Now View C Course

WhatsApp