Вы находитесь на странице: 1из 16

#include <stdio.

h>print the address of a variable

int main(void)

// declare variables

int a;

float b;

char c;

printf("Address of a: %p\n", &a);

printf("Address of b: %p\n", &b);

printf("Address of c: %p\n", &c);

return 0;

/* C program to print Hello World! */

#include <stdio.h>

int main()

printf("Hello World!");

return 0;

#include<stdio.h>
int main()

int a,b,sub;

//Read value of a

printf("Enter the first no.: ");

scanf("%d",&a);

//Read value of b

printf("Enter the second no.: ");

scanf("%d",&b);

//formula of subtraction

sub= a-b;

printf("subtract is = %d\n", sub);

return 0;

/* c program find sum and average of two numbers*/

#include <stdio.h>

int main()

int a,b,sum;
float avg;

printf("Enter first number :");

scanf("%d",&a);

printf("Enter second number :");

scanf("%d",&b);

sum=a+b;

avg= (float)(a+b)/2;

printf("\nSum of %d and %d is = %d",a,b,sum);

printf("\nAverage of %d and %d is = %f",a,b,avg);

return 0;

Program to get ASCII of a character in C

#include <stdio.h>

int main()

char ch;

//input character

printf("Enter the character: ");

scanf("%c",&ch);
printf("ASCII is = %d\n", ch);

return 0;

Program to find quotient and remainder in C

#include <stdio.h>

int main()

int dividend, divisor;

int quotient, remainder;

printf("Enter dividend: ");

scanf("%d",&dividend);

printf("Enter divisor: ");

scanf("%d",&divisor);

quotient= dividend/divisor;

remainder= dividend%divisor;

printf("quotient: %d, remainder: %d\n",quotient,remainder);


return 0;

C program for Simple Interest

/* c program to calculate simple interest*/

#include <stdio.h>

int main()

float amount,rate,time,si;

printf("Enter principal (Amount) :");

scanf("%f",&amount);

printf("Enter rate :");

scanf("%f",&rate);

printf("Enter time (in years) :");

scanf("%f",&time);

si=(amount*rate*time)/100;

printf("\nSimple Interest is = %f",si);

return 0;

}
C program to read marks and print total and percentage

#include<stdio.h>

int main()

int science;

int math;

int english;

int total;

float per;

science = 50;

math = 90;

english = 40;

//you can take input from user instead of these values

//calculating total

total= science + math + english;

//calculating percentage

per= (float) total*100/300;

printf("Total Marks: %d\n",total);

printf("Percentage is: %.2f\n",per);


/

return 0;

/* c program to calculate salary of an employee with name */

#include <stdio.h>

int main()

char name[30];

float basic, hra, da, pf, gross;

printf("Enter name: ");

gets(name);

printf("Enter Basic Salary: ");

scanf("%f",&basic);

printf("Enter HRA: ");

scanf("%f",&hra);

printf("Enter D.A.: ");

scanf("%f",&da);

/*pf automatic calculated 12%*/

pf= (basic*12)/100;
gross=basic+da+hra+pf;

printf("\nName: %s \nBASIC: %f \nHRA: %f \nDA: %f \nPF: %f \n***GROSS SALARY: %f


***",name,basic,hra,da,pf,gross);

return 0;

/*C program to print size of variables using sizeof() operator.*/

#include <stdio.h>

int main()

char a ='A';

int b =120;

float c =123.0f;

double d =1222.90;

char str[] ="Hello";

printf("\nSize of a: %d",sizeof(a));

printf("\nSize of b: %d",sizeof(b));

printf("\nSize of c: %d",sizeof(c));

printf("\nSize of d: %d",sizeof(d));

printf("\nSize of str: %d",sizeof(str));


return 0;

/*C program to demonstrate examples of escape sequences.*/

#include <stdio.h>

int main()

printf("Hello\nWorld!"); //use of \n

printf("\nHello\tWorld!"); // use of \t

printf("\n\"Hello World!\""); //use of \"

printf("\nHello\bWorld!"); //use of \b

return 0;

/*C program to find area and perimeter of circle.*/

#include <stdio.h>

#define PI 3.14f

int main()
{

float rad,area, perm;

printf("Enter radius of circle: ");

scanf("%f",&rad);

area=PI*rad*rad;

perm=2*PI*rad;

printf("Area of circle: %f \nPerimeter of circle: %f\n",area,perm);

return 0;

/*C program to find area of a rectangle.*/

#include <stdio.h>

int main()

float l,b,area;

printf("Enter the value of length: ");

scanf("%f",&l);

printf("Enter the value of breadth: ");

scanf("%f",&b);
area=l*b;

printf("Area of rectangle: %f\n",area);

return 0;

C program to convert feet to inches

#include<stdio.h>

int main()

int feet,inches;

printf("Enter the value of feet: ");

scanf("%d",&feet);

//converting into inches

inches=feet*12;

printf("Total inches will be: %d\n",inches);

return 0;

/*C - Print ASCII value of entered character.*/


#include <stdio.h>

int main(){

char ch;

int asciiValue;

printf("Enter any character: ");

scanf("%c",&ch);

asciiValue=(int)ch;

printf("ASCII value of character: %c is: %d\n",ch,asciiValue);

Write a C program to evaluate the net salary of an employee

#include <stdio.h>

//main program

int main()

//variable to store values

float basic, da, hra, ta, others;

float pf,it;

float net_salary;
//input required fields

printf("Enter Basic Salary ($): ");

scanf("%f",&basic);

printf("Enter HRA ($): ");

scanf("%f",&hra);

printf("Enter TA ($): ");

scanf("%f",&ta);

printf("Enter others ($): ");

scanf("%f",&others);

//calculate DA 12% of Basic Salary

da = (basic*12)/100;

//calculate PF 14% of Basic salary

pf = (basic*14)/100;

//calculate IT, 15% of Basic salary

it = (basic*15)/100;

//calculate net salary

net_salary = basic + da + hra + ta + others - (pf+it);

//printing Net salary

printf("Net Salary is: $ %.02f\n",net_salary);

return 0;

}
Program to swap numbers without using temporary variable in C

#include <stdio.h>

int main()

//variable declarations

int a,b;

//Input values

printf("Enter the value of a: ");

scanf("%d",&a);

printf("Enter the value of b: ");

scanf("%d",&b);

//Numbers before swapping

printf("Before swapping... a: %d, b: %d\n",a,b);

//swapping numbers

a = a+b;//step 1

b = a-b; //step 2

a = a-b; //step 3

//Numbers after swapping

printf("After swapping... a: %d, b: %d\n",a,b);


return 0;

C program to find sum of all numbers from 0 to N

#include <stdio.h>

int main(void) {

int n, sum;

//input value of n

printf("Enter the value of n: ");

scanf("%d", &n);

//initialize sum with 0

sum =0;

//use formula to get the sum from 0 to n

sum = n*(n+1)/2;

//print sum

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

return 0;

Вам также может понравиться