C-HelpDesk

if statement and if..else statement

Compiler is a program which translate English like language into binary or machine language and vice-versa.

..........

  1.     #include<stdio.h>
         
        void main()
        {
        int marks;
        clrscr();
        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");
        }
         
        }

  2.     #include<stdio.h>
         
        void main()
        {
        int num;
        clrscr();
        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");
        }
         
        }

  3.     #include<stdio.h>
         
        void main()
        {
        int num;
        clrscr();
        printf("Enter any number");
        scanf("%d",&num);
        if(num%2==0)
        {
        printf("Number is even");
        }
        else 
        {
        printf("Number is odd");
        }
         
        }

  4.     #include<stdio.h>
         
        void main()
        {
        char ch;
        clrscr();
        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 consonent");
        }
         
        }

  5.     #include<stdio.h>
         
        void main()
        {
        char ch;
        clrscr();
        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 consonent");
        }
         
        }

  6.     #include<stdio.h>
         
        void 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");
        }
        if(num==3)
        {
        printf("Day is Wednesday");
        }
        if(num==4)
        {
        printf("Day is Thursday");
        }
        if(num==5)
        {
        printf("Day is Friday");
        }
        if(num==6)
        {
        printf("Day is Saturday");
        }
        if(num==7)
        {
        printf("Day is Sunday");
        }
        }

  7.     #include<stdio.h>
         
        void 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");
        }
        }

  8.     #include<stdio.h>
         
        void 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 Feburary");
        }
       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");
        }
        }

  9.     #include<stdio.h>
         
        #include<stdlib.h> 
        void 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>
     
    void 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");
    }
    

Assignments of Switch Statement

  1.     #include<stdio.h>
         
        void main()
        {
        int num;
        printf("enter any number between 0 to 9:");
        scanf("%d",&num);
        switch(num)
        {
        case 0:
        print("You entered ZERO");
        break;
        case 1:
        print("You entered ONE");
        break;
        case 2:
        print("You entered TWO");
        break;
        case 3:
        print("You entered THREE");
        break;
        case 4:
        print("You entered FOUR");
        break;
        case 5:
        print("You entered FIVE");
        break;
        case 6:
        print("You entered SIX");
        break;
        case 7:
        print("You entered SEVEN");
        break;
        case 8:
        print("You entered EIGHT");
        break;
        case 9:
        print("You entered NINE");
        break;
        default:
        print("wrong input");
        }
       }
       

  2.     #include<stdio.h>
         
        void main()
        {
        int num;
        printf("enter any number between 1 to 12:");
        scanf("%d",&num);
        switch(num)
        {
        case 1:
        print("You entered JANUARY");
        break;
        case 2:
        print("You entered FEBURARY");
        break;
        case 3:
        print("You entered MARCH");
        break;
        case 4:
        print("You entered APRIL");
        break;
        case 5:
        print("You entered MAY");
        break;
        case 6:
        print("You entered JUNE");
        break;
        case 7:
        print("You entered JULY");
        break;
        case 8:
        print("You entered AUGUST");
        break;
        case 9:
        print("You entered SEPTEMBER");
        break;
         case 10:
        print("You entered OCTOBER");
        break;
        case 11:
        print("You entered NOVEMBER");
        break;
        case 12:
        print("You entered DECEMBER");
        break;
        default:
        print("wrong input");
        }
       }
        

  3.     #include<stdio.h>
         
        void main()
        {
        int num;
        printf("enter any number between 1 to 7:");
        scanf("%d",&num);
        switch(num)
        {
        case 1:
        print("You entered SUNDAY");
        break;
        case 2:
        print("You entered MONDAY");
        break;
        case 3:
        print("You entered TUESDAY");
        break;
        case 4:
        print("You entered WEDNESDAY");
        break;
        case 5:
        print("You entered THURSDAY");
        break;
        case 6:
        print("You entered FRIDAY");
        break;
        case 7:
        print("You entered SATURDAY");
        break;
        default:
        print("wrong input");
        }
       }
        

  4.     #include<stdio.h>
         
        void main()
        {
        char ch;
        printf("Enter any character in lowercase:");
        scanf("%c",&ch);
        switch(ch)
        {
        case 'a':
        print("Character is vowel");
        break;
        case 'e':
        print("Character is vowel");
        break;
        case 'i':
        print("Character is vowel");
        break;
        case 'o':
        print("Character is vowel");
        break;
        case 'u':
         print("Character is vowel");
        break;
        default:
        printf("character is consonent");
       }}
        

  5.     #include<stdio.h>
         
        #include<stdlib.h> 
        void 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 multilication");
        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;
       
        default:
        printf("EXIT");
        }}
        

  6.     #include<stdio.h>
         
        #include<stdlib.h> 
        void 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");
      }
        break;
       }}
       

    #include<stdio.h>
     
    #include<stdlib.h> 
    void main()
    {
    int value;
    char a;
    int x=0,y=1,z,i,fac=1;
    
   
    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("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

  1.     #include<stdio.h>
         
        void main()
        {
        int i;
        clrscr();
        for(i=1;i<=10;i++)
        {
        printf("*");
        }
         
        }

  2.     #include<stdio.h>
         
        void main()
        {
        int i;
        clrscr();
        for(i=1;i<=7;i++)
        {
        printf("*");
        print("\n");
        }
         
        }

  3.     #include<stdio.h>
         
        void main()
        {
        int i;
        clrscr();
        for(i=1;i<=6;i++)
        {
        printf("    *");
        print("\nCOMPUHELP\n");
        }
         
        }

  4.     #include<stdio.h>
         
        void main()
        {
        int i;
        clrscr();
        for(i=0;i<=9;i++)
        {
        printf("%d ",i);
            }
         
        }

  5.     #include<stdio.h>
         
        void main()
        {
        int i;
        clrscr();
        for(i=9;i>=0;i--)
        {
        printf("%d ",i);
            }
         
        }

  6.     #include<stdio.h>
         
        void main()
        {
        int i;
        clrscr();
        for(i=5;i<=20;i++)
        {
        printf("%d ",i);
            }
         
        }

  7.     #include<stdio.h>
         
        void main()
        {
        int i;
        clrscr();
        for(i=45;i>=7;i--)
        {
        printf("%d ",i);
            }
         
        }

  8.     #include<stdio.h>
         
        void main()
        {
        int i;
        clrscr();
        for(i=1;i<=20;i+=2)
        {
        printf("%d\n",i);
            }
         
        }

  9.     #include<stdio.h>
         
        void main()
        {
        int i;
        clrscr();
        for(i=0;i<=20;i+=2)
        {
        printf("%d\n",i);
            }
         
        }

  10.     #include<stdio.h>
         
        void main()
        {
        int i,num;
        clrscr();
        printf("Enter number ");
        scanf("%d",&num);
        for(i=1;i<=num;i+=2)
        {
        printf("%d\n",i);
            }
         
        }

  11.     #include<stdio.h>
         
        void main()
        {
        int i,num;
        clrscr();
        printf("Enter number ");
        scanf("%d",&num);
        for(i=0;i<=num;i+=2)
        {
        printf("%d\n",i);
            }
         
        }

  12.     #include<stdio.h>
         
        void main()
        {
        int i;
        clrscr();
         for(i=0;i<=50;i+=3)
        {
        printf("%d\n",i);
            }
         
        }

  13.     #include<stdio.h>
         
        void main()
        {
        int i,num,a=0,b=1,res=0;
        clrscr();
        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);
            }
         
        }

  14.     #include<stdio.h>
         
        void main()
        {
        int i,num,prod=1;
        clrscr();
        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;
        }
         
        }

  15.     #include<stdio.h>
         
        void main()
        {
        int i,num,fact=1;
        clrscr();
        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);
         
        }

  16.     #include<stdio.h>
         
        void main()
        {
        int i,num,sum=0;
        clrscr();
        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);
         
        }

  17.     #include<stdio.h>
         
        void 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

  1.     #include<stdio.h>
         
        void main()
        {
        int row,col;
        for(row=1;row<=3;row++)
        {
        for(col=1;col<=3;col++)
        {
        printf("*");
        }
        printf("\n");
        }
         
        }

  2.     #include<stdio.h>
         
        void main()
        {
        int row,col,k=1;
        for(row=1;row<=3;row++)
        {
        for(col=1;col<=3;col++)
        {
        printf("%d",k);
        }
        printf("\n");
        }
         
        }

  3.     #include<stdio.h>
         
        void main()
        {
        int row,col;
        for(row=1;row<=3;row++)
        {
        for(col=1;col<=3;col++)
        {
        printf("%d",col);
        }
        printf("\n");
        }
         
        }

  4.     #include<stdio.h>
         
        void main()
        {
        int row,col;
        for(row=1;row<=3;row++)
        {
        for(col=1;col<=3;col++)
        {
        printf("%d",row);
        }
        printf("\n");
        }
         
        }

  5.     #include<stdio.h>
         
        void main()
        {
        int row,col,k=1;
        for(row=1;row<=3;row++)
        {
        for(col=1;col<=3;col++)
        {
        printf("%d",k);
        k++;
        }
        printf("\n");
        }
         
        }

  6.     #include<stdio.h>
         
        void main()
        {
        int row,col;
        for(row=3;row>=1;row--)
        {
        for(col=1;col<=3;col++)
        {
        printf("%d",row);
        }
        printf("\n");
        }
         
        }

  7.     #include<stdio.h>
         
        void main()
        {
        int row,col,k=9;
        for(row=1;row<=3;row++)
        {
        for(col=1;col<=3;col++)
        {
        printf("%d",k);
        k--;
        }
        printf("\n");
        }
         
        }

  8.     #include<stdio.h>
         
        void main()
        {
        int row,col;
        for(row=3;row>=1;row--)
        {
        for(col=3;col>=1;col--)
        {
        printf("%d",col);
        }
        printf("\n");
        }
         
        }

  9.     #include<stdio.h>
         
        void main()
        {
        int row,col;
        for(row=1;row<=3;row++)
        {
        for(col=1;col<=row;col++)
        {
        printf("*");
        }
        printf("\n");
        }
         
        }

  10.     #include<stdio.h>
         
        void main()
        {
        int row,col;
        for(row=3;row>=1;row--)
        {
        for(col=1;col<=row;col++)
        {
        printf("*");
        }
        printf("\n");
        }
         
        }

  11.     #include<stdio.h>
         
        void main()
        {
        int row,col;
        for(row=1;row<=3;row++)
        {
        for(col=1;col<=row;col++)
        {
        printf("%d",col);
        }
        printf("\n");
        }
         
        }

  12.     #include<stdio.h>
         
        void main()
        {
        int row,col;
        for(row=1;row<=3;row++)
        {
        for(col=1;col<=row;col++)
        {
        printf("%d",row);
        }
        printf("\n");
        }
         
        }

  13.     #include<stdio.h>
         
        void main()
        {
        int row,col;
        for(row=3;row>=1;row--)
        {
        for(col=3;col>=row;col--)
        {
        printf("%d",row);
        }
        printf("\n");
        }
         
        }

  14.     #include<stdio.h>
         
        void main()
        {
        int row,col;
        for(row=1;row<=3;row++)
        {
        for(col=3;col>=row;col--)
        {
        printf("%d",row);
        }
        printf("\n");
        }
         
        }

  15.     #include<stdio.h>
         
        void main()
        {
        int row,col;
        for(row=3;row>=1;row--)
        {
        for(col=row;col<=3;col++)
        {
        printf("%d",col);
        }
        printf("\n");
        }
         
        }

  16.     #include<stdio.h>
         
        void main()
        {
        int row,col;
        for(row=3;row>=1;row--)
        {
        for(col=3;col>=row;col--)
        {
        printf("%d",col);
        }
        printf("\n");
        }
         
        }

  17.     #include<stdio.h>
         
        void 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");
        }
         
        }

  18.     #include<stdio.h>
         
        void 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");
        }
         
        }

  19.     #include<stdio.h>
         
        void main()
        {
          int row,col,k;
        for(row=1;row<=3;row++)
        {
        for(k=row;k>=2;k--)
        {
        printf(" ");
        }
        for(col=row;col<=3;col++)
        {
        printf("%d",row);
        }
        printf("\n");
        }
         
        }

  20.     #include<stdio.h>
         
        void main()
        {
          int row,col;
        for(row=1;row<=3;row++)
        {
        for(col=1;col<=row;col++)
        {
        printf("*");
        }
        printf("\n");
        }
         
        }

  21.     #include<stdio.h>
         
        void main()
        {
          int i,j,k=1;
        for(i=1;i<=5;i+=2)
        {
        for(j=1;j<=i;j++)
        {
        printf("%d",k);
        }
        printf("\n");
        k++;
        }
         
        }

  22.     #include<stdio.h>
         
        void main()
        {
          int i,j;
        for(i=1;i<=3;i++)
        {
        for(j=1;j<=i;j++)
        {
        printf("%d",i);
        }
        printf("\n");
    
        }
         
        }

  23.     #include<stdio.h>
         
        void main()
        {
          int i,j,k,n=1;
        for(i=1;i<=5;i+=2)
        {
        for(k=i;k<=4;k+=2)
        {
        printf(" ");
        }
        for(j=1;j<=i;j++)
        {
        printf("%d",n);
        }
        printf("\n");
         n++;
        }
         
        }

  24.     #include<stdio.h>
         
        void main()
        {
          int i,j,k,n=1;
        for(i=1;i<=3;i++)
        {
        for(k=i;k<=2;k++)
        {
        printf(" ");
        }
        for(j=1;j<=i;j++)
        {
        printf(" %d",n);
        }
        printf("\n");
         n++;
        }
         
        }

  25.     #include<stdio.h>
         
        void main()
        {
          int i,j;
        for(i=1;i<=5;i+=2)
        {
        for(j=5;j>=i;j--)
        {
        printf("*");
        }
        printf("\n");
        }
         
        }

  26.     #include<stdio.h>
         
        void main()
        {
          int i,j;
        for(i=1;i<=3;i++)
        {
        for(j=3;j>=i;j--)
        {
        printf(" *");
        }
        printf("\n");
        }
         
        }

  27.     #include<stdio.h>
         
        void main()
        {
          int i,j,k;
        for(i=1;i<=5;i+=2)
        {
        for(k=1;k<=i;k+=2)
        {
         printf(" ");
        }
        for(j=i;j<=5;j++)
        {
        printf("*");
        }
        printf("\n");
        }
         
        }

  28.     #include<stdio.h>
         
        void main()
        {
          int i,j,k;
        for(i=1;i<=3;i++)
        {
        for(k=1;k<=i;k++)
        {
         printf(" ");
        }
        for(j=i;j<=3;j++)
        {
        printf(" *");
        }
        printf("\n");
        }
         
        }

  29.     #include<stdio.h>
         
        void main()
        {
          int i,j,k=3;
        for(i=1;i<=5;i+=2)
        {
        for(j=5;j>=i;j--)
        {
        printf("%d",k);
        }
        printf("\n");
        k--;
        }
         
        }

  30.     #include<stdio.h>
         
        void main()
        {
          int i,j,k=3;
        for(i=1;i<=3;i++)
        {
        for(j=3;j>=i;j--)
        {
        printf(" %d",k);
        }
        printf("\n");
        k--;
        }
         
        }

  31.     #include<stdio.h>
         
        void main()
        {
          int i,j,k,n=3;
        for(i=5;i>=1;i-=2)
        {
        for(k=5;k>=i;k-=2)
        {
         printf(" ");
        }
        for(j=1;j<=i;j++)
        {
        printf("%d",n);
        }
        printf("\n");
        n--;
        }
         
        }

  32.     #include<stdio.h>
         
        void main()
        {
          int i,j,k,n=1;
         for(i=1;i<=5;i+=2)
        {
        for(k=i;k<=5;k+=2)
        {
         printf(" ");
        }
        for(j=1;j<=i;j++)
        {
        printf("%d",n);
        }
        printf("\n");
        n++;
        }
        n=n-2;
        for(i=3;i>=1;i-=2)
        {
        for(k=5;k>=i;k-=2)
        {
         printf(" ");
        }
        for(j=1;j<=i;j++)
        {
        printf("%d",n);
        }
        printf("\n");
        n--;
        }
         
        }

  33.     #include<stdio.h>
         
        void main()
        {
         int i,j,k,n=3;
        for(i=3;i>=1;i--)
        {
        for(k=5;k>=i;k--)
        {
         printf(" ");
        }
        for(j=1;j<=i;j++)
        {
        printf(" %d",n);
        }
        printf("\n");
        n--;
        }
         
        }

  34.     #include<stdio.h>
         
        void main()
        {
          int i,j,k;
         for(i=1;i<=3;i++)
        {
        for(k=i;k<=3;k++)
        {
         printf(" ");
        }
        for(j=1;j<=i;j++)
        {
        printf(" %d",i);
        }
        printf("\n");
        }
        for(i=2;i>=1;i--)
        {
        for(k=3;k>=i;k--)
        {
         printf(" ");
        }
        for(j=1;j<=i;j++)
        {
        printf(" %d",i);
        }
        printf("\n");
        }
    
         
        }

Assignments of While and Do While Loops

  1.     #include<stdio.h>
         
        #include<stdlib.h> 
        void main()
        {
        int i, m,n=0;
        printf("enter nth number:");
        scanf("%d",&n);
        while(m<=n)
        {
        printf("%d",m);
        m++;
        }
        }
        

  2.     #include<stdio.h>
         
        #include<stdlib.h> 
        void main()
        {
        int i,m;
        printf("enter starting number:");
        scanf("%d",&m);
        while(m>=0)
        {
        printf("%d",m);
        m--;
        }
        }
        

  3.     #include<stdio.h>
         
        #include<stdlib.h> 
        void 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++;
        }
        }
        

  4.     #include<stdio.h>
         
        #include<stdlib.h> 
        void 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));
        }
            

  5.     #include<stdio.h>
         
        #include<stdlib.h> 
        void 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++;
        }
        } 
        

  6.     #include<stdio.h>
         
        #include<stdlib.h> 
        void 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);
        }
        }
            

  7.     #include<stdio.h>
         
        #include<stdlib.h> 
        void 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>
     
    #include<stdlib.h> 
    void 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);
        }
        

Assignments of Character

  1. //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;
    
    }//end of main
    

  2. //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;
    
    }//end of main
    
    

  3. //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;
    
    }//end of main
    

  4. // 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;
    
    }//end of main
    

  5. // 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;
    
    }//end of main
    

  6. //  program to display the ASCII values from 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;
    
    }//end of main
    

  7. /*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;
    
    }//end of main
    
    

  8. /* 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;
    
    }//end of main
    
    

  9. /* 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;
    
    }//end of main
    

    Assignments of single Dimensional Array

    1.     #include<stdio.h>
           
          void 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]);
            }
           
          }

    2.     #include<stdio.h>
           
          void main()
          {
            int arr[5],i;
            printf("Enter array elements ");
            for(i=0;i<=4;i++)
            {
            scanf("%d",&arr[i]);
            }
            printf("\n Elements in reverse order are:\n");
            for(i=4;i>=0;i--)
            {
            printf("\n Element is %d",arr[i]);
            }
           
          }

    3.     #include<stdio.h>
           
          void 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]);
            }
           
          }

    4.     #include<stdio.h>
           
          void main()
          {
            int arr[5],arr1[5],i,j;
            printf("Enter array elements ");
            for(i=0;i<=4;i++)
            {
            scanf("%d",&arr[i]);
            }
            printf("\n The copy of array elements is :\n");
            j=0;
            for(i=4;i>=0;i--)
            {
                 arr1[j]=arr[i];
            printf("\n Element is %d",arr1[j]);
            j++;
            }
           
          }

    5.     #include<stdio.h>
           
          void main()
          {
            int arr[5],i,sum=0;
            printf("Enter array elements ");
            for(i=0;i<=4;i++)
            {
            scanf("%d",&arr[i]);
            }
            printf("\n The sum of array elements is :\n");
            for(i=0;i<=4;i++)
            {
                 sum=sum+arr[i];
            printf("%d+",arr[i]);
            }
            printf("\b=%d",sum);
           
          }

    6.     #include<stdio.h>
           
          void 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]);
            }
           
          }

    7.     #include<stdio.h>
           
          void 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 sum of array elements is :\n");
            for(i=0;i<=4;i++)
            {
                 diff[i]=arr1[i]-arr2[i];
             printf(" %d",diff[i]);
            }
           
          }

    8.     #include<stdio.h>
           
          void 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);
             
          }

    9.     #include<stdio.h>
           
          void main()
          {
            int arr[5],i,small,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(small>arr[i])
            {
            small=arr[i];
            loc=i+1;
            }
            }
            printf("\n The smallest element is :%d",small);
            printf("\n The location is: %d",loc);
             
          }

    10.     #include<stdio.h>
           
          void 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]);
            }
             
          }

    11.     #include<stdio.h>
           
          void 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]
          

    12.     #include<stdio.h>
           
          void 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");
            }
      
             
          }

    Assignments of Two Dimensional Array

    1.     #include<stdio.h>
           
          #include<stdlib.h> 
          void 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");
          }
           
          }
              

    2.     #include<stdio.h>
           
          #include<stdlib.h> 
          void 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");
          }
           
          }
              

    3.     #include<stdio.h>
           
          #include<stdlib.h> 
          void 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");
          }
           
          }
              

    4.     #include<stdio.h>
           
          void 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");
          }
           
          }
              

    5.     #include<stdio.h>
           
          void 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");
          }
           
          }
              

    6.     #include<stdio.h>
           
          void 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);
          }
           
          }
              

    7.     #include<stdio.h>
           
          void 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");
              }
           
          }
              

    8.     #include<stdio.h>
           
          void 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");
              }
           
          }
              

    9.     #include<stdio.h>
           
              void 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 division 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");
              }
           
          }
              

    10.     #include<stdio.h>
           
          void 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 Enter the elements of the second matrix:");
         for(i=0;i<2;i++)
          {
          for(j=0;j<2;j++)
          {
          scanf("%d",&arr1[i][j]);
          printf("%d",arr3[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");
          {
           
          }}
              

    11.     #include<stdio.h>
           
          void 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;
           i=j+1;
           }}}
           printf("The greatest element is %d and present in %d row and in %d column",large,k,i);
          {
           
          }
             

    12.     #include<stdio.h>
           
          
          void 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");
           }
           small=arr[i][j];
           for(i=0;i<2;i++)
          {
           for(j=0;j<2;j++)
           {
           if(arr[i][j]

    13.     #include<stdio.h>
           
          
          void 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");
           }    
           
          }}
             

    14.     #include<stdio.h>
           
              void main()
          {
          int arr[3][3],i,j,n,flag=1;
          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");
          }
           
          }
             

    15.     #include<stdio.h>
           
          #include<stdlib.h> 
          void main()
          {
          int arr[3][3],i,j;
          printf("Enter the square matrix:");
          for(i=0;i<3;i++)
          {
           for(j=0;j<3;j++)
           {
           scanf("%d",&arr[i][j]);
           }}
           printf("\n The elements are: ");
           printf("\n");
           for(i=0;i<3;i++)
          {
           for(j=0;j<3;j++)
           {
           printf("%d",arr[i][j]);
           }
           printf("\n");
           }
          printf("The left diagonal is:");
           for(i=0;i<3;i++)
          {
           for(j=0;j<=i;j++)
           {
              printf("%d",arr[i][j]);
          }
           
          }}
             

    16.     #include<stdio.h>
           
          void main()
          {
          int arr[3][3],i,j;
          printf("Enter the square matrix:");
          for(i=0;i<3;i++)
          {
           for(j=0;j<3;j++)
           {
           scanf("%d",&arr[i][j]);
           }}
           printf("\n The elements are: ");
           printf("\n");
           for(i=0;i<3;i++)
          {
           for(j=0;j<3;j++)
           {
           printf("%d",arr[i][j]);
           }
           printf("\n");
           }
          printf("The lower triangle is :");
           for(i=1;i<3;i++)
          {
           for(j=0;j<=i;j++)
           {
              printf("%d",arr[i][j]);
          }
           
          }}
             

        #include<stdio.h>
         
           void main()
        {
        int arr[3][3],i,j;
        printf("Enter the square matrix:");
        for(i=0;i<3;i++)
        {
         for(j=0;j<3;j++)
         {
         scanf("%d",&arr[i][j]);
         }}
         printf("\n The elements are: ");
         printf("\n");
         for(i=0;i<3;i++)
        {
         for(j=0;j<3;j++)
         {
         printf("%d",arr[i][j]);
         }
         printf("\n");
         }
        printf("The lower triangle is:");
         for(i=0;i<2;i++)
        {
         for(j=i+1;j<=2;j++)
         {
            printf("%d",arr[i][j]);
        }
         
        }}
           

    Assignments of Character Array

    1.     #include<stdio.h>
          void main()
          {
          char name[30];
          printf("Enter a string");
          scanf("%s",&name);
          printf("You entered: %s",name);
          }
        

    2.     #include<stdio.h>
          void main()
          {
          char name[30];
          printf("Enter a string");
          gets(name);//to read a string with spaces
          printf("You entered:);
          puts(name);
          }
        

    3.     #include<stdio.h>
          void main()
          {
          char name[20],i,j;
          printf("Enter a string");
          gets(name);
          for(i=0;name[i]!='\0';i++);
          {
          printf("Entered string is:");
          }
          for(j=i-1;j>=0;j--)
          {
          printf("%c",name[j]);
          }
         }
      

    4.     #include<stdio.h>
          void main()
          {
          char name[20],i;
          printf("Enter a string");
          gets(name);
          for(i=0;name[i]!='\0';i++);
          printf("The length of the string is: %d",i);
         }
      

    5.     #include<stdio.h>
          void main()
          {
          char name[20],i;
          printf("Enter a string in uppercase");
          gets(name);
          printf("\nThe string in lowercase");
          for(i=0;name[i]!='\0';i++)
          {
          if((name[i]>='A')&&(name[i]<='Z'))
          {
          name[i]=name[i]+32;
          }}
          puts(name);
        }
      

    6.     #include<stdio.h>
          void main()
          {
          char name[20],i;
          printf("Enter a string in lowercase");
          gets(name);
          printf("\nThe string in uppercase");
          for(i=0;name[i]!='\0';i++)
          {
          if((name[i]>='a')&&(name[i]<='z'))
          {
          name[i]=name[i]-32;
          }}
          puts(name);
          }
      

    7.     #include<stdio.h>
          void 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]!='\0';i++)
          {
          if((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);
         }
      

    8.     #include<stdio.h>
          void main()
          {
          char name[20];
          int i,cnt=0;
          printf("Enter a string:");
          gets(name);
          printf("\nThe consonents are: ");
          for(i=0;name[i]!='\0';i++)
          {
          if((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 consonents  are:%d",cnt);
        }
      

    9.     #include<stdio.h>
          void 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]!='\0';i++)
          {
          name1[i]=name[i];
          printf("%c",name[i]);
          }
          }
      

    10.     #include<stdio.h>
          void main()
          {
          char str1[20],str2[2],str3[20];
          int i,j;
          printf("Enter first string:");
          scanf("%s",&str1);
          printf("Enter second  string:");
          scanf("%s",&str2);
          for(i=0;str1[i]!='\0';i++)
          {
          str3[i]=str1[i];
          }
          for(j=0;str2[j]!='\0';j++)
          {
          str3[i]=str2[j];
          i++;
          }
          str3[i]='\0';
          printf("\n%s",str3);
        }

    11.     #include<stdio.h>
          void main()
          {
          char name[20];
          int i,wrd=0;
          printf("Enter a sentence:");
          gets(name);
          printf("The number of words are:");
          for(i=0;name[i]!='\0';i++)
          {
          if(name[i]=='')
          wrd++;
         }
             printf("%d",wrd+1);
          }
      

    12.     #include<stdio.h>
          void main()
          {
          char name[30];
          int i,spc=0;
          printf("Enter a sentence:");
          gets(name);
          printf("The number of spaces are:");
          for(i=0;name[i]!='\0';i++)
          {
          if(name[i]=='')
          spc++;
          }
          printf("%d",spc+1);
          }
      

    13.     #include<stdio.h>
          void main()
          {
          char name[30];
          int i,lwr=0;
          printf("Enter a sentence:");
          gets(name);
          printf("The numbers of lower case letters are:");
          for(i=0;name[i]!='\0';i++)
          {
          if(name[i]>='a')&&(name[i]<='z'))
          lwr++;
          }
          printf("%d",lwr);
         }
      

    14.     #include<stdio.h>
          void main()
          {
          char name[30];
          int i,upr=0;
          printf("Enter a sentence:");
          gets(name);
          printf("The numbers of upper case letters are:");
          for(i=0;name[i]!='\0';i++)
          {
          if(name[i]>='A')&&(name[i]<='Z'))
          upr++;
          }
          printf("%d",upr);
        }
      

      Assignments of Pointer

      1.     #include<stdio.h>
             
            void 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);
               
            }

      2.     #include<stdio.h>
             
            void main()
            {
            int num1,num2,temp;
           int *aptr,*bptr,*cptr;
           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);
        
               
            }

      3.     #include<stdio.h>
             
            void 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);
           }
        
               
            }

      4.     #include<stdio.h>
             
            void 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);
               
            }

      5.     #include<stdio.h>
             
            void 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);
              }
        
               
            }

      6.     #include<stdio.h>
             
            void 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);
            }
               
            }

      7.     #include<stdio.h>
             
            void 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]);
         }
        }
        printf("\n The sum of array elements is: \n");
        for(i=0;i<3;i++)
        {
         for(j=0;j<3;j++)
         {
         ptr=&arr[i][j];
         sum=sum+arr[i][j];
         }}
         printf("\n %d",sum);
        
               
            }

      ASSIGNMENTS OF FUNCTIONs

      1.     #include<stdio.h>
             
            void main()
            {
              void sum();        //declaration of sum() function
              sum();        //calling sum() function
               
            }

        void sum()        //definition 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); }

      2.     #include<stdio.h>
             
            void main()
            {
              void sum();        //declaration of sum() function
              void subtract();        //declaration of subtract() function
              void multiply();        //declaration of multiply() function
              void division();        //declaration of division() function
                 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 '+': sum();        //calling sum() function break; case '-': subtract();        //calling subtract() function break; case '*': multiply();        //calling multiply() function break; case '/': division();        //calling division() function break; default: printf("Invalid choice"); } }

        void sum()        //definition of sum() { int num1,num2,res; printf("Enter first number: "); scanf("%d",&num1); printf("Enter second number: "); scanf("%d",&num2); res=num1+num2; printf("\n The sum of numbers is %d",res); } void subtract()        //definition of subtract() { int num1,num2,res; printf("Enter first number: "); scanf("%d",&num1); printf("Enter second number: "); scanf("%d",&num2); if(num1>num2) { res=num1-num2; } else { res=num2-num1; } printf("\n The subtraction of numbers is %d",res); } void multiply()        //definition of multiply() { int num1,num2,res; printf("Enter first number: "); scanf("%d",&num1); printf("Enter second number: "); scanf("%d",&num2); res=num1*num2; printf("\n The multiplication of numbers is %d",res); } void division()        //definition of division() { int num1,num2,res; printf("Enter first number: "); scanf("%d",&num1); printf("Enter second number: "); scanf("%d",&num2); res=num1/num2; printf("\n The division of numbers is %d",res); }

      3.     #include<stdio.h>
             
            void main()
        {
        void odd(int);
        int num;
        printf("Enter nth number");
        scanf("%d",&num);
        odd(num);
         
        }
        
        void odd(int n)
        {
         int i;
         printf("\n The odd series is : ");
         for(i=1;i<=n;i+=2)
         {
          printf("%2d",i);
         }
        }
            

      4.     #include<stdio.h>
             
            void main()
        {
        void even(int);
        int num;
        printf("Enter nth number");
        scanf("%d",&num);
        even(num);
         
        }
        
        void even(int n)
        {
         int i;
         printf("\n The even series is : ");
         for(i=0;i<=n;i+=2)
         {
          printf("%2d",i);
         }
        }
            

      5.     #include<stdio.h>
             
            void main()
         	{
        void square(int);
        int num;
        printf("Enter a number");
        scanf("%d",&num);
        square(num);
         
        }
        
        void square(int n)
        {
         int i;
         for(i=1;i<=n;i++)
         {
          printf("\n The square of %d is : %d",i,i*i);
         }
        }
            

      6.     #include<stdio.h>
             
            void main()
         	{
        void display(char,int);
        char ch;
        int num;
        printf("Enter a character");
        scanf("%c",&ch);
        printf("Enter the limit");
        scanf("%d",&num);
        display(ch,num);
         
        }
        
        void display(char ch1,int n)
        {
         int i;
         for(i=1;i<=n;i++)
         {
          printf(" %c",ch1);
         }
        }    

      7.     #include<stdio.h>
             
            void main()
         	{
        void series(int,int);
        int m,n;
        printf("Enter starting value");
        scanf("%d",&m);
        printf("Enter ending value");
        scanf("%d",&n);
        series(m,n);
         
        }
        
        void series(int a,int b)
        {
         int i;
         printf("\n The series is : ");
         for(i=a;i<=b;i++)
         {
          printf("%d ",i);
         }
        }
           

      8.     #include<stdio.h>
             
            	void main()
         		{
        void sum_series(int,int);
        int m,n;
        printf("Enter starting value:");
        scanf("%d",&m);
        
        printf("Enter ending value:");
        scanf("%d",&n);
        sum_series(m,n);
          
        		 }
        void sum_series(int a,int b)
        {
        int i, sum=0;
        printf("The sum of series is");
        for(i=a;i<=b;i++)
        {
        sum=sum+i;
        printf("%d+",i);
        }
        printf("\b=%d",sum);
        }
           

      9.     #include<stdio.h>
             
            	void main()
         		{
        void alphabets(char);
        char alp;
        printf("Enter the alphabet int upper case:");
        scanf("%c",&alp);
        alphabets(alp);
         
        }
        void alphabets(char a)
        {
        int i;
        printf("The alphabets are:");
        for(i=65;a<=90;a++)
        {
        printf("%c",a);
        }}
           

      10.     #include<stdio.h>
             
            	void main()
              {
        void is_pos_neg(int);
        int num;
        printf("Enter any number:");
        scanf("%d",&num);
        is_pos_neg(num);
         
        }
        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");
        }
           

      11.     #include<stdio.h>
             
            	void main()
              {
        void fibonacci(int);
        int num;
        printf("Enter ending value:");
        scanf("%d",&num);
        fibonacci(num);
         
        }
        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);
        }}  

      12.     #include<stdio.h>
             
            	void main()
              {
        void fibonacci(int);
        int num;
        printf("Enter ending value:");
        scanf("%d",&num);
        fibonacci(num);
         
        }
        void fibonacci(int n)
        {
        int i,j=0,k=1,m;
        printf("%d %d",j,k);
        for(i=1;i<=n-2;i++)
        {
        m=j+k;
        j=k;
        k=m;
        if(m<=n)
        printf("%d",m);
        }} 
         

      13.     #include<stdio.h>
             
            	void main()
              {
        char ch[20];
        void to_upper(char a[20]);
        printf("Enter an alphabet in lowercase");
        scanf("%s",&ch);
        to_upper(ch);
         
        }
        void to_upper(char a[20])
        {
        int i;
        printf("The alphabet in uppercase is:");
        for(i=0;a[i]!='\0';i++)
        {
        if((a[i]>='a')&&(a[i]<='z'))
        {
        a[i]=a[i]-32;
        }
        printf("%s",a);
        }}
         

      14.     #include<stdio.h>
             
            	void main()
              {
        char ch[20];
        void to_upper(char a[20]);
        printf("Enter an alphabet in uppercase");
        scanf("%s",&ch);
        to_upper(ch);
         
        }
        void to_upper(char a[20])
        {
        int i;
        printf("The alphabet in lowercase is:");
        for(i=0;a[i]!='\0';i++)
        {
        if((a[i]>='A')&&(a[i]<='Z'))
        {
        a[i]=a[i]+32;
        }
        printf("%s",a);
        }} 

      15.     #include<stdio.h>
             
            	void main()
              {
        void series(int);
        int num;
        printf("Enter a number");
        scanf("%d",&num);
        series(num);
         
        }
        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);
        } 

      16.     #include<stdio.h>
             
            	void main()
              {
        int factorial(int);
        int num,ans;
        printf("Enter a number");
        scanf("%d",&num);
        ans=factorial(num);
        printf("\b=%d",ans);
         
        }
        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);
        } 

      17. #include<stdio.h>
        void main()
        {
        void triangle(int);
        int num;
        printf("Enter any number");
        scanf("%d",&num);
        triangle(num);
        }

        void triangle(int n)
        {
        int i,j,k,m=1;
        for(int i=n;i>=1;i--)
        {
        for(int j=1;j<=i-1;j++)
        {
        printf(" ");
        }
        for(int k=1;k<=m;k++)
        {
        printf("*");
        }
        printf("\n");
        m++;
        }
        }

      18. #include<stdio.h>
        void triangle(int);
        void main()
        {
        int num;
        printf("Enter any number");
        scanf("%d",&num);
        triangle(num);
        }

        void triangle(int n)
        {
        int i,j,k;
        for(i=1;i<=n;i++)
        {
        for(j=1;j<=i;j++)
        {
        printf(" ");
        }
        for(k=i;k<=n;k++)
        {
        printf("*"); // print the Star
        }
        printf ("\n");
        } }

         

      19. #include<stdio.h>
        void pyramid(int);
        void main()
        {
        int num;
        printf("Enter any number");
        scanf("%d",&num);
        pyramid(num);
        }

        void pyramid(int n)
        {
        int i,j,k;
        for(i=1;i<=n;i++)
        {
        for(j=1;j<=n-i;j++)
        {
        printf(" ");
        }
        for(k=1;k<=(2*i-1);k++)
        {
        printf("* ");
        }
        printf("\n");
        }
        }

      20.     #include<stdio.h>
             
            	void main()
              {
        void swap(int,int);
        int x,y;
        printf("Enter first number");
        scanf("%d",&x);
        printf("Enter Second number");
        scanf("%d",&y);
        swap(x,y);
         
        }
        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("\nFirst: %d",a);
        printf("\nSecond: %d",b);
        }
        

      21. #include<stdio.h>
             
        void main()
        {
        int fact(int);
        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);
        }
        
        int fact(int value)
        {
        int ans;
         if((value==0)||(value==1))
         return(1);
         else
         ans=value*fact(value-1);
         return(ans);
         }
        

        Assignments of Structure

        1.     #include<stdio.h>
               
              
               struct student
            {
            char name[10];
            int subject[9];
            };
          void main()
          {
            struct student st;
            int sum=0,avg,i;
            printf("Enter name");
            gets(st.name);
            for(i=0;i<9;i++)
            {
             printf("Enter the marks of %d subject",i+1);
             scanf("%d",&st.subject[i]);
             sum=sum+st.subject[i];
            }
            avg=sum/9;
            printf("\n Average of nine subjects is %d",avg);
                       
              }
              

        2.     #include<stdio.h>
               
              struct employee
          {
            char name[10];
            int salary;
            int id;
          };
          
          void 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);
           }
                   
              }
              

        3.     #include<stdio.h>
               
              struct student
          {
            char name[10];
            int subject[5];
          };
          void 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 student\n\n",i+1);
            for(j=0;j<5;j++)
            {
             printf("\nEnter 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 %d",i+1,avg);
            printf("\n");
            }
                   
              }
              

        4.     #include<stdio.h>
               
              struct student
          {
            char name[10];
            int subject[5];
          };
          void 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 nine subjects is %d",avg);
          
                   
              }
              

        5.     #include<stdio.h>
               
             struct student
          {
            char name[10];
            int subject[5];
          };
          void 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 student\n\n",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("\n\n");
            }
                   
              }
              

        6.     #include<stdio.h>
               
             struct student
          {
              int rollno;
              char name[10];
              int fee;
          }st;
          
          void main()
          {
          void display(struct student*);
          printf("Enter name : ");
          scanf("%s",&st.name);
          printf("Enter rollno : ");
          scanf("%d",&st.rollno);
          printf("Enter fee : ");
          scanf("%d",&st.fee);
          display(&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);
          }
              

          Assignments of File Handling

          1. #include<stdio.h>

            void main()
            {
            FILE *fptr;
            fptr=fopen("first.txt","w");
            fprintf(fptr,"Welcome to Compuhelp");
            fclose(fptr);

            }

          2. #include<stdio.h>

            void 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);

            }

          3. #include<stdio.h>

            void 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 Value of num= %d",num);
            fclose(fptr);

            }

          4. #include<stdio.h>

            void 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 anoter file");
            fptr=fopen("second.txt","w");
            fprintf(fptr,"%d",num);
            fclose(fptr);

            }

          5. #include<stdio.h>
            #include<stdlib.h>

            void 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 saved\n");
            fclose(fptr);
            fptr=fopen("string.txt","r");
            while(ch!=EOF)
            {
            ch=fgetc(fptr);
            printf("%c",ch);
            }
            fclose(fptr);

            }

          6. #include<stdio.h>
            #include<stdlib.h>

            void 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 saved\n");
            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);

            }

          7. #include<stdio.h>
            #include<stdlib.h>

            void 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 saved\n");
            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);

            }

          8. #include<stdio.h>
            #include<stdlib.h>

            void 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 saved\n");
            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);

            }

          9. #include<stdio.h>
            #include<stdlib.h>

            void main()
            {
            FILE *fptr;
            char 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 saved\n");
            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);

            }

          10. #include<stdio.h>
            #include<stdlib.h>

            void 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 COMPUHELP\n Thanks to Join Compuhelp\nBye");
            printf("Data saved\n");
            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);

            }

          11. #include<stdio.h>

            void 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);

            }

             

          12. #include<stdio.h>
            #include<stdlib.h>

            void 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 saved\n");
            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);

            }

             

          13. #include<stdio.h>
            #include<stdlib.h>

            struct student
            {
            char name[20];
            int rollno;
            float fee;
            };
            void 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);

            }