Basic of C program:- comment and print function.
// This is a single line comment...
/*this is a multi line
comment*/
#include<stdio.h> //Header file..
#include<conio.h> //Header file..
int main() //first Code runs from here..
{
printf("Hello world!"); //Printf is the function to print..
return 0; //Returns the value. Here, it return nothings means 0..
}
C program to find Simple Intrest.
#include<stdio.h>
#include<conio.h>
int main()
{
float si, p, t, r;
printf("Enter principle(P): \n");
scanf("%f",&p);
printf("Enter time(T): \n");
scanf("%f",&t);
printf("Enter rate(R): \n");
scanf("%f",&r);
si=(p*t*r)/100; //formula to calculate Simple intrest......
printf("The simple intrest is: %f", si);
return 0;
}
C program to find whether the entered number is positive or negative.
#include<stdio.h>
#include<conio.h>
int main()
{
int a;
printf("\nEnter a number(Not zero): ");
scanf("%d",&a);
if (a < 0)
{
printf("\nIts negative number");
}
else
{
printf("\nIts positive number");
}
return 0;
}
C program to find whether the entered number is odd or even.
#include<stdio.h>
#include<conio.h>
int main()
{
int a;
printf("\nEnter a number: ");
scanf("%d",&a);
if (a%2==0)
{
printf("\nIts even number");
}
else
{
printf("\nIts odd number");
}
return 0;
}
C program to arrange 10 user input number in ascending order.
#include<stdio.h>
#include<conio.h>
int main()
{
int n[50],t;
for (int i = 0; i < 10; i++)
{
printf("\nEnter a number: ");
scanf("%d",&n[i]);
}
for (int i = 0; i < 10-1; i++)
{
for (int j = i+1; j < 10; j++)
{
if (n[i]>n[j])
{
t=n[i];
n[i]=n[j];
n[j]=t;
}
}
}
printf("\nNumber in ascending order are: ");
for (int i = 0; i < 10; i++)
{
printf("\n%d",n[i]);
}
return 0;
}
C program to show simple switch case.
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,ch,m;
printf("\nEnter first number: ");
scanf("%d",&a);
printf("\nEnter second number: ");
scanf("%d",&b);
printf("\nEnter 1 for finding sum\nEnter 2 for finding differnce\nEnter 3 for finding greaternumber\nyou have entered: ");
scanf("%d",&ch);
switch (ch) //switch to the var ch
{
case 1:
m=a+b;
printf("\nThe sum is: %d",m);
break;
case 2:
m=a-b;
printf("\nThe differnce is: %d",m);
break;
case 3:
if (a>b) // to find greates number
{
printf("%d is greates number\n",a);
}
else
{
printf("%d is greates number\n",b);
}
break;
default:
printf("\nYou should press 1/2/3 only\nThank you");
break;
}
return 0;
}
C program to show simple array example And to find Smallest number in array.
#include<stdio.h>
#include<conio.h>
int main()
{
int max,i;
int a[10]; //array declearing......
printf("\nEnter 5 positive numbers:\n");
for (int i = 0; i < 5; i++) //array always starts from 0..
{
scanf("%d",&a[i]);
}
max=a[0];
for (int i = 0; i > 5; i++)
{
if (a[i]<max)
{
max=a[i];
}
}
printf("\nSmallest number in array is: %d",max);
return 0;
}
C program to display number of digit you entered.
#include<stdio.h>
#include<conio.h>
int main()
{
int n,count=0;
printf("Enter the number: ");
scanf("%d",&n);
for ( n == 0; n++;)
{
count=count+1;
n=n/10;
}
printf("\nThere are %d digit in your number",count);
return 0;
}
C program to calculate electricity bill.
#include<stdio.h>
#include<conio.h>
int main()
{
float n,u;
printf("Enter Unit:");
scanf("%f",&n);
if (n<=20)
{
printf("\nTotal amount(Rs.) = 80");
}
else if (n<=30)
{
u=n*7.5+80;
printf("\nTotal amount(Rs.) = %f",u);
}
else if (n<=50)
{
u=n*10+80;
printf("\nTotal amount(Rs.) = %f",u);
}
else if (n<=80)
{
u=n*12.5+80;
printf("\nTotal amount(Rs.) = %f",u);
}
else
{
u=n*15+80;
printf("\nTotal amount(Rs.) = %d",u);
}
return 0;
}
C program to display fibonacci series to n term.
#include<stdio.h>
#include<conio.h>
int main()
{
int a=1,b=1,c=0,n;
printf("\nEnter the limit: ");
scanf("%d",&n);
for (int i = 1; i <= 10; i++)
{
printf("%d, ",a);
c= a+b;
a=b;
b=c;
}
return 0;
}
C program to find whether the entered number is Perfect number or not.
#include<stdio.h>
#include<conio.h>
int main()
{
int n,sum=0;
printf("Enter the number: ");
scanf("%d",&n);
for (int i = 1; i < n; i++)
{
if (n%i==0)
{
sum=sum+i;
}
}
if (sum==n)
{
printf("\nPerfect number");
}
else
{
printf("\nNot perfect");
}
return 0;
}
JS to display another content on another button click.
let btnText = document.querySelector('#btnText');
let text = document.querySelector('#text');
let htmle = document.querySelector('#htmle');
let btnHtml = document.querySelector('#btnHtml');
htmle.style.display='none';
text.style.display="";
btnText.addEventListener('click', () => {
htmle.style.display='none';
text.style.display="";
});
btnHtml.addEventListener('click', () => {
text.style.display='none';
htmle.style.display='';
});
JS of working contact page (G-mail).
function sendEmail(){
Email.send({
Host : "smtp.gmail.com",
Username : "123web.site8@gmail.com",
Password : "obktvhspdnlhxhxq",
To : '123web.site8@gmail.com',
From : document.getElementById("email").value,
Subject : "From portfolio Website",
Body : "Name: " + document.getElementById("name").value +"Email: " + document.getElementById("email").value + "Message: " +document.getElementById("message").value
}).then(
message => alert("Message send successfully")
);
}
JS to display typing effect.
// typing animation script
var typing = new Typed(".typing", {
strings: ["Student.",
"Web Developer."],
typeSpeed: 100,
backSpeed: 60,
loop: true
});