Some Basic Program
1) Write a Program that will print your mailing address in the following form.
Solution :
#include<stdio.h>
#include<conio.h>
void main()
{
float r,A;
printf("Enter radius:");
scanf("%f",&r);
A=3.1416*r*r;
printf("Area=%f",A);
getch();
}
2) Write a program to calculate and print the area of surface and volume of a sphere.(Try other geometrical solids)
Solution :
#include<stdio.h>
#include<conio.h>
void main()
{
float r,A,V;
printf("Enter radius:");
scanf("%f",&r);
A=4*3.1416*r*r;
V=4/3*3.1416*r*r*r;
printf("Area=%f,Volume=%f",A,V);
getch();
}
3) Write a program to calculate and print the area of a rectangle.
Solution :
#include<stdio.h>
#include<conio.h>
void main()
{
float a,b,A;
printf("Enter length & height:");
scanf("%f%f",&a,&b);
A=a*b;
printf("Area=%f",A);
getch();
}
4) Write a program to convert centigrade value to Fahrenheit value(Try such other conversions).Solution :
#include<stdio.h>
#include<conio.h>
void main()
{
float C,F;
printf("Enter fahrenheit value:");
scanf("%f",&F);
C=((F-32)*5)/9;
printf("Centigrade value=%f",C);
getch();
}
5) Write a program to convert days in year, month and days(Try such other conversion).Solution :
#include<stdio.h>
#include<conio.h>
void main()
{
int days,d,m,y;
printf("Enter number of days:");
scanf("%d",&days);
y=days/365;
d=days%365;
m=d/30;
d=d%30;
printf("%d days=%d years %d months & %d
days.",days,y,m,d);
getch();
}
6) Write a program to display fibonacci series using recursive function.Solution :
#include<stdio.h>
#include<conio.h>
void fibonacci(int x,int y,int n)
{
int sum=x+y;
if(sum<n)
{
printf(" %d",sum);
fibonacci(y,sum,n);
}
}
void main()
{
clrscr();
int s;
printf("\nEnter your fibonacci number:");
scanf("%d",&s);
fibonacci(-1,1,s);
getch();
}
7) Write a program to check password that will contain minimum a upper, a lower and a digit.
Solution :
#include<stdio.h>
#include<conio.h>
#include<ctype.h>
#include<string.h>
bool testPass(char *pass)
{
// flags
bool aUpper = false,
aLower = false,
aDigit = false ;
for ( int i = 0 ; pass[i] ; i++ ){
if ( isupper(pass[i]) )
aUpper = true ;
else if ( islower(pass[i]) )
aLower = true ;
else if ( isdigit(pass[i]) )
aDigit = true ;
}
if ( aUpper && aLower && aDigit )
return true;
else
return false ;
}
int main(){
char pass[10];
printf("Enter some char >");
gets(pass);
//scanf("%s", &pass);
//printf("Len > %d",strlen(pass));
if(testPass(pass) && strlen(pass) >=8){
printf("Correct");
}
else{
printf("Not Correct");
}
return 0;
}