Sie sind auf Seite 1von 18

EX:NO:1 DATE : 27.7.

11

SUM OF TWO NUMBERS, AREA OF A CIRCLE,BIGGEST OF TWO AND THREE NUMBERS

#include<stdio.h> main() { int n, a, b, c; float area, r, s=3.14; printf("\nchoices:\n 1.sum of nimbers.\n 2.area of circle\n 3. maximum of two numbers\n 4.maximum of three numbers\n Enter oyur choices:"); scanf("%d", &n); switch (n) { case 1: printf("enter the two no"); scanf("%d%d", &a, &b); c=a+b; printf("%d is the sum",c); break; case 2: printf("enter the radius"); scanf("%f", &r); area = s * r * r; printf("%f is the area",area); break; case 3: printf("enter the two numbers"); scanf("%d%d", &a, &b); if(a>b) printf("%d is maximum",a); else printf("%d is maximum",b); break; case 4: printf("enter thtree numbers"); scanf("%d%d%d", &a, &b, &c); if(a>b) { if(a>c) printf("%d is maximum",a); else printf("%d is maximum",c); } else printf("%d is maximum",b); break; }; }

Output:
choices: 1. sum of nimbers. 2. area of circle 3. maximum of two numbers 4.maximum of three numbers Enter your choices : 1 enter the two no 3 6 9 is the sum Enter your choices : 2 enter the radius=6 Area=113.040001 Enter your choices : 3 enter the two numbers 6 9 9 is maximum

EX:NO:2 DATE:1.8.11

IMPLEMENTING ALL OPERATORS IN C

#include<stdio.h> main() { int n, a, b, c; short int m; do { printf("\n\t\t\tImplementation of operaters"); printf("\n1.Arithmatic\n2.Relatonal\n3.Logical\n4.conditional\n 5.size of"); printf("\nEnter your choice:"); scanf("%d",&n); switch(n) { case 1: printf("\n\t\t\tAirthmatic operater"); printf("\nEnter the value for a and b:\n"); scanf("%d%d",&a,&b); printf("\nsum=%d",a+b); printf("\ndifference=%d",a-b); printf("\nproduct==%d",a*b); printf("\nreminder=%d",a%b); printf("\nquantient=%d\n",a/b); break; case 2: printf("\n\t\t\tRelational operater"); printf("\nEnter a number:"); scanf("%ld",&a); if(a>0) printf("\n%d is positive",a); else if(a==0) printf("\n%d is poasitive nor negative",a); else printf("\n%d is negative",a); break; case 3: printf("\n\t\t\tLogical operater"); printf("\nEnter two numbers:"); if((0<=a<=1)&&(0<=b<=1)) { scanf("\n%d\n%d", &a,&b); printf("\nAND=%d",a&&b); printf("\nOR=%d",a||b); printf("\nNOT=%d",!a); }

else printf("\npls Enter the numbers 1's and 0,s."); break; case 4: printf("\n\t\t\tConditional operaters\n"); printf("\nenter two numbers:\n"); scanf("%d%d",&a,&b); printf("\n%d is maximum",(a>b)?a:b); break; case 5: printf("size of m=%d",sizeof(m)); break; }; } while(n>=1&&n<=5); }

OUTPUT
Implementation of operators 1. Arithmatic 2. Relatonal 3. Logical 4. Conditional 5. Size of Enter your choice: 1 Airthmatic operater Enter the value for a and b: 6 3 sum=9 difference=3 product==18 reminder=0 quantient=2 Enter your choice: 2 Relational operater Enter a number : 3 3 is positive Enter your choice: 3 Logical operater AND = 1 OR = 1 NO = 0 Enter your choice : 4 Conditional operators enter two numbers:6 3 6 is maximum

SUM OF DIGITS
EX NO:3
DATE:1.8.11 #include<stdio.h> main() { long int n; int sum=0; printf("\n Enter the number:"); scanf("%d",&n); while(n>0) { sum=sum+(n%10); n=n/10; } printf(" \n%d is the sum of digits\n\n\n",sum); }

Output:
Enter the number: 321654
21 is the sum of digits

REVERSING THE GIVEN NUMBER


EX NO:4 DATE:8.8.11
#include<stdio.h> main() { int x,s=0,r; printf("Enter the number:\n"); scanf("%d",&x); while(x!=0) { r=x%10; x=x/10; s=(s*10)+r; } printf("\nThe reverse is %d\n",s); }

Output:
Enter the number The reverse is 654. . : 456

FIBONOCCI SERIES
EX NO:5 DATE:8.8.11
#include<stdio.h> main() { int n,i,x1=-1,x2=1,x3; printf("enter the number of terms:"); scanf("%d",&n); printf("\n the series is...."); for(i=0;i<n;i++) { x3=x1+x2; x1=x2; x2=x3; printf("\n%d\n",x3); } }

Output:
enter the number of terms:5 the series is.... 0 1 1 2 3

FACTORIAL OF A GIVEN NUMBER:


EX NO:6 DATE:10.8.11
#include<stdio.h> main() { int f=1,i,n; printf("Enter the number:"); scanf("%d",&n); for(i=1;i<=n;i++) { f=f*i; } printf("\nThe factorial value is...%d\n",f); }

Output:
Enter the number:5 The factorial value is...120

ARMSTRONG NUMBER
EX NO:7 DATE:17.8.11

#include<stdio.h> main() { int n,n1,p,s=0; printf("enter n value:"); scanf("%d%",&n); n1=n; while(n!=0) { p=n%10; s=s+(p*p*p); n=n/10; } if (s==n1) printf("\n the no is ARMSTRONG\n"); else printf("\n the no is not ARMSTRONG\n"); }

Output:
Enter n value:153 the no is ARMSTRONG

GENERATING PRIME NUMBERS


E X NO:8 DATE:17.8.11
#include<stdio.h> main() { int n=1,i,a; printf("Enter the number:\n"); scanf("%d",&a); printf("\nthe series is....\n"); while(n<=a) { i=2; while(i<=n) { if(n%i==0) break; else i++; } if(i==n) printf("%d\n",n); n++; } }

Output:
Enter the number: 12 the series is.... 2 3 5 7 11

PRINTING MULTIPLICATON TABLES


EX NO:9 DATE:17.8.11
#include<stdio.h> main() { int n,i,m,j; printf("Enter the number:"); scanf("%d",&n); printf("tables for %d",n); for(i=1;i<n;i++) { for(j=1;j<=10;j++) { m=j*n; printf("\n%d*%d=%d",n,j,m); } } }

Output:
Enter the number:2 tables for 2 2*1=2 2*2=4 2*3=6 2*4=8 2*5=10 2*6=12 2*7=14 2*8=16 2*9=18 2*10=20

DISPLAYING NUMERIC TRIANGLES TRIANGLES


EX NO:10 DATE:24.8.11
#include<stdio.h> main() { int n,i,j,a; printf("1.Normal triangle.\n2.Reversed triangle\enter your choice:"); scanf("%d",&a); switch(a) { case 1: printf("Enter the number:"); scanf("%d",&n); for(i=1;i<=n;i++) { for(j=1;j<=i;j++) { printf(" %d ",j); } printf("\n"); } break; case 2: printf("Enter the number:"); scanf("%d",&n); for(i=1;i<=n;i++) { for(j=i;j>=1;j--) { printf(" %d ",j); } printf("\n"); } for(i=n;i>=1;i--) { for(j=i;j>=1;j--) { printf(" %d ",j); } printf("\n"); } break; } }

Output:
1. Normal triangle. 2. Reversed triangle Enter your choice: 1 Enter the number: 5 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 1. Normal triangle. 2. Reversed triangle Enter your choice: 2 Enter the number: 5 1 2 1 3 2 1 4 3 2 1 5 4 3 2 1 5 4 3 2 1 4 3 2 1 3 2 1 2 1 1

GENERATING ELECTRICITY BILL


EX NO: 11 DATE:24.8.11
#include<stdio.h> main() { char name[10]; int id,date,units,charge=0; printf("\nEnter the customer id:"); scanf("%d",&id); printf("\nEnter the customer name:"); scanf("%s",&name); printf("\nEnter the units consumed:"); scanf("%d",&units); printf("\n****************"); if(units<100) { charge=units*5; printf("charge=%d",charge); } else if(units>=100&&units<=200) { charge=units*7; printf("charge=%d",charge); } else { charge=units*10; printf("charge=%d",charge); } printf("\n****************"); printf("\ncustomer id:%d",id); printf("\ncustomer name:%s",name); printf("\ndate of payment:24|08|2011"); printf("\nunits consumed:%d",units); printf("\ncharges:%d\n",charge); }

Output:
Enter the customer id : 1001

Enter the customer name : aswin Enter the units consumed : 126 **************** Charge **************** customer id customer name date of payment units consumed charges

= 882 : : : : : 1001 Aswin 24|08|2011 126 882

FINDING SUM OF SERIES


EX NO:12 DATE:5.9.11
#include<stdio.h> main() { int n,i,j,sum=0,sqsum=0,c; printf("\n1.sum of number\n2.power\nEnter ur choice:"); scanf("%d",&c); switch(c) { case 1: { printf("Enter the number:"); scanf("%d",&n); printf("the numbers are "); for(i=1;i<=n;i++) { printf("\n%d",i); } printf("\nthe squres are"); for(j=1;j<=n;j++) { printf("\n%d",j*j); } for(i=1;i<=n;i++) { sum=sum+i; } printf("\nThe sum of numbers is %d",sum); for(j=1;j<=n;j++) { sqsum=sqsum+(j*j); } printf("\ntne sum of squres is %d\n",sqsum); } break; case 2: { int x,i,p,s=1,sum=0; printf("Enter the number:"); scanf("%d",&x); printf("\nEnter the power:"); scanf("%d",&p); sum=sum+1;

for(i=1;i<=p;i++) { s=s*x; sum=sum+s; sum=sum+1; } printf("\n%d",sum); } break; } }

Out put:
1.sum of number 2.power Enter ur choice : Enter the number:

1 5

the numbers are 1 2 3 4 5 the squres are 1 4 9 16 25 the sum of numbers is 15 tne sum of squres is 55 Enter your choice : 2 Enter the number : 6 Enter the power : 3

The sum of series is 262.

PERFECT NUMBER
EX NO:13 DATE:12.9.11
#include<stdio.h> main() { int n,i=1,s,sum=0; printf("Enter the number:"); scanf("%d",&n); while(i<n) { s=n%i; if(s==0) { sum=sum+i; } i++; } if(sum==n) printf("%d is perfect",n); else printf("%d is not perfect",n); }

Output:
Enter the number: 6 6 is perfect number.

Das könnte Ihnen auch gefallen