Sie sind auf Seite 1von 12

C Syllabus for LAB

Problem Based on If Statement


1. To check whether the given number is odd or even. #include<stdio.h> #include<conio.h> void main() { int num; clrscr(); printf("Enter the number >> "); scanf("%d",&num); if(num%2==0) { printf("\nIt is Even number"); } else { printf("\nIt is Odd number"); } getch(); } 2. To check whether the given number is positive or negative or zero. #include<stdio.h> #include<conio.h> void main() { int num; clrscr(); printf("Enter the number >> "); scanf("%d",&num); if(num<0) { printf("\nIt is Negative number"); } else if(num>0) { printf("\nIt is Positive number"); } else { printf("\nIt is Zero");

} getch(); } 3. To check whether the given number is palindrome or not. 4. To check whether the given number is of one digited or two digited or three digited or more than three digited. #include<stdio.h> #include<conio.h> void main() { int num; clrscr(); printf("Enter the number >> "); scanf("%d",&num); if(num<10) { printf("\nIt is One digit number"); } else if(num<100) { printf("\nIt is Two digit number"); } else if(num<1000) { printf("\nIt is Three digit number"); } else if(num>1000) { printf("\nMore than three digit are there"); } getch(); } 5. To check whether the given number is a perfect square or not. 6. To check whether the given character is an uppercase letter or lowercase letter or a digit or a special character. #include<stdio.h> #include<conio.h>

void main() { int num; clrscr(); printf("Enter the number >> "); scanf("%d",&num); if(num>=48 & num<=57) { printf("\nIt is %c digit",num); } else if(num>=65 && num<=90) { printf("\nIt is Uppercase letter"); } else if(num>=97 && num<=122) { printf("\nIt is Lowercase Letter"); } else { printf("\nIt is Sepecial Symbol"); } getch(); } 7. To determine whether the given year is a leap year or not. #include<stdio.h> #include<conio.h> void main() { int yr; clrscr(); printf("Enter the year >> "); scanf("%d",&yr); if(yr%4==0) { printf("\nIt is Leap Year"); } else { printf("\nIt is not a Leap year"); }

getch(); } 8. To check whether the given number is divisible by 5 or not. #include<stdio.h> #include<conio.h> void main() { int num; clrscr(); printf("Enter the year >> "); scanf("%d",&num); if(yr%5==0) { printf("\nIt is divisible by 5"); } else { printf("\nIt is not Divisible by 5"); } getch(); } 9. To find maximum number out of given three numbers. 10. An electronic component vendor supplies three products: transistors, resistors and capacitors. The vendor gives a discount of 10% on orders for transistors is the order is for more than Rs. 1000. On orders of more than Rs. 100 for resistors, a discount of 5% is given, and a discount of 10% is given on orders for capacitors of value more than Rs. 500. Assume that the numeric codes 1, 2 and 3 are used for transistors, capacitors and resistors respectively. Write a program that reads the product code and the order amount and prints out the net amount that customer is required to pay after discount.

Problem Based on For-loop Statement


1. To print multiplication table from 1x1 to 10x10.

#include<stdio.h> #include<conio.h> void main() { int i,j; clrscr(); printf("\n****************************************************************** **************"); printf("\n\t\t\t\t\tTables"); printf("\n****************************************************************** **************\n"); for(i=1;i<=10;i++) { for(j=1;j<=10;j++) { printf("%d*%d=%d\t",j,i,j*i); } printf("\n"); } getch(); }

2. To compute the sum of the digits of a given positive integer number.


#include<stdio.h> #include<conio.h> void main() { int i,sum=0,n,val; clrscr(); printf("How nmany no u want to enter >> "); scanf("%d",&n); for(i=1;i<=n;i++) { printf("Enter the number >> "); scanf("%d",&val); sum=sum+val; }

printf("\nThe sum of digit %d",sum); getch(); }

3. To read any five real numbers and print the average value.
#include<stdio.h> #include<conio.h> void main() { int i; float rl,avg,sum=0; clrscr(); for(i=1;i<=5;i++) { printf("Enter the Real number >> "); scanf("%f",&rl); sum=sum+rl; } avg=sum/5; printf("\nAverage of 5 real no is %.2f",avg); getch(); }

4. To calculate the sum of first N natural numbers.


#include<stdio.h> #include<conio.h> void main() { int i,sum=0,n; clrscr(); printf("Enter the number >> "); scanf("%d",&n); for(i=1;i<=n;i++) { sum=sum+i; } printf("\nSum of Natural No is %d",sum);

getch(); }

5. To calculate the average of first N odd numbers.


#include<stdio.h> #include<conio.h> void main() { int i,n,sum=0; float avg; clrscr(); printf("Enter the number >> "); scanf("%d",&n); for(i=1;i<=n;i++) { if(i%2!=0) { sum=sum+i; } } avg=sum/n; printf("\nAverage of %d ODD no is %.2f",n,avg); getch(); }

6. To calculate the average of first N even numbers.


#include<stdio.h> #include<conio.h> void main() { int i,n,sum=0; float avg; clrscr(); printf("Enter the number >> "); scanf("%d",&n); for(i=1;i<=n;i++) { if(i%2==0)

{ sum=sum+i; } } avg=sum/n; printf("\nAverage of %d Even no is %.2f",n,avg); getch(); }

Write a program to generate and display the following patterns:


1 12 123 1234 #include<stdio.h> #include<conio.h> void main() { int i,n,sum=0; float avg; clrscr(); printf("Enter the number >> "); scanf("%d",&n); for(i=1;i<=n;i++) { if(i%2==0) { sum=sum+i; } } avg=sum/n; printf("\nAverage of %d Even no is %.2f",n,avg); getch(); } 1.

2.

22 333 4444

#include<stdio.h> #include<conio.h> void main() { int i,j; float avg; clrscr(); for(i=1;i<=5;i++) { for(j=1;j<=i;j++) { printf("%d",i); } printf("\n"); } getch(); } 3.

1 22 333 4444

#include<stdio.h> #include<conio.h> void main() { int i,j,k; clrscr(); for(i=1;i<=5;i++) { for(k=5;k>=i;k--) { printf(" "); } for(j=1;j<=i;j++)

{ printf("%d",i); } printf("\n"); } getch(); }

4.

1 21 321 4321

#include<stdio.h> #include<conio.h> void main() { int i,j,k; clrscr(); for(i=1;i<=5;i++) { for(k=5;k>=i;k--) { printf(" "); } for(j=i;j>=1;j--) { printf("%d",j); } printf("\n"); } getch(); }

Write a program to do the following task: 1. To print ASCII value of all characters.
#include<stdio.h> #include<conio.h>

void main() { int str,stp,i; clrscr(); printf("Enter the start value >> "); scanf("%d",&str); printf("Enter the stop value >> "); scanf("%d",&stp); printf("\nAscii\tsymbol"); for(i=str;i<=stp;i++) { printf("\n%d\t%c",i,i); } getch(); }

2. To print series: 2,10,30,68, 130 and so on.


#include<stdio.h> #include<conio.h> void main() { int n,i,sr; clrscr(); printf("Enter the number >> "); scanf("%d",&n); printf("\n"); for(i=1;i<=n;i++) { sr=(i*i*i)+i; printf("%d ",sr); } getch(); }

3. To print the series: 1, 3, 6,10,15,21 and so on.


#include<stdio.h> #include<conio.h> void main()

{ int n,i,sr; clrscr(); printf("Enter the number >> "); scanf("%d",&n); printf("\n"); for(i=1;i<=n;i++) { sr=(i*i*i)+i; printf("%d ",sr); } getch(); }

Das könnte Ihnen auch gefallen