Sunday, 1 July 2018

C Interview Questions


1. C Program to Print an Integer (Entered by the User)
  Solution:      

            #include<stdio.h>
            Void main()     
            {
               int a;
              printf(“Enter the integer value”); 
              scanf(“%d”,&a);
             printf(“%d”,a);
              return 0;
            }

2. C Program to Add Two Integers
  Solution:
#include<stdio.h>
void main()
{
    int a,b,c;
    printf("enter integer values of a,b:");
    scanf("%d%d",&a,&b);
    c=a+b;
    printf("a+b=%d",c);
}

3. C Program to Multiply Two Floating Point Numbers
  Solution:
#include<stdio.h>                                      
void main()
{
    float a=1.52,b=2.03,c;
    c=a*b; 
    printf("%f",c);
}

4. C Program to Find ASCII Value of a Character
  Solution:
#include<stdio.h>
void main()
{
    char ch;
    printf("Enter the character:");
    scanf("%c",&ch);
    printf("ASCII value of given Char, %c = %d",ch,ch);
}

5. C Program to Compute Quotient and Remainder
  Solution:


#include<stdio.h>


  void main()

{

    int dividend,divisor,remainder,quotient;

    printf("Enter the Integer values:");

    scanf("%d %d",&dividend,&divisor);

    quotient = dividend/divisor;

    remainder = dividend%divisor;

    printf("quotient = %d \nremainder = %d",quotient,remainder);

}

6. C Program to Find the Size of int, float, double and char
  Solution:

#include<stdio.h>
void main()
{
    printf("Size of Int : %d Bytes\nFloat : %d Bytes\nDouble : %d Bytes\nChar : %d Bytes",sizeof(int),sizeof(float),sizeof(double),sizeof(char));
}



7. C Program to Demonstrate the Working of Keyword long
  Solution:


#include <stdio.h>


int main()
{
    printf("Size of int = %ld bytes \n", sizeof(int));
    printf("Size of long = %ld bytes\n", sizeof(long));
    printf("Size of long long = %ld bytes\n", sizeof(long long));
    printf("Size of double = %ld bytes\n", sizeof(double));
    printf("Size of long double = %ld bytes\n", sizeof(long double));
}


8. C Program to Swap Two Numbers
  Solution:

#include <stdio.h>
int main()
{
    int a,b,temp;
    printf("enter the numbers to get swap:");
    scanf("%d %d",&a,&b);
    printf("a=%d b=%d\n",a,b);
 temp=a;
    a=b;
    b=temp;
    printf("swap numbers: a=%d b=%d",a,b);
}



No comments:

Post a Comment