Q.1: Write a program to print hello world.
Ans.
#include<stdio.h>
#include<conio.h>
main()
{
printf("Hello world");
getch();
}
Q.2: Write a program to enter a string and print the string.
Ans.
#include<stdio.h>
#include<conio.h>
void main()
{
char a[ 10 ] ,i ;
clrscr ( );
printf ("Enter a string / your Name");
for ( i=0; i<10; i++)
scanf ("%c", &a[ i] );
for (i=0; i<10; i++)
printf ("%c", a[ i ] );
getch( );
}
Message : By the above program we can input limited character of string.
Q.3: Write a program to input a string and display by using gets( ) & puts( ) method.
Message : By using gets ( ) & puts ( ) method we can input infinite character in to the string.
Ans.
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<string.h>
void main( )
{
char a[ 1 ];
clrscr( ) ;
printf("Enter a string / Your Name");
gets ( a );
puts ( a );
getch ( );
}
Q.4: Write a program to count the length of a string.
Message : Here strlen( ) return a value which is store in n.
Ans.
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main( )
{
char a[ 10 ];
int n;
clrscr( );
printf("Enter a string / Your name : ");
gets(a);
n = strlen ( );
printf("Length of the string : %d", n);
getch( );
}
Q.5: Write a program to enter Two numbers and return multiple results Addition / Subtraction / Multiplication / Division .
Ans.
#include<stdio.h>
#include<conio.h>
int main( )
{
int no1, no2, add, sub, mul, div ;
clrscr();
printf("Enter two nos for multiple operation");
scanf("%d %d", &no1, &no2);
add=no1+no2;
sub=no1-no2;
mul=no1*no2;
div=no1/no2;
printf("Addition of two numbers = %d", add);
printf(" \n Subtraction of two numbers = %d", sub);
printf(" \n Multiplication of two numbers = %d", mul);
printf(" \n Division of two numbers = %d", div);
getch();
}
Q.6: Write a program to input two numbers and find the biggest number.
Ans.
#include<stdio.h>
#include<conio.h>
void main()
{
int a, b;
clrscr();
printf("Enter the value of A=");
scanf("%d", &a);
printf("Enter the value of B=");
scanf("%d", &b);
a>b? printf("The Number A %d is biggest number",a) : printf("The Number B %d is biggest number",b);
getch();
}
Q.7: Write a program to input three numbers and find the biggest among them.
Ans.
#include<stdio.h>
#include<conio.h>
void main()
{
int a, b, c;
clrscr();
printf("Enter the value of A");
scanf ("%d", &a);
printf("Enter the value of B");
scanf("%d", &b);
printf("Enter the value of C");
scanf("%d", &c);
a>b? a>c? printf("A is big") : printf("C is big") : b>c? printf(" B is big") : printf("C is big");
getch();
}
Q.8: Write a program to check the number is odd or even.
Ans.
#include<stdio.h>
#include<conio.h>
void main()
{
int no;
clrscr();
printf("Enter a no. :");
scanf("%d", &no);
no>0 ? printf("Number is positive") : printf("Number is negative");
getch();
}
Q.9: Write a program to check no is even or odd.
Ans.
#include<stdio.h>
#include<conio.h>
void main()
{
int no;
clrscr();
printf("Enter a no");
scanf("%d", &no);
(no%2)==0 ? printf("Number is even"): printf("Number is odd");
getch();
}
Q.10: Write a program to check that number is odd or even using if/else statement.
Ans.
#include<stdio.h>
#include<conio.h>
void main()
{
int no;
clrscr();
printf("Enter a number");
scanf("%d", &no);
if(no%2==0)
printf("Number is Even");
else
printf("Number is Odd");
getch();
}
Q.11: Write a program to print the numbers from 1 to 25.
Ans.
#include<stdio.h>
#include<conio.h>
void main()
{
int no;
clrscr();
for(no=1; no<=25; no++)
printf(" %d ", no);
getch();
}
Q.12: Write a program to print your name for 10 times.
Ans.
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char name[30];
int i;
clrscr();
printf("Enter your name");
gets(name);
for(i=0; i<10; i++)
puts(name);
getch();
}
Q.13: Write a program to add all the Even numbers & multiply all the Odd numbers from 1 to 20.
Ans.
#include<Stdio.h>
#include<conio.h>
void main()
{
int no, sum=0, mul=1;
clrscr();
for(no=1; no<=20; no++)
{
if (no%2==0)
sum+=no;
else
mul*=no;
}
printf("Sum is= ", sum);
printf("Multiply is= ", mul);
getch();
}
Q.14: Write a program to input a number and display the even numbers of that number.
Ans:
#include <stdio.h>
#include <conio.h>
main()
{
int no, dg;
clrscr();
printf("\nEnter a no:>");
scanf("%d", &no);
for (; no!=0 ;)
{
dg=no%10;
if(dg%2==0)
printf("%d\n", dg);
no=no/10;
}
getch();
}
#include <conio.h>
main()
{
int no, dg;
clrscr();
printf("\nEnter a no:>");
scanf("%d", &no);
for (; no!=0 ;)
{
dg=no%10;
if(dg%2==0)
printf("%d\n", dg);
no=no/10;
}
getch();
}
Q.15: Write a program to print the prime numbers under 50.
Ans:
#include <stdio.h>
#include <conio.h>
main()
{
int i, no;
clrscr();
no=1;
while(no<=50)
{
i=0;
while(i<no)
{
if(no%2==0)
break;
i++;
}
if(i==no)
printf("%d\t", no);
no++;
}
}
#include <conio.h>
main()
{
int i, no;
clrscr();
no=1;
while(no<=50)
{
i=0;
while(i<no)
{
if(no%2==0)
break;
i++;
}
if(i==no)
printf("%d\t", no);
no++;
}
}
Q.16: Write a program to check that is prime number or not.
Ans:
#include <stdio.h>
#include <conio.h>
main()
{
int i=2, no;
clrscr();
printf("Enter a Number:>");
scanf("%d",&no);
while(i<no)
{
if(no%2==0)
break;
i++;
}
if(i==no)
printf("Number is prime Number\n", no);
else
printf("Number is not a prime Number\n");
getch();
}
1 Comments
🥰
ReplyDelete