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

Question Number# 1

Write a Program to check the sizes of the main C data type on


your machine.
Program
#include <stdio.h>
#include <conio.h>
int main ()
{
char a;
int b;
long c;
float d;
double e;
long double f;
printf("No. of byts taken by character=");
printf("%d", sizeof(a));
printf("\nNo. of byts taken by integer=");
printf("%d", sizeof(b));
printf("\nNo. of byts taken by long=");
printf("%d", sizeof(c));
printf("\nNo. of byts taken by float=");
printf("%d", sizeof(d));
printf("\nNo. of byts taken by double=");
printf("%d", sizeof(e));
printf("\nNo. of byts taken by long double=");
printf("%d", sizeof(f));
getch();
}

Question Number# 2
Write a program to illustrate whether standard library function
truncates or round when printing out a floating point Numbers.
Program
#include <stdio.h>
#include <conio.h>
int main ()
{
int r;
printf("enter your number\n");
scanf("%d",&r);
printf("The round value is\n");
printf("%d",r);

getch();
Question Number# 3
Write o program to check what the fillowing code segment
output and explain the results.
Char c;
printf("sizeof(c) = %d\n",sizeof(c));
printf("sizeof(a) = %d\n",sizeof('a'));
printf("sizeof(c='a') = %d\n",sizeof(c='a'));
Program
#include <stdio.h>
#include <conio.h>
int main ()
{
char c;
printf("sizeof(c) = %d\n",sizeof(c));
printf("sizeof(a) = %d\n",sizeof('a'));
printf("sizeof(c='a') = %d\n",sizeof(c='a'));
getch();
}

Result
printf("sizeof(c) = %d\n",sizeof(c));
printf("sizeof(a) = %d\n",sizeof('a'));
printf("sizeof(c='a') = %d\n",sizeof(c='a'));

Question Number# 4
Run the “Hello Word” program on your system. Experiment with
leaving out part of the program, to see what error message to
get?

Program
#include <stdio.h>
#include <conio.h>
int main ()
{
char c;
printf("Hello world");

}
Error
If (;)is missing then syntax error before ‘getch’ occure.
Question Number# 5

Experiment to find out what happens when print’s argument string


contains\where c is some character not listed above.
Program
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
void main()
{
clrscr();
int q;
printf("Enter Value = %c" ,q);
getch();
}

Question Number# 6

Write a Program which read a character from the keyboard and


writes out its ASCII Representation.
Program
#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
int a;
printf("Enter a number(0-9): ");
scanf("%d", &a);
if(a>9)
{
printf("you enter invalid choice");
printf("\nEnter a number(0-9): ");
scanf("%d", &a);
}
switch(a)
{
case 0:
printf("ASCII CHARACTER OF 0=48");
break;
case 1:
printf("ASCII CHARACTER OF 1=49");
break;
case 2:
printf("ASCII CHARACTER OF 2=50");
break;
case 3:
printf("ASCII CHARACTER OF 3=51");
break;
case 4:
printf("ASCII CHARACTER OF 4=52");
break;
case 5:
printf("ASCII CHARACTER OF 5=53");
break;
case 6:
printf("ASCII CHARACTER OF 6=54");
break;
case 7:
printf("ASCII CHARACTER OF 7=55");
break;
case 8:
printf("ASCII CHARACTER OF 8=56");
break;
case 9:
printf("ASCII CHARACTER OF 9=57");
break;
}

getch();
}

Question Number# 7
In an integer from the keyboard and print out its character
representation Make certain you carry out appropriate bound/error
checking.
Program
#include <stdio.h>
#include <conio.h>
int main ()
{
char a;
scanf("%c",&a);
if(a==a)
printf("65");
if(a==b)
printf("66");
getch();
}

Question Number# 8
Write a program to read Fahrenheit tempture and print them in
Celsius. The formula is C=(5/9)(F-32) use variable of type double
in your program.
Program
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
main()
{

double f,c;

printf ("Enter temperature in Farehnihiet:");


scanf("%d",f);

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

printf("The temperature in Fahrenheit is:%d ", c);


getch();
}

Question Number# 9
Write a program that reads in the radius of a circle and prints the
circle’s diameters, cumference and area. Use the value 3.14159
for”pi”
Program
#include<stdio.h>
#include<conio.h>
void main()

{
clrscr();
float a;
float r;
float c;
float d;
float pi=3.141593;
printf("ENTER RADIUS= ");
scanf("%f", &r);
a=2*pi*r*r;
c=2*pi*r;
d=2*r;
printf("\n\tArea: %f",a);
printf("\n\tCircumference: %f ",c);
printf("\n\tDiameter:%f",d);
getch()
}

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