C Programs 1 /* PR1 */ main() { clrscr(); /* Clears the screen contents */ printf("We are three brothers: \n Shoni \n Cooki \n Mani"); printf("\n There are two kinds of break Softbreak \n and \r Hardbreak"); printf("\n Provide following \n name: \t class: \t roll no:"); printf("\a"); sleep(1); /* Stop the execution of program for given no of seconds */ printf("\n Did you hear a beep?"); sleep(5); } /* PR2 */ main() { clrscr(); /* Clears the screen contents */ printf("\n\t My name is tanveer and i am %d years old: ",45); printf("\n\t Temperature in the core of the sun is %ld degree celcius:",41000000); printf("\n\t The value of the PI is %.4f ",3.1415); printf("\n\t The character %c is pronounced as \'SEE\': ",'c'); printf("\n\t The character %c is pronounced as \'%s\' : ",'T',"TEE"); printf("\n\t The data type LONG can store uupto %e unsigned value: ",4294967295); sleep(5); /* Stop the execution of program for given no of seconds */ } Prepared by Tanveer Ahmed 6/6/22 1
C language programs for the students of BCS or computer languages. Coding is done with examples for convenience. reader can be able to understand main topics of C just in one night,
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
C Programs 1
/* PR1 */
main()
{
clrscr(); /* Clears the screen contents */
printf("We are three brothers: \n Shoni \n Cooki \n Mani");
printf("\n There are two kinds of break Softbreak \n and \r Hardbreak");
printf("\n Provide following \n name: \t class: \t roll no:");
printf("\a");
sleep(1); /* Stop the execution of program for given no of seconds */
printf("\n Did you hear a beep?");
sleep(5);
}
/* PR2 */
main()
{
clrscr(); /* Clears the screen contents */
printf("\n\t My name is tanveer and i am %d years old: ",45);
printf("\n\t Temperature in the core of the sun is %ld degree celcius:",41000000);
printf("\n\t The value of the PI is %.4f ",3.1415);
printf("\n\t The character %c is pronounced as \'SEE\': ",'c');
printf("\n\t The character %c is pronounced as \'%s\' : ",'T',"TEE");
printf("\n\t The data type LONG can store uupto %e unsigned value: ",4294967295);
sleep(5); /* Stop the execution of program for given no of seconds */
}
Prepared by Tanveer Ahmed 4/8/23 1
C Programs 2
/* PR3 */
main()
{
int x = 12, y = 6, z = 2;
clrscr(); /* Clears the screen contents */
printf("\n\t X = %d Y = %d Z = %d",x,y,z);
printf("\n\n\t The Division of X and Y is %d",x/y);
printf("\n\t The Product of X and Y is %d",x*y);
printf("\n\t The Remainder of X divided by Z is %d",x%z);
printf("\n\t The Addition of X and Y is %d",x+y);
printf("\n\t The Subtraction of X and Y is %d",x-y);
printf("\n\t An expression using more than one operators:");
printf("\n\t X * Y + Z = %d",x*y+z);
printf("\n\t Use of Parenthesis to change the priority of operators");
printf("\n\t X * (Y + Z) = %d",x*(y+z));
sleep(5); /* Stop the execution of program for given no of seconds */
}
Prepared by Tanveer Ahmed 4/8/23 2
C Programs 3
/* PR4 */
main()
{
int x, y;
clrscr(); /* Clears the screen contents */
printf("\n\t Enter two integers and see their relationship\n\t");
scanf("%d %d",&x,&y);
if(x == y)
printf("\n\t %d is equal to %d",x,y);
if(x != y)
printf("\n\t %d is not equal to %d",x,y);
if(x < y)
printf("\n\t %d is less than %d",x,y);
if(x > y)
printf("\n\t %d is greater than %d",x,y);
if(x <= y)
printf("\n\t %d is less than or equal to %d",x,y);
if(x >= y)
printf("\n\t %d is greater than or equal to %d",x,y);
sleep(5); /* Stop the execution of program for given no of seconds */
}
Prepared by Tanveer Ahmed 4/8/23 3
C Programs 4
/* PR5 */
main()
{
char x, y;
clrscr(); /* Clears the screen contents */
printf("\n\t Truth table for Logical AND, OR and NOT ");
printf("\n\t Enter two expression values for AND (T,F)\n\t");
scanf("%c,%c",&x,&y);
x = toupper(x);
y = toupper(y);
printf("\n\t AND \t OR \t NOT ");
if (x == 'T' && y == 'T')
printf("\n\t TRUE");
if (x == 'T' && y == 'F')
printf("\n\t FALSE");
if (x == 'F' && y == 'T')
printf("\n\t FALSE");
if(x == 'F' && y == 'F')
printf("\n\t FALSE");
getch(); /* Stop the execution of program for given no of seconds */
if (x == 'T' && y == 'T')
printf("\t TRUE");
if (x == 'T' && y == 'F')
printf("\t TRUE");
if (x == 'F' && y == 'T')
printf("\t TRUE");
if(x == 'F' && y == 'F')
printf("\t FALSE");
getch();
if (x == 'T')
printf("\t FALSE");
if (x == 'F')
printf("\t TRUE");
getch();
}
/* PR6 */
main()
{
int a = 2;
clrscr(); /* Clears the screen contents */
Prepared by Tanveer Ahmed 4/8/23 4
C Programs 5
printf("\n\t The value of memory variable a is %d \n\t",a);
printf(" and the address of memory variable a is %u ",&a);
getch(); /* It is used to read a character */
}
/* PR7 */
main()
{
int a;
clrscr(); /* Clears the screen contents */
a = 2;
printf("\n\t The value of a is %d",a);
++a;
printf("\n\t The Value of ++a is %d",a);
a++;
printf("\n\t The Value of a++ is %d",a);
a--;
printf("\n\t The Value of a++ is %d",a);
--a;
printf("\n\t The Value of a++ is %d",a);
getch(); /* It is used to read a character */
}
Prepared by Tanveer Ahmed 4/8/23 5
C Programs 6
/* PR8 */
main()
{
int a;
clrscr(); /* Clears the screen contents */
a = 2;
printf("\n\t The value of a is %d",a);
a = a + 7;
printf("\n\t The Value of a=a+7 is %d",a);
a+=3;
printf("\n\t The Value of a+= 3 is %d",a);
a-=6;
printf("\n\t The Value of a-= 6 is %d",a);
a*=4;
printf("\n\t The Value of a*= 4 is %d",a);
a/=8;
printf("\n\t The Value of a/= 8 is %d",a);
getch(); /* It is used to read a character */
}
/* PR9 */
main()
{
int a;
clrscr(); /* Clears the screen contents */
a = 16;
printf("\n\t The integer value of a is %d",a);
printf("\n\t The hexa decimal value of a is %x",a);
printf("\n\t The octal value of a is %o",a);
getch(); /* It is used to read a character */
}
/* PR19 */
main()
{
int a;
clrscr(); /* Clears the screen contents */
Prepared by Tanveer Ahmed 4/8/23 6
C Programs 7
printf("\n\t Enter any integer: ");
scanf("%d",&a);
printf("\n\t Value read in by scanf is %d:",a);
getch();
}
/* PR11 */
main()
{
int a = 2;
clrscr(); /* Clears the screen contents */
if(a > 0)
{
printf("\n\t If statement can also execute more than one statements");
printf("\n\t First Statement");
printf("\n\t Second statement");
}
getch();
}
Prepared by Tanveer Ahmed 4/8/23 7
C Programs 8
/* PR12 */
main()
{
int a = 2;
clrscr(); /* Clears the screen contents */
printf("\n\t Use of if-else with multiple statements:\n\n");
if(a > 0)
{
printf("\n\t Value is greater than zero :");
printf("\n\t And therefore is positive");
}
else
{
printf("\n\t Value is less than zero :");
printf("\n\t And therefore is negative");
}
getch();
}
Prepared by Tanveer Ahmed 4/8/23 8
C Programs 9
/* PR13 */
main()
{
char a;
clrscr(); /* Clears the screen contents */
printf("\n\t Enter a lower case alphabet fro a-c:\n\n");
scanf("%c",&a);
if(a == 'a')
printf("\n\t An apple a day keeps the doctor away:");
else
{
if(a =='b')
printf("\n\t Before you let yourself go, be sure that you can get your self back");
else
{
if(a == 'c')
printf("\n\t Children are gifts of God :");
else
printf("\n\t Illegal character, enter character from a-c");
}
}
getch();
}
Prepared by Tanveer Ahmed 4/8/23 9
C Programs 10
/* PR14*/
#include<ctype.h>
main()
{
char a;
clrscr(); /* Clears the screen contents */
printf("\n\t Enter any negative or positive number :");
class mthd{ public static void main(String args[]) { box mb = new box(); mb.width = 10; mb.height = 12; mb.depth = 30;
mb.vol(); }}
/* mymath */
class mymath{ public static void main(String args[])
Prepared by Tanveer Ahmed 4/8/23 32
C Programs 33
{ int a = 1 + 1; int b = a * 3; int c = b / 4; int d = c - a; int e = -d;
System.out.println("a is :" + a); System.out.println("b is :" + b); System.out.println("c is :" + c); System.out.println("d is :" + d); System.out.println("e is :" + e); }}
/* mymod */class mymod{public static void main(String args[]) { int x = 42; double y = 42.3;
System.out.println("x is integer with value :" +x); System.out.println("x mod 10 is :" +x % 10); System.out.println("y is double with value :" +y); System.out.println("x mod y is :" +x % y); }}