Sie sind auf Seite 1von 14

simple program.

1). program for hello print without input.


#include<stdio.h>
#include<conio.h>
void main()
{
printf("hello world");
getch();
} output: - hello world

2). program for name print using input(samarpit).


#include<stdio.h>
#include<conio.h>
void main()
{
char name;
printf("enter your name: ");
scanf("%c",&name);
printf(“your name is%c”,name);
getch();
} output:- s

3). program for name print using input(samarpit).


#include<stdio.h>
#include<conio.h>
void main()
{
char name[10];
printf("enter your name: ");
scanf("%s",&name);
printf(“your name is:%s”,name);
getch();
} output:- samarpit

4). program for name print using input(samarpit).


#include<stdio.h>
#include<conio.h>
void main()
{
char name[10];
printf("enter your name: ");
gets(name);
printf(“your name is);
puts(name);
getch();
} output:- samarpit

5). program for print number using input(123).


#include<stdio.h>
#include<conio.h>
void main()
{
int a;
clrscr();
printf("enter your number: ");
scanf(“%d”,&a);
printf(“your number is:%d”,a);
getch();
} output:- 123
6). program for print float number using input(4.5689).
#include<stdio.h>
#include<conio.h>
void main()
{
float a;
clrscr();
printf("enter your number: ");
scanf(“%f”,&a);
printf(“your number is:%f”,a);
getch();
} output:- 4.568900

7). program for print float number using input(4.5689).


#include<stdio.h>
#include<conio.h>
void main()
{
float a;
clrscr();
printf("enter your number: ");
scanf(“%f”,&a);
printf(“your number is:%.2f”,a);
getch();
} output:- 4.57

8). program for add two integer value using three variables.(2,5)
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("enter your number: ");
scanf(“%d%d”,&a,&b);
c=a+b;
printf(“your number is:%d”,c);
getch();
} output:- 7
or
printf("sum of a or b =%d, c=a+b);

9). program for add two integer value using two variables(2,5)
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("enter your number: ");
scanf(“%d%d”,&a,&b);
a=a+b;
printf(“your number is:%d”,a);
getch();
} output:- 7
10). program for add, sub, mul, div in two integer value.(8,2) short
#include<stdio.h>
#include<conio.h>
void main()
{
int a=9,b=2,c;
clrscr();
printf("%d",c=a+b);
printf("\n%d",c=a*b);
printf("\n%d",c=a/b);
printf("\n%d",c=a-b);
printf("\n%d",c=a%b);
getch();
} output:-11, 18, 4, 7, 1

11). program for convert temperature from fahrenheit to centigrade.(of=89.5)


#include<stdio.h>
Int main()
{
float f,c;
printf(“enter temperature in fahrenheit:”);
scanf(“%f”,f);
c=(f-32)/1.8;
printf(“temperature in centigrade %.2f”,c);
return 0;
} output:- centigrade- 32

12). program for convert temperature from centigrade to fahrenheit.(oc=32)


#include<stdio.h>
Int main()
{
float f,c;
printf(“enter temperature in centigrade:”);
scanf(“%f”,c);
f=(c*1.8)+32;
printf(“temperature in fahrenheit %.2f”,f);
return 0;
} output:- fahrenheit – 89.5

13). program for postfix and prefix increment or decrement operator.


#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
n=4;
printf(“postfix value is:%d”,n++);
printf(“prefix value is:%d”,++n);
getch();
} output:- 4 , 6

14). program for postfix and prefix increment or decrement operator.


#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
n=4;
printf(“prefix value is:%d”,++n);
printf(“postfix value is:%d”,n++);
getch();
} output:- 5 , 5

15). program for sizeof data types. sizeof operator also unary operator.
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
float b;
double c;
char d;
clrscr();
printf(“sizeof int data type is:%d”,sizeof(a));
printf(“sizeof float data type is:%d”,sizeof(b));
printf(“sizeof double data type is:%d”,sizeof(c));
printf(“sizeof char data type is:%d”,sizeof(d));
getch();
} output:- 2 , 4 , 8, 1

16). program for types casting.


#include<stdio.h>
#include<conio.h>
void main()
{
int sum, total;
float pre;
clrscr();
printf(“please enter total marks: ”);
scanf(“%d”,&total);
printf(“please enter sum of marks: ”);
scanf(“%d”,&sum);
pre=(100*(float)sum)/(float)total;
printf(“percentage of student marks is:%.2f”,pre);
getch(); 1200--600
} output:- 50.00

17). program for swap tow number using three variables.


#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf(“please enter values of a and b: ”);
scanf(“%d%d”,&a,&b);
c=a;
a=b;
b=c;
printf(“value of a is:%d\t value of b is:%d”,a,b);
getch(); a=5, b=7
} output:- a=7, b=5
.

18). program for swap tow number without using third variables.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf(“please enter values of a and b: ”);
scanf(“%d%d”,&a,&b);
a=a+b;
b=a-b;
a=b-a;
printf(“value of a is:%d\t value of b is:%d”,a,b);
getch(); a=5, b=7
} output:- a=7, b=5

19). program to find the area of rectangle. (a=h.w)


#include<stdio.h>
#include<conio.h>
void main()
{
int h,w,area;
clrscr();
printf(“please enter rectangle width: ”);
scanf(“%d”,&w);
printf(“please enter rectangle height: ”);
scanf(“%d”,&h);
area=w*h;
printf(“area of rectangle is: %d”,area);
getch(); w=25, h=50
} output:- area = 1250

20). program for find area and circumference of circle.


#include<stdio.h>
#include<conio.h>
void main()
{
int r;
float area,ci,pi=3.14;
clrscr();
printf(“pls enter the radius:”);
scanf(“%d”,r);
area=pi*r*r;
printf(“area of circle is:%.2f”,area);
ci=2*pi*r;
printf(“circumference of circle is:%.2f”,ci);
getch(); enter radius- 5
} output:- area of circle= 78.0
circumference= 31.4

21). program for find volume of cuboid.


#include<stdio.h>
#include<conio.h>
void main()
{
int h,w,b;
clrscr();
printf(“pls enter cuboid height:”);
scanf(“%d”,&h);
printf(“pls enter cuboid width:”);
scanf(“%d”,&w);
printf(“pls enter cuboid base:”);
scanf(“%d”,&b);
area=h*w*b;
printf(“area of circle is:%.d”,area);
getch();
} height=7, width=5, base=6
output:- area of cuboid= 210

22). program for print reverse string using library file.


#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int ch[100];
clrscr();
printf(“enter string: ”);
gets(a);
strrev(a);
printf(“your revers string is: %s”,ch);
getch();
} string: i am student.
output:-

23). program for calculate the factorial given number using for loop.
#include<stdio.h>
#include<conio.h>
void main()
{
int c,n,fact=1;
clrscr();
printf(“enter a number to calculate it`s factorial: ”);
scanf(“%d”,&n)
for(c=1;c<=n;c++)
{
fact= fact*c;
}
printf(“factorial of %d is : %d”,n,fact);
getch();
} n=6
output:- 720

24). program for the number is positive or negative using simple if.
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
clrscr();
printf("enter the number: ");
scanf("%d",&a);
if(a>=0)
{
printf("the number %d is positive”, a);
}
if(a<0)
{
printf("the number %d is negative”, a);
}
getch();
}

25). program for user can vote or not using simple if.
#include<stdio.h>
#include<conio.h>
void main()
{
int age;
clrscr();
printf("enter the number: ");
scanf("%d",&age);
if(age>=18)
{
printf("you can vote because your age is:%d”,age);
}
if(a<18)
{
printf("you can`t vote because your age is:%d”,age);
}
getch();
}

26). program for the is odd or even using simple if.


#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf("enter the number: ");
scanf("%d",&n);
if(a%2 == 0)
{
printf("the number is even:%d",a);
}
if(a%2 != 0)
{
printf("the number is odd:%d",a);
}
getch();
}

27). program for find largest number in two variables using simple if.
#include<stdio.h>
#include<conio.h>
void main()
{
int a, b, largest;
clrscr();
printf("enter two number: ");
scanf("%d%d",&a,&b);
largest=a;
if(b>largest)
{
largest=b;
}
printf("the largest number is :%d",largest);
getch();
}

28). program for find largest number in three variables using simple if.
#include<stdio.h>
#include<conio.h>
void main()
{
int a, b, c, largest;
clrscr();
printf("enter three number: ");
scanf("%d%d%d",&a,&b,&c);
largest=a;
if(b>largets)
{
largest=b;
}
if(c>largets)
{
largest=c;
}
printf("the largest number is :%d",largest);
getch();
}

29). program for the number is positive or negative using if-else.


#include<stdio.h>
#include<conio.h>
void main()
{
int a;
clrscr();
printf("enter the number: ");
scanf("%d",&a);
if(a>=0)
{
printf("the number %d is positive”, a);
}
else
{
printf("the number %d is negative”, a);
}
getch();
}

30). program for user can vote or not using if-else.


#include<stdio.h>
#include<conio.h>
void main()
{
int age;
clrscr();
printf("enter the number: ");
scanf("%d",&age);
if(age>=18)
{
printf("you can vote because your age is:%d”,age);
}
else
{
printf("you can`t vote because your age is:%d”,age);
}
getch();
}

31). program for the is odd or even using if-else.


#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf("enter the number: ");
scanf("%d",&n);
if(a%2 == 0)
{
printf("the number is even:%d",a);
}
else
{
printf("the number is odd:%d",a);
}
getch();
}

32). program for find largest number in two variables using if-else.
#include<stdio.h>
#include<conio.h>
void main()
{
int a, b;
clrscr();
printf("enter tow number: ");
scanf("%d%d",&a,&b);
if(a>b)
{
printf("the largest number is :%d",a);
}
else
{
printf("the largest number is :%d",b);
}
getch();
}

33). program for find largest number in three variables using simple if.
#include<stdio.h>
#include<conio.h>
void main()
{
int a, b, c, largest;
clrscr();
printf("enter tow number: ");
scanf("%d%d%d",&a,&b,&b);
largest=a;
if(b>largets)
{
largest=b;
}
if(c>largets)
{
largest=b;
}
printf("the largest number is :%d",largest);
getch();
}

34). program for a for loop with break.


#include<stdio.h>
#include<conio.h>
void main()
{
int i=1;
for(i=1;i<=10;i++)
{
printf(“enter ”,i,”no”);
printf(“ \t %d ”,i);
if(i>5)
break;
}
getch();
}

35). program for a for loop with continues.


#include<stdio.h>
#include<conio.h>
void main()
{
int i=1;
for(i=1;i<=10;i++)
{
printf(“enter ”,i,”no”);
printf(“ \t %d ”,i);
if(i==5 || i==8)
continue;
}
getch();
}

36). program for a for loop with continues.


#include<stdio.h>
#include<conio.h>
void main()
{
int i,n;
float s;
start:
printf(“enter a no.”);
scanf(“%d”,&n);
s=sqrt(n);
if(n<=0)
goto start;
printf(“%f”,s);
getch();
}

star program

37)
#include<stdio.h>
*
int main()
*** {
***** int i, j, k;
******* for(i=1;i<=5;i++)
********* {
for(j=i;j<5;j++)
{
printf(" ");
}
for(k=1;k<(i*2);k++)
{
printf("*");
}
printf("\n");
}
return 0;
}

38)
#include<stdio.h>
*********
int main(){
******* int i, j, k;
***** for(i=5;i>=1;i--)
*** {
* for(j=5;j>i;j--)
{
printf(" ");
}
for(k=1;k<(i*2);k++)
{
printf("*");
}
printf("\n");
}
return 0;
}

39)
********** #include<stdio.h>
int main()
**** ****
{
*** *** int i, j, k;
** ** for(i=1;i<=5;i++)
* * {
** ** for(j=1;j<=6-i;j++)
{
*** *** printf("*");
**** **** }
********** for(k=1;k<i;k++)
{
printf(" ");
}
for(j=1;j<=6-i;j++)
{
printf("*");
}
printf("\n");
}
for(i=2;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("*");
}
for(k=1;k<=5-i;k++)
{
printf(" ");
}
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
return 0;
}

40)
#include<stdio.h>
*
int main()
*** {
***** int i, j, k;
******* for(i=1;i<=5;i++)
********* {
for(j=i;j<5;j++)
*******
{
***** printf(" ");
*** }
* for(k=1;k<(i*2);k++)
{
printf("*");
}
printf("\n");
}
for(i=4;i>=1;i--)
{
for(j=5;j>i;j--)
{
printf(" ");
}
for(k=1;k<(i*2);k++)
{
printf("*");
}
printf("\n");
}
return 0;
}

41)
#include<stdio.h>
*
int main()
** {
*** int i, j;
**** for(i=1;i<=5;i++)
***** {
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
return 0;
}

42)
#include<stdio.h>
*****
int main()
**** {
*** int i, j;
** clrscr();
* for(i=5;i>=1;i--)
{
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
return 0;
}

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

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

Das könnte Ihnen auch gefallen