Technical Point.

The Best Platform of Diploma CSE Students.

Subscribe Us

Breaking

Wednesday, August 5, 2020

August 05, 2020

All C program

Write a C program to print ‘Hello World’ on screen.

#include <stdio.h>

#include <conio.h>

void main()

{

    Printf(“hello World”)

   }

Output:

Hello World

 

 

Write a ‘C’ Program To Swap the values between two variable.

#include <stdio.h>

void main()

{

    int a,b,t// variable 't' for temporary use.

    printf("Enter values of 'A' and 'B' = ");

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

    t=a;

    a=b;

    b=t;

    printf("A=%d B=%d",a,b);

}

 Output

Enter values of 'A' and 'B' = 10

20

A=20  B=10.

 

 

 

Write a ‘C’ Program To addition and Subtraction of two numbers.

#include <stdio.h>

void main()

{

    int x,y,sum;

    printf("Enter Two Integers : ");

    scanf("%d%d",&x,&y);

    sum=x+y;

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

}

 Output:

Enter Two Integers : 12

54

Addition = 66

 

 

Write a ‘C’ To Multiplication and Division of two number.

#include <stdio.h>

#include <conio.h>

void main()

{

    int x,y,mul;

    float div;

    printf("Enter Two Integers : ");

    scanf("%d%d",&x,&y);

    mul=x*y;

    div=x/y;

    printf("\nMultiplication= %d\nDivision= %f",mul,div);

}

Output:

Enter Two Integers :100

10

Multiplication = 1000

Division = 10.000000

 

 

 

Write a ‘C’ to calculate area and perimeter of circle from user input radius.

#include <stdio.h>

#include <conio.h>

void main()

{

    int r;

    float area,perimeter;

    printf("Enter The Radius of Circle : ");

    scanf("%d",&r);

    area=3.14*r*r;

    perimeter=2*3.14*r;

    printf("\nArea =%f\nPerimeter=%f",area,perimeter);

}

Output

Enter The Radius of Circle :3

Area = 28.26000

Perimeter = 18.840000

 

 

Write a ‘C’ to calculate Sum and Average by reading 3 integer from user input.

#include <stdio.h>

#include <conio.h>

void main()

{

    int x,y,z,sum;

    float avg;

    printf("Enter Three Integers : ");

    scanf("%d%d%d",&x,&y,&z);

    sum=x+y+z;

    avg=sum/3.0; //3.0 to store float value

    printf("\nSum =%d\nAverage =%f",sum,avg);

}

Output:

Enter Three Integers : 10

20

30

Sum = 60

Average = 20.000000

 

 

Write a ‘C’ to read Celsius from user input and convert it into Fahrenheit.

#include <stdio.h>

#include <conio.h>

void main()

{

    float c,f;

    printf("Enter Temperature in Celsius : ");

    scanf("%f",&c);

    f=c*9/5+32;

    printf("\nFahrenheit = %f",f);

}

Output:

Enter Temperature in Celsius : 40

Fahrenheit = 104.00000

 

 

Write a ‘C’ to checked number entered by user is Positive or Negative.

#include <stdio.h>

#include <conio.h>

void main()

{

    int x;

    printf("Enter The Number : ");

    scanf("%d",&x);

    if(x>0)

    {

        printf("\n%d is Positive Integer  ",x);            

    }

    if(x<0)

    {

        printf("\n%d is Negative Integer ",x);            

    }

}

Output:

Enter The Number :554

544 is Positive Integer

 

Write a ‘C’ to find greatest number among entered 2 input value 

#include <stdio.h>

#include <conio.h>

void main()

{

    int x,y;

    printf("Enter Two Number : ");

    scanf("%d%d",&x,&y);

    if(x>y)

    {

        printf("\n%d is Greatest Number ",x);            

    }

    if(x<y)

    {

        printf("\n%d is Greatest Number ",y);            

    }

}

Output:

Enter Two Number : 765

698

765 is Greatest Number

 

 

 

 To Print Appropriate Message

If Pressed…

Message

A

Excellent

B

Very Good

C

Fair

D

Poor

 

 

#include <stdio.h>

#include <conio.h>

void main()

{

    char c;

    printf("Enter The Character : ");

    scanf("%c",&c);

    if(c=='A')

    {

        printf("\nExcellent");

    }

    if(c=='B')

    {

        printf("\nVery Good");

    }

    if(c=='C')

    {

        printf("\nFair");

    }

    if(c=='D')

    {

        printf("\nPoor");

           }

}

Output:

Enter The Character : B

Very Good




































Write a ‘C’ to determine even or Odd integers by user input

#include<stdio.h>

#include <conio.h>

void main()

{

    int n=2;

    printf("Enter The Number : ");

    scanf("%d",&n);

    if(n%2==0)

    {

        printf("\n%d is Even Number",n);

    }

    else

    {

        printf("\n%d is odd number",n);

    }

}

Output:

Enter The Number : 7

7 is odd number


Write a ‘C’ to check complete divisibility of number entered by user.

#include<stdio.h>

void main()

{

    int n,div;

    printf("\nEnter The Number : ");

    scanf("%d",&n);

    printf("\nEnter The Divisor : ");

    scanf("%d",&div);

    if(n%div==0)

    {

        printf("\n%d is completely divisible by %d",n,div);

    }

    else

    {

        printf("\n%d is not completely divisible by %d",n,div);

    }

}

Output:

Enter The Number : 345

Enter The Divisor : 13

345 is not completely divisible by 13

 

Write a ‘C’ to  determine the character entered is vowel or not

#include<stdio.h>

#include <conio.h>

void main()

{

    char c;

    printf("\nEnter The Alphabet : ");

    scanf("%c",&c);

    if(c==’A’ || c==’E’ || c==’I’ || c==’O’ || c==’U’//Used Logical ‘OR’

    {

        printf("\n%c is vowel",c);

    }

    else

    {

        printf("\n%c is not vowel”,c);

    }

}

Output:

Enter The Alphabet : I

I is vowel

 

 

To read age and print message

Age

Message

Less than 18

Children

18-60

Young

Above 60

Old

 

 Write a ‘C’ to read from user input and print message.

#include<stdio.h>

#include <conio.h>

void main()

{

    int age;

    printf("\nEnter The age : ");

    scanf("%d",&age);

    if(age<18)

    {

        printf("\nYou are children");

    }

    else if(age>=18 && age<60)

    {

        printf("\nYou are Young”);

    }

    else if(age>=60 && age<=110)

    {

        printf("\nYou are Old");

    }

    else

    {

        printf("\nInvalid Age");

    }

}

Output:

Enter The age : 45

You are Younger





































To read marks and print message

Marks

Message

Less than 40

Failed

40-60

Pass

60-80

First Class

80-100

Distinction

Any Other

Invalid Marks Input

 

  Write a ‘C’ to print grade by user input marks.

#include<stdio.h>

#include <conio.h>

void main()

{

    int m;

    printf("\nEnter The Marks : ");

    scanf("%d",&m);

    if(m<40)

    {

        printf("\nFailed");

    }

    else if(m>=40 && m<60//Used Logical ‘AND’

    {

        printf("\nPass);

    }

    else if(m>=60 && m<=80)

    {

        printf("\nFirst Class");

    }

    else if(m>=80 && m<=100)

    {

        printf("\nDistinction");

    }

    else

    {

        printf("\nInvalid Marks Input");

    }

}

Output:

Enter The Marks : 75

First Class







































 

 

  

Write a ‘C’ to read integers and print largest among three integers.

#include<stdio.h>

#include <conio.h>

void main()

{

    int x,y,z;

    printf("\nEnter Three Integers : ");

    scanf("%d%d%d",&x,&y,&z);

    if(x>y && x>z)

    {

        printf("\n%d is greatest number",x);

    }

    else if(y>z)

    {

        printf("\n%d is greatest number”,y);

    }

    else

    {

        printf("\n%d is greatest number",z);

    }

}

Output:

Enter Three Integers : 45

15

65

65 is greatest number.

 

 

 Write a ‘C’ to read character from user and print if it is vowel or not.

#include<stdio.h>

#include <conio.h>

void main()

{

    char c;

    printf("\nEnter The Character : ");

    scanf("%c",&c);

    switch(c)

    {

        case ‘a’:

        case ‘A’:printf(“\n%c is a vowel”,c);break;

        case ‘e’:

        case ‘E’:printf(“\n%c is a vowel”,c);break;

        case ‘i’:

        case ‘I’:printf(“\n%c is a vowel”,c);break;

        case ‘o’:

        case ‘O’:printf(“\n%c is a vowel”,c);break;

        case ‘u’:

        case ‘U’:printf(“\n%c is a vowel”,c);break;

        default :printf(“\n%c is not a vowel”,c);

    }

}

Output:

Enter The Character : Z

Z is not a vowel.


  Write a ‘C’ to read integer from user and perform operation according to number.

#include<stdio.h>

void main()

{

    int n,x;

    printf("\nEnter 1 or 2 : ");

    scanf("%d",&n);

    x=(n==1)?10:20;

    printf("\nX=%d”,x);

}

Output:

Enter 1 or 2 : 1

X=10

 

 

 


 

 

 

 

 

 






Write a ‘C’ to print Hello world ten times using for loop.

#include<stdio.h>

void main()

{

    int i;

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

    {

        printf("\nHello World");

    }

}

Output:

Hello World

Hello World

Hello World

Hello World

Hello World

Hello World

Hello World

Hello World

Hello World

Hello World

 





 

 

 

 

Write a ‘C’ to print number 1 to 10 using for loop

#include<stdio.h>

void main()

{

    int i;

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

    {

        printf("\n %d",i);

    }

}

Output:

1

2

3

4

5

6

7

8

9

10



















 

 

 

 

 

Write a ‘C’ to print number 10 to 1 using for loop

#include<stdio.h>

void main()

{

    int i;

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

    {

        printf("\n %d",i);

    }

}

Output:

10

9

8

7

6

5

4

3

2

1












































Write a c program to print Multiplication table of given number

#include<stdio.h>

void main()

{

    int i,n,m;

    printf(“Enter The Number : “);

    scanf(“%d“,&n);

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

    {

        m=i*n;

        printf("\n %d",m);

    }

}

Output:

Enter The Number : 25

25

50

75

100

125

150

200

225

250





















Write a c program to print sum of first ten numbers using for loop

#include<stdio.h>

void main()

{

    int i,sum=0; //sum contains garbage value

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

    {

        sum=i+sum;

    }

        printf("\n Sum of first Ten Digit numbers =%d",sum);

}

Output:

Sum of first ten digit number = 55

 

 

 

 

 

 

 

 

 

 

 

 

 



Write a C program to read integer from user then calculate and print its factorial using for loop.

 

#include<stdio.h>

void main()

{

    int i,n,fact=1; //’fact’ contains garbage value. to perform multiplication it is assigned to 1

    printf(“\nEnter the number : ”);

    scanf(“%d”,&n);

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

    {

        fact=fact*i;

    }

        printf("\n%d! =%d",n,fact);

}

Output:

Enter the number : 6

6! = 720

 

 

Write a c program to read integer from user then calculate and print its power using for loop. 

#include<stdio.h>

void main()

{

    int i,x,y,pow=1;

    printf("\n Enter the Base : ");

    scanf("%d",&x);

    printf("\n Enter the Index : ");

    scanf("%d",&y);

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

    {

        pow=pow*x;

    }

    printf("\n %d^%d = %d",x,y,pow);

}

Output:

Enter the Base : 2

Enter the Index : 5

2^5 = 32

 

 

 

 

 

 

 

 

 

 

 

 

 

 








Write a C program to read integer from user and calculate if it is prime number or Not.

#include<stdio.h>

void main()

{

    int n,i,c=0;

    printf("\n Enter the Number : ");

    scanf("%d",&n);

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

    {

        if(n%i==0)

        {

            c++;

        }

    }

    if(c==0)

    {

        printf("\n %d is Prime Number",n);

    }

    else

    {

        printf("\n %d is Not Prime Number",n);

    }

 }

Output:

Enter the Number : 4

4os not Prime Number

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Write a C program To print Fibonacci series.

#include<stdio.h>

void main()

{

    int i,x=0,y=1,s;

    printf("\nFibonacci Series : ");

    printf("\n%d\t%d",x,y);

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

    {

        s=x+y;

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

        x=y;

        y=s;

    }

}

Output:

Fibonacci Series :

0     1      1       2      3

610   978   1597   2584   4181

 

 

 

 

 

 

 

 

 

 

 

Write A C program to read from number from user and then calculate sum of digits in it using while loop.

#include<stdio.h>

void main()

{

    int n,r,sum=0;

    printf("\nEnter the Numbers : ");

    scanf("%d",&n);

    while(n!=0)

    {

        r=n%10;

        sum=sum+r;

        n=n/10;

    }

    printf("\nSum of Digits of Number = %d",sum);  

}

Output:

Enter the Numbers :  444

Sum of Digit of Number = 12


 

 






























Write a C program to read number  from user and then calculate occurrences of digit using while loop.

#include<stdio.h>

void main()

{

    int n,r,s,c=0;

    printf("\nEnter the Numbers : ");

    scanf("%d",&n);

    printf("\nEnter the Digit to Count : ");

    scanf("%d",&s);

    while(n!=0)

    {

        r=n%10;

        if(r==s)

        {

            c++;

        }

        n=n/10;

    }

    printf("\n%d Occurs %d times",s,c);  

}

Output:

Enter the Numbers : 112311

Enter the Digit to Count : 1

1 Occurs 4 time

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 









Write a C program to read number from user and then calculate reverse of number using while loop.

#include<stdio.h>

void main()

{

    int n,r,rev=0;

    printf("\nEnter the Number : ");

    scanf("%d",&n);

    while(n!=0)

    {

        r=n%10;

        rev=rev*10+r;

        n=n/10;

    }

    printf("\nReverse Number = %d",rev);  

}

Output:

Enter the Number : 1234

Reverse Number = 4321

 

  




















 Write a C program to read number from user and then print its multiplication table using do while loop.

#include<stdio.h>

void main()

{

    int n,i=1,m;

    printf("\nEnter the Number : ");

    scanf("%d",&n);

    printf("\nMultiplication Table of %d : ",n);

    do

    {

        m=n*i;

        printf(“\n%d,m);

        i++;

    }while(i<=10);

}

Output:

Enter the Number : 12

Multiplication Table of 12 :

12

24

36

48

60

72

84

96

108

120
































Other is coming Soon 


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 



Recently

All C program

Write a C program to print ‘Hello World’ on screen . #include < stdio.h > #include < conio.h > void  m...