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

C Program Page 8

C Program Page 8

C Program Page 8
To view other topics related to Computer. Click Here.

Program to find sum of digits (1-20) using if and goto statement

main()

{

int

clrscr();

n=1;

s=0;

abc;

s=s+n;

n=n+1;

if(n>=20)

goto abc;

print(“Sum of digits =%d\n”,s);

getch();

}

This program will perform arithmetic operation depending on your choice (Switch Statement).

Main()

{

int a,b,ch;

printf(“Enter first number\n”);

scanf(“%d”,&a);

printf(“Enter second number\n”);

scanf(“%d”,&b);

printf(“ Enter your choice\n”);

scanf(“%d”,&ch

}

case 1: printf(“Addition =%d\n”,a+b);

break;

case 2: printf(“Subtraction =%d\n”,a-b);

case 3: printf(“Multiplication =%d\n”,a*b);

break;

case 4:printf (“Division=%d\n”,a/b);

break;

default:

printf(Invalid Choice\n”);

}

A quick demo of nested if-else statement(Nested “If –Else” Statement)

main()

{

int l;

printf(“Enter either 1 or 2”);

scanf(“%d”,&l);

if (I == 1)

printf(“You would go to heavent\n”);

else

{

if(I ==2)

printf(“Hell was created with you in mind”);

else

printf(“How about mother earth l”);

getch();

}

}

Write a program to input three integer values. Compare the three values to find out if they are equal .Use “ nested if statement”

main()

{

int r,n,b;

clrscr();

printf(Enter first value ?\n”);

scanf(“%d”,&r);

printf(“Enter second value ?\n”);

scanf(“%d”,&n);

printf(“Enter third value ?\n”);

scanf(“%d”,&b);

if(r==n)

{

if(r==b)

printf(“All values are equal\n”);

}

else

printf(“These values are different\n”);

}

Write a program to calculate the division obtained by the student(Using Else-if Statement).

main()

{

int mks;

float per;

char g;

printf(“Enter your marks\n”);

scanf(“%d”,&mks);

per=mks*100/850;

if((per>=80)&&(per<=100))

g=’A’

else if ((per>=60)&&(per<=80))

g=’B’

else if ((per>=40)&&(per<=60))

g=’C’

else if ((per >= 30)&&(per< = 40))

g=’D’

else

printf (marks = %d\n”,mks);

printf (“marks = %f \n”,per);

printf(“marks =%c\n”,g);

getch();

}

Write a program to calculate the division obtained by the student (Block of Statements).

main()

{

int m1,m2,m3,m4,m5,per;

print(“Enter marks in five subjects”);

scanf(“%d %d %d %d %d”,&m1,&m2,&m3,&m4,&m5);

per=(m1+m2+m3+m4+m5)/5;

if(per>= 60)

printf(“First division”);

else

{

if ( per>=50)

printf(“Second division”);

else

{

if ( per >=40)

printf(“Third division”);

else

printf(“Fail”);

}

}

}

Post a Comment

Previous Post Next Post