1. Question:Write a c program to know read/write permission of given file. 

    Answer
    #include "time.h"
    #include "sys\stat.h"
    #include "stdio.h"
    void main(){
        struct stat status;
        FILE *fp;
        stat("test.txt",&status);
        clrscr();
        if (status.st_mode & S_IREAD)
             printf("You have read permission.\n");
        if (status.st_mode & S_IWRITE)
             printf("You have write permission.");
        getch();
    
    }

    1. Report
  2. Question:Write a c program to know the last date of modification of any file 

    Answer
    #include "time.h"
    #include "sys\stat.h"
    #include "stdio.h"
    int main(){
        struct stat status;
        FILE *fp;
        fp=fopen("test.txt","r");
        fstat(fileno(fp),&status);
        
        printf("Last date of modification : %s",ctime(&status.st_ctime));
        return 0;
    }

    1. Report
  3. Question:Write a c program to find out the size and drive where file has stored of any given file? 

    Answer
    #include "time.h"
    #include "sys\stat.h"
    #include "stdio.h"
    int main(){
        struct stat status;
        FILE *fp;
        fp=fopen("test.txt","r");
        fstat(fileno(fp),&status);
        printf("Size of file : %d",status.st_size);
        printf("Drive name   : %c",65+status.st_dev);
        return 0;
    }

    1. Report
  4. Question:How to use complex numbers in c 

    Answer
    #include<stdio.h>
    int main(){
    int a,b;
    
    printf("Enter any complex number in the format a+ib: ");
    scanf("%d+i%d",&a,&b);
    
    printf("Real part is: %d",a );
    printf("\nImaginary part is: %d",b);
    
    return 0;
    
    }

    1. Report
  5. Question:C program to printf complex numbers 

    Answer
    #include<stdio.h>
    int main(){
    int a,b;
    
    printf("Enter the real part of complex number: ");
    scanf("%d",&a);
    
    printf("Enter the imaginary part of complex number: ");
    scanf("%d",&b);
    
    printf("\nComplex number is: %d%+di",a,b );
    
    return 0;
    
    }

    1. Report
  6. Question:C program to add two complex numbers 

    Answer
    #include<stdio.h>
    int main(){
      int a,b,c,d,x,y;
      printf("\nEnter the first complex number:");
      scanf("%d%d",&a,&b);
      printf("\nEnter the second complex number:");
      scanf("%d%d",&c,&d);
      if(b<0)
          printf("%d-i\n",a-b);
      else
          printf("d+i\n",a+b);
      if(d<0)
          printf("d-i\n",c-d);
      else
          printf("%d+i\n",c+d);
      printf("\nADDITION ");
      x=a+c;
      y=b+d;
      if(y>0)
          printf("%d-i%d",x,-y);
      else
          printf("%d+i%d",x,+y);
      printf("\n\nSUBTRACTION ");
      x=a-c;
      y=b-d;
      if(y<0)
          printf("%d-i%d",x,-y);
      else
          printf("%d+i%d",x,+y);
      return 0;
    }

    1. Report
  7. Question:Sum of 1 + 2 + …. + n series in c programming language 

    Answer
    #include<stdio.h>
    int main(){
    
        int n,i;
        int sum=0;
    
        printf("Enter the n i.e. max values of series: ");
        scanf("%d",&n);
    
        sum = (n * (n + 1)) / 2;
    
        printf("Sum of the series: ");
    
        for(i =1;i <= n;i++){
             if (i!=n)
                 printf("%d + ",i);
             else
                 printf("%d = %d ",i,sum);
             }
       
        return 0;
    }
    Sample output: Enter the n i.e. max values of series: 5 Sum of the series: 1 + 2 + 3 + 4 + 5 = 15

    1. Report
  8. Question:Sum of 1^2 + 2^2 + …. + n^2 series in c programming language 

    Answer
    #include<stdio.h>
    
    int main(){
    
        int n,i;
        int sum=0;
    
        printf("Enter the n i.e. max values of series: ");
        scanf("%d",&n);
    
        sum = (n * (n + 1) * (2 * n + 1 )) / 6;
    
        printf("Sum of the series : ");
    
        for(i =1;i<=n;i++){
             if (i != n)
                 printf("%d^2 + ",i);
             else
                 printf("%d^2 = %d ",i,sum);
        }
    
        return 0;
    }
    Sample output: Enter the n i.e. max values of series: 5 Sum of the series: 1^2 + 2^2 + 3^2 + 4^2 + 5^2 = 55

    1. Report
  9. Question:Write a c program or code to find out the sum of series 1^3 + 2^3 + …. + n^3 that is sum of cube of n natural numbers. 

    Answer
    #include<stdio.h>
    #include<math.h>
    
    int main(){
    
        int n,i;
        int sum=0;
    
        printf("Enter the n i.e. max values of series: ");
        scanf("%d",&n);
    
        sum = pow(((n * (n + 1) ) / 2),2);
    
        printf("Sum of the series : ");
    
        for(i =1;i<=n;i++){
             if (i != n)
                 printf("%d^3 + ",i);
             else
                 printf("%d^3 = %d ",i,sum);
        }
    
        return 0;
    }
    Sample output: Enter the n i.e. max values of series: 3 Sum of the series: 1^3 + 2^3 + 3^3 = 36

    1. Report
  10. Question:Write a c program to find out the sum of in A.P. series 

    Answer
    #include<stdio.h>
    #include<math.h>
    
    int main(){
    
        int a,d,n,i,tn;
        int sum=0;
    
        printf("Enter the first number of the A.P. series: ");
        scanf("%d",&a);
    
        printf("Enter the total numbers in the A.P. series: ");
        scanf("%d",&n);
    
        printf("Enter the common difference of A.P. series: ");
        scanf("%d",&d);
    
        sum = ( n * ( 2 * a + ( n -1 ) * d ) )/ 2;
        tn = a + (n-1) * d;
        printf("Sum of the series A.P.: ");
    
        for(i=a;i<=tn; i= i + d ){
             if (i != tn)
                 printf("%d + ",i);
             else
                 printf("%d = %d ",i,sum);
        }
    
        return 0;
    }
    Sample output: Enter the first number of the A.P. series: 1 Enter the total numbers in the A.P. series: 5 Enter the common difference of A.P. series: 3 Sum of the series: 1 + 4 + 7 + 10 + 13 = 35

    1. Report
Copyright © 2024. Powered by Intellect Software Ltd