parajulirajesh.com.np

Rajesh Parajuli

C Programming

C is a procedural general purpose programming language that was developed by Dennis Ritchie at the Bell Laboratories in 1972 for the purpose of developing Unix Operating System.

The Structure of C program is:

#include<stdio.h> //header file
int main() // Main function or main method
{
int a; // declaration of variable
printf(“enter a number: “);// display
scanf(“%d”,&a); //read by compiler
printf(“entered number is %d”,a); //display entered number
return 0 // int main does not return null value

Datatypes refers to the type of data. There are various types of data used in c programming. some of them are:

Datatypes              keywords      format specifier        example
Integer                     int                  %d                                int a=10;
Floating point        float                %f                                float a=10.5;
Double                   double             %1f                             double a=10.005;
String                     char                 %s                               char a=”helloword”;
Character              char                 %c                               char a=’h’;

Write a c program to calculate Simple Interest by declaring value

#include<stdio.h>
int main()
{
int p=4000,t=2,r=3,SI;
SI=(p*t*r)/100;
printf(“the simple interest is %d”,SI);
return 0;
}

Write a c program to calculate Simple Interest by getting values from user.

#include<stdio.h>
int main()
{
int p,t,r,SI;
printf(“enter the principal: “);
scanf(“%d”,&p);
printf(“enter the time: “);
scanf(“%d”,&t);
printf(“enter the rate: “);
scanf(“%d”,&r);
SI=(p*t*r)/100;
printf(“the simple interest is %d”,SI);
return 0;
}

Write a program in c language to ask length, breadth, and height and display the volume of the box.

#include<stdio.h>
int main()
{
int L,b,h,volume;
printf(“enter the length: “);
scanf(“%d”,&L);
printf(“enter the breadh: “);
scanf(“%d”,&b);
printf(“enter the height: “);
scanf(“%d”,&h);
volume=L*b*h;
printf(“the simple interest is %d”,volume);
return 0;
}

Write a program in c language that ask for a number and checks whether it is odd or even.

#include<stdio.h>
int main()
{
int n;
printf(“enter the number: “);
scanf(“%d”,&n);
if(n%2==0)
  {
     printf(“%d is even number”,n);
   }
else
   {
     printf(“%d is odd number”,n);
    }
return 0;
}

Write a C program to find the sum of first 10 natural numbers.

#include<stdio.h>
int main()
{
int i,sum=0;
for(i=1;i<=10;i++)
{
sum=sum+i;
}
printf(“the sum of the first natural number is %d”,sum);
return 0;
}

Write a C program to display the first 10 odd numbers.
 
#include <stdio.h>
int main() {
    int i;
    printf(“The first 10 odd numbers are:\n”);
    for(i = 1; i <= 20; i=i+2) 
{
        printf(“%d “, i);
    }
    printf(“\n”);
    return 0;
}

Write a C program to find the factorial of a given number?

#include<stdio.h>
int main()
{
int fact=1,i,num;
printf(“enter the number to find factorial: “);
scanf(“%d”,&num);
if(num<0)
{
printf(“negative number factorial is not exists”);
}
else
{
for(i=1;i<=num;i++)
{
fact=fact*i;
}
printf(“factorial of a number is: %d”,fact);
}
return 0;
}
Scroll to Top

Rajesh Parajuli.

Services: