In this program we use the function 'getchar' to read a character. The getchar function may be called successively to read the characters contained in a line of text.Warning: The getchar() function accepts any character keyed in. This includes RETURN and TAB.#inlcude <stdio.h>main(){char answer;printf("Would you like to know my name ?\n");printf("Type Y for YES and N for NO: ");answer = getchar(); /*...Reading a Character...*/if(answer == 'Y' || answer == 'y')printf("\n\n My name is Bond...,JAMES BOND \n");elseprint("\n\n...
Write a program to read the price of an item in decimal form and print the output in paise.
The program is to read the price of an item in decimal form like 15.95 and print the output in paise like 1595 paise. #include<stdio.h> main() { float n; int sum; printf("Enter the value in decimal "); scanf("%f",&n); sum = 100 * n; printf(" \nThe paise is %d.", sum); getch(); return 0;}Output :Enter the value in decimal 15.95The paise is 15...
Write a program to demonstrate Temperature Conversion Problem
The program presented converts the given temperature in Fahrenheit to Celsius using the following conversion formula: F - 32 C = ---------------- 1.8#include "stdio.h"#define F_LOW 0#define F_MAX 250#define STEP 25main(){typedef float REAL;REAL fahrenheit, celsius;fahrenheit = F_LOW;printf("Fahrenheit Celsius\n\n");while( fahrenheit <= F_MAX ){celsius = ( fahrenheit - 32.0)/1.8;printf("%5.1f %7.2f\n", fahrenheit, celsius);fahrenheit = fahrenheit...
Write a program to calculate Average of Numbers.
A program to calculate the average of a set of N numbers ...#include <stdio.h>#define N 10 main(){int count; float sum, average, number; sum =0; count =0; while( count <> { scanf( "%f",&number); sum = sum + number; count = count + 1; } average = sum/N ; printf("N = %d Sum = %f", N, sum); printf(" Average = %f", average); return 0; }Output:12.34.671.4273.674.082.24.258.21N = 10 Sum = 38.799999 Average = 3.880...
Write a program to demonstrate the use of scanf function.
Though I've already explained about 'scanf' function in my previous examples. I would like to add some of point here. The first executable statement is of-course the 'printf' function. Which is also know as 'prompt message'. Some compilers permit the use of the 'prompt message' as a part of control string in scanf, like scanf("Enter a number %d", &number);#include <stdio.h>main(){ int number; printf("Enter an integer number\n"); scanf("%d", &number); if( number...
Witer a program to Represent integer constants.
We rarely use octal and hexadecimal numbers in programming. The largest integer value that can be stored in machine-dependent. It is 32767 on 16-bit machines and 2,147,483,647 on 32-bit machines.#include <stdio.h>main(){printf("Integer values\n");printf("%d%d%d\n", 32767,32767+1,32767+10);printf("\n");printf("Long integer values\n\n");printf("%ld%ld%ld\n", 32767L, 32767L+1L, 32767L+10L);return 0;}Output:Integer values32767 -32768 -32759Long integer values32767 32768 32...
Write a program to output the Multiplication table.
The problem is to program a multiplication table. The program is....#include <stdio.h>main(){int i,n,x;printf("Enter the value for n: ");scanf("%d", &n);for(i=1; i<=10; ++i){x = n * i ;printf("%d * %d = %d\n", n,i,x);}getch();return 0;}The program reads the value of "n" at the run time using the predefine function "scanf".Output:Enter the value for n: 55 * 1 = 55 * 2 = 105 * 3 = 155 * 4 = 205 * 5 = 255 * 6 = 305 * 7 = 355 * 8 = 405 * 9 = 455 * 10 =...
Write a program to print your mailing address.
The program ask the programmer to print the mailing address in the following form: 1. First line: Name. 2. Second line: Door No, Street. 3. Third line: City, Pin Code.To display the out put in above formate we use newline character "\n". A newline character instructs the computer to go to the next(new) line. #include <stdio.h> main() { printf("Jubilant Organosys Limited\n"); printf("Nimbut Village, Nira R. S.\n"); printf("Pune-412102 \n"); return 0; }Output:Jubilant Organosys Limited,Nimbut...
Write a program using math funtion.
We often use standard mathematical funtions such as cos, sin, exp, etc. In this program we add a new header called #include"math.h" that instructs the compiler to link the specified mathematical function form the library. We shall see now the use of a mathematical function in a program.#include <stdio.h>#include <math.h>#define PI 3.1416#define MAX 180main(){int angle;float x,y;angle = 0;printf(" Angle Cos(angle)\n\n");while(angle <= MAX){x = (PI/MAX)*angle;y = cos(x);printf("%15d %13.4f\n", angle, y);angle...
Write a program using user-defined funtion.
The program uses a user-defined function. A function defined by the user is equivalent to a subroutine in FORTRAN or subprogram in BASIC.#include <stdio.h>main(){int a,b,c;a = 5;b = 10;c = mul(a,b);printf(" Multiplication of %d and %d is %d.", a,b,c);}mul(x,y)int p,x,y;{p = x*y;return(p);}The program will print the following output:Multiplication of 5 and 10 is ...
Write a program to calculater Interest rate.
The program calculates the value of money at the end of each year of investment assuming an interest rate of 11 percent and prints the year and the corresponding amount, in two columns.#include"stdio.h"#define PERIOD 10#define PRINCIPAL 5000.00main(){ int year; float amount, value, inrate; amount = PRINCIPAL; inrate = 0.11; year = 0; while(year <= PERIOD) { printf("%2d %8.2f\n", year, amount);...
Write a program to add two numbers.
This program performs addition on two numbers and displays the result.#include <stdio.h>main(){int number;float amount;number = 100;amount = 30.75 + 75.35;printf("%d\n", number);printf("%5.2f", amount);}This program when executed will produce following output:100106...
Hello World.......! in C
The beginning of programming in ' C '. The #include"stdio.h"is a standard I/O header file containing standard input and output functions and it is often required.
#include<stdio.h>
void main()
{
printf("Hello, World..........!");
}
Output :-
Hello, World............
Subscribe to:
Posts (Atom)