0% found this document useful (0 votes)
25 views9 pages

C Programs

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views9 pages

C Programs

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

1)Printf()

#include <stdio.h>

int main()

printf("C Programming");

return 0;

2) Example 2: Integer Output

#include <stdio.h>

int main()

int testInteger = 5;

printf("Number = %d", testInteger);

return 0;

3) Example 3: float and double Output

#include <stdio.h>

int main()

{
float number1 = 13.5;

double number2 = 12.4;

printf("number1 = %f\n", number1);

printf("number2 = %lf", number2);

return 0;

4) Example 4: Print Characters

#include <stdio.h>

int main()

char chr = 'a';

printf("character = %c", chr);

return 0;

5) Example 5: Integer Input/Output

#include <stdio.h>

int main()
{

int testInteger;

printf("Enter an integer: ");

scanf("%d", &testInteger);

printf("Number = %d",testInteger);

return 0;

Example 6: Float and Double Input/Output

#include <stdio.h>

int main()

float num1;

double num2;

printf("Enter a number: ");

scanf("%f", &num1);

printf("Enter another number: ");

scanf("%lf", &num2);
printf("num1 = %f\n", num1);

printf("num2 = %lf", num2);

return 0;

Example 7: C Character I/O

#include <stdio.h>

int main()

char chr;

printf("Enter a character: ");

scanf("%c",&chr);

printf("You entered %c.", chr);

return 0;

Example 8: ASCII Value

#include <stdio.h>
int main()

char chr;

printf("Enter a character: ");

scanf("%c", &chr);

// When %c is used, a character is displayed

printf("You entered %c.\n",chr);

// When %d is used, ASCII value is displayed

printf("ASCII value is %d.", chr);

return 0;

I/O Multiple Values

#include <stdio.h>

int main()

int a;
float b;

printf("Enter integer and then a float: ");

// Taking multiple inputs

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

printf("You entered %d and %f", a, b);

return 0;

}
1)algorithm
step 1:Declare a variable a,b,c and avg as int;
Step 2:Read two numbers a,b and c;
Step 3:avg=(a+b+c)/3;
Step 4:Print avg;

Flow chart
#include<stdio.h>

int main() {

int a, b, c, avg; //Declaring the variables


printf("Enter three variables:\n");
printf("a:");
scanf("%d", & a); //Reading Variable a
printf("b:");
scanf("%d", & b); //Reading Variable b
printf("c:");
scanf("%d", & c); //Reading Variable c
avg = (a + b + c) / 3;
printf("\nAverage of %d,%d and %d is %d", a, b, c, avg);

2)conversion of fahrenheit to Celsius


#include <stdio.h>

int main() {
// declare variables
double f, c;
//take input in fahrenheit
printf("Enter the temperature in Fahrenheit = ");
scanf("%lf", & f);

//convert fahrenheit and c


c = 5 * (f - 32) / 9;

printf("Temperature is %lf in centigrade When %lf in


fahrenheit.", c, f);
return 0;
}

3)simple interest calculation

Algorithm to find simple interest:


1. Start the program.
2. Read Principal amount, rate of interest and time period.
3. Calculate interest by using the formula.

4. Print the simple interest.


5. Stop the program.
The flowchart for simple interest is attached below.
Algorithm to find simple interest:
1. Start the program.
2. Read Principal amount, rate of interest and time period.
3. Calculate interest by using the formula.

4. Print the simple interest.


5. Stop the program.
The flowchart for simple interest is attached below.

#include <stdio.h>

int main() {

double P = 20000.0; // principal amount


double R = 7.5; // 7.5 % interest rate
double T = 4; // For 4 years

double interest = ( P * R * T ) / 100 ;


printf("interest is %0.2f ", interest);

return 0;
}

You might also like