Beruflich Dokumente
Kultur Dokumente
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
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
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
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();
}
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();
}
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();
}
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();
}