Collection Of Icc Programs

  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Collection Of Icc Programs as PDF for free.

More details

  • Words: 975
  • Pages: 11
Introduction to Computer & Computing

// Print a table of number entered by user // //1st Program using LOOPS// #include #include<stdio.h> void main() { int a,b,c; clrscr(); printf("\n\nEnter the number of which you want to get table = "); scanf("%d",&a); for(b=1;b<=10;b++) { c=a*b; printf("\n%d * %d = %d ",a,b,c); } getch(); }

// HOLLOW RECTANGLE // #include #include<stdio.h> void main() { int a,b,c,d; char f='*'; clrscr(); printf("\n\nEnter the width of rectangle = "); scanf("%d",&a); printf("\nEnter the length of rectangle = "); scanf("%d",&b); for(c=a;c>=1;c--) { printf("%c ",f); } for(d=b;d>=1;d--) { printf("\n%c",f); for(c=2*a-3;c>=1;c--) { printf(" "); } printf("%c",f); } printf("\n"); for(c=a;c>=1;c--) { printf("%c ",f); } getch(); }

Page 1 of 11

Introduction to Computer & Computing

//

HOLLOW

TRIANGLE //

#include #include<stdio.h> void main() { int a,b,c,d=-1; clrscr(); for(a=6;a>=1;a--) { printf("\n"); for(b=a;b>=1;b--) { printf(" "); } printf("*"); for(c=1;c<=d;c++) { printf(" "); } if(c>1) { printf("*"); } d=d+2; } printf("\n"); for(a=13;a>=1;a--) printf("*"); getch(); }

Page 2 of 11

Introduction to Computer & Computing

//

DIAMOND //

#include #include<stdio.h> void main() { int a,b,c,d=-1; clrscr(); for(a=7;a>=1;a--) { d=d+2; printf("\n"); for(b=a;b>=1;b--) { printf(" "); } for(c=d;c>=1;c--) { printf("*"); } } for(a=1;a<=6;a++) { d=d-2; printf("\n"); for(b=a;b>=0;b--) { printf(" "); } for(c=d;c>=1;c--) { printf("*"); } } getch(); }

Page 3 of 11

Introduction to Computer & Computing

//

HOLLOW

DIAMOND //

#include #include<stdio.h> void main() { int a,b,c,d=-1; clrscr(); printf("\n"); for(a=6;a>=1;a--) { printf("\n"); for(b=a;b>=1;b--) { printf(" "); } printf("*"); for(c=1;c<=d;c++) { printf(" "); } if(c>1) { printf("*"); } d=d+2; } for(a=1;a<=7;a++) { printf("\n"); for(b=a;b>=2;b--) { printf(" "); } printf("*"); for(c=1;c<=d;c++) { printf(" "); } if(c>1) printf("*"); d=d-2; } getch(); }

Page 4 of 11

Introduction to Computer & Computing

// Check the Prime Number // #include #include<stdio.h> void main() { int i,a,b=1; clrscr(); printf("\n\nEnter the number to check wheather it is prime or constant = "); scanf("%d",&a); for(i=2;i<=a-1;) { b=a%i; if(b==0) { printf("\nThe number is constant = %d",a); break; } i++; if(i==a) { printf("\nThe number is PRIME = %d",a); } } getch(); }

//

FIBBONACCI

#include<stdio.h> #include void fibonacci(float num); void main() { float i,j,k,n; i=0; j=1; printf("%f, %f",i,j); for(n=2;n<=num;n++) { k=i+j; i=j; j=k; printf(", %f",k); } getch(); }

Page 5 of 11

//

Introduction to Computer & Computing

//

PRIME FACTORS

#include #include<stdio.h> void main() { int a; clrscr(); printf("\n\nEnter A Number = "); scanf("%d",&a); printf("\nThe Prime Factors of The Number %d =",a); prime(a); getch(); } prime(int b) { int i,j,k,l; for(i=2;i<=b;) { j=b%i; if(j==0) { b=b/i; printf(" %d, ",i); continue; } if(j!=0) { i++; continue; } } }

// FACTORIAL // #include #include<stdio.h> void main() { int a,b; long double c=1; clrscr(); printf("\n\nEnter the number of which you want to get factorial = "); scanf("%d",&a); printf("\n%d! = ",a); for(b=a;b>=1;b--) { c=c*b; } printf(" = %.0Lf ",c); Page 6 of 11

//

Introduction to Computer & Computing getch(); }

//

LCM HCF //

#include<stdio.h> #include void main() { int a,b,c; printf("Enter two numbers = "); scanf("%d%d",&a,&b); c=a*b; while(a!=b) { if(a>b) a=a-b; else b=b-a; } printf("HCF = %d ",a); printf("\nLCM = %d ",c/a); getch(); }

//

// LCM HCF // By using Functions

#include<stdio.h> #include int lcm(int a,int b); void main() { int a,b,c; printf("Enter two numbers = "); scanf("%d%d",&a,&b); c=a*b; a=lcm(a,b); printf("\nHCF = %d ",a); printf("\nLCM = %d ",c/a); getch(); } int lcm(int a,int b) { while(a!=b) { if(a>b) a=a-b; else b=b-a; } return(a); }

Page 7 of 11

//

Introduction to Computer & Computing

//

Average Marks By using Array

#include #include<stdio.h> avg(int a,int b); void main() { int a[5],c,d=0; clrscr(); printf("\n\nEnter the Marks of 5 students = "); for(c=0;c<=4;c++) { scanf("%d",&a[c]); } for(c=0;c<=4;c++) { d=avg(a[c],d); } printf("The average marks are = %d",d/5); getch(); }

//

Binary Equivalent

#include #include<stdio.h> void main() { int a,b[1000],i,j; printf("\n\nEnter a Number = "); scanf("%d",&a); printf("The binary equivalent of %d = ",a); for(i=0;;i++) { b[i]=a%2; if(b[i]==0) { a=a/2; } if(b[i]==1) { a=(a-1)/2; } if(a==1) break; } printf("%d",a); for(j=i;j>=0;j--) { printf("%d",b[j]); Page 8 of 11

//

//

Introduction to Computer & Computing } getch(); }

//

Search the number in array

//

#include #include<stdio.h> void main() { int a[25],b,c,d=0; clrscr(); printf("\nEnter 25 nos = "); for(b=0;b<=24;b++) scanf("%d",&a[b]); printf("Enter the no you want to search = "); scanf("%d",&c); for(b=0;b<=24;b++) { if(a[b]==c) d++; } if(d==0) printf("The no not appear in array"); else printf("The no %d appear in array %d times",c,d); getch(); }

//

Search even, odd, +ve and –ve number in array

#include #include<stdio.h> void main() { int a[25],b,c=0,d=0,e=0,f=0; clrscr(); printf("Enter 25 nos = "); for(b=0;b<=24;b++) scanf("%d",&a[b]); for(b=0;b<=24;b++) { if(a[b]>0) c++; if(a[b]<0) d++; if(a[b]%2==0) e++; if(a[b]%2!=0) f++; } printf("\nPositive number are %d times",c); printf("\nNegative number are %d times",d); printf("\nEVEN number are %d times",e); printf("\nODD number are %d times",f); Page 9 of 11

//

Introduction to Computer & Computing getch(); }

//

SIEVE of ERATOTHENES

//

#include #include<stdio.h> void main() { int a[100],b,c,d; clrscr(); for(b=0;b<=99;b++) { a[b]=b+1; } for(b=2;b<=100;b++) { for(c=b+1;c<=100;c++) { if(c%b==0) a[c-1]=0; } } for(b=1;b<=99;b++) { if(a[b]!=0) printf("%d ",a[b]); } getch(); }

//

Changing odd elements of array with even//

#include #include<stdio.h> void main() { int a[6],b[6],c; clrscr(); printf("Enter 6 numbers array = "); for(c=0;c<=5;c++) scanf("%d",&a[c]); for(c=0;c<=5;c++) printf("%d ",a[c]); for(c=1;c<=5;c=c+2) b[c]=a[c-1]; for(c=0;c<=5;c=c+2) b[c]=a[c+1]; printf("\n"); for(c=0;c<=5;c++) { printf("%d ",b[c]); } getch(); Page 10 of 11

Introduction to Computer & Computing }

//

S1--Q3

//

#include #include<stdio.h> void main() { int age; char ms,gender; clrscr(); printf("\nEnter your marital status for married press '1' and for unmarried press '2' = "); scanf("%d",&ms); printf("\nEnter your gender for male press '3' for female press '4' = "); scanf("%d",&gender); printf("\nEnter your age = "); scanf("%d",&age); if((ms==1)||(ms==2&&gender==3&&age>30)||(ms==2&&gender==4&&age>25)) { printf("\nThe Company will insure driver"); } else printf("\nThe Company will not insure Driver"); getch(); }

// S2—Q2 // // Number of Combinations of Entered Name #include #include<stdio.h> #include<string.h> void main() { int i; char name[1000]; float c=1; clrscr(); printf("\n\nEnter the word = "); scanf("%s",&name); i=strlen(name); if(i>=3) { for(;i>=1;i--) { c=c*i; } printf("Possible number of combinations are %.0f",c); } getch(); }

Page 11 of 11

//

Related Documents

Icc
November 2019 16
Icc
November 2019 26
Programs
October 2019 61
Icc Cronograma
June 2020 8