All the Notes in one Place. Download our Official App from Google Play.

C Programs Page 1

C Programs Page 1

C Programs Page 1
To view other topics related to Computer. Click Here.

Program using if-else statement to find the largest number in the given three numbers (If Else Statement)

Main()

{

int n,m,k;

printf(“Enter three numbers\n”);

scanf(“%d%d%d”,&n,&m,&k);

if((n>m)&&(n>k))

printf(“Greater no=%d\n”,n);

else

if(m>n&&m>k)

printf(“Greater no=%d\n”,m);

else

if(k>n&& k>m)

printf(“Greater no =%d\n”,k);

getch();

}

Determine whether the number is positive or negative or zero(If Statement)

Main()

{

int num;

printf(“Enter the number\n”);

scanf(“%d”,&num);

if(num >0)

printf(“num is pocitve =%d\n”,num);

if(num<0)

printf(“num is negative =%d\n”,num);

if(num=0)

printf(“num is zero =%d\n”,num);

getch();

}

Write a program to input the age of a person in years. Convert the age into months and days and print the result in the center of the screen

Main()

{

long int age,mon,days;

clrscr();

printf(“Enter age in years ?”);

scanf(“%d”,& age );

mon=age*12;

days=age*365;

gotoxy(35,12);

printf(“Age in months = %d”, mon);

gotoxy(35,13);

printf(“Age in days =%d”,days);

getch();

}

Write a program to compute the area of a triangle

main()

{

int a,b,c;

double area, s;

a=115;

b=163;

c=210;

s=(a+b+c)/2..0;

area=sqrt (s* (s-a)* (s-b)* (s-c);

clrscr ();

printf( “/n Calculate Area= %f”,area);

}

Program to declare and initialize data into string type variables name & city and print these variables on the screen by using the printf function

main( )

{

char name [15]=”wasim javed”;

char city[25]=”D-I-khan”;

clrdcr ();

printf(“ Name: % s/n”,name);

printf(“city: % s/n”,city);

getch();

}

Write a program to input a string by using “gets” function and then print it on the screen by using the “puts” function

main( )

{

char str[20];

clrscr ();

puts (“Enter a string ? ”);

gets (str);

puts( The string is :”);

puts(str);

getch ();

}

Kinetic Energy of a body of mass “m” moving with velocity “v” input the mass and velocity of a body during program execution(Kinetic Energy=1/2 mv^2)

main( )

{

float m,v,ke;

printf(“/n enter value of m,v”);

scanf(“%f % f”,&m,&v);

ke=1/2*m*v*v;

printf(

‘/n KR= %f “,ke);

}

Post a Comment

Previous Post Next Post