Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
75 views

Programming in C Language

The document provides examples of C programming code for various tasks: 1) A program to calculate simple interest using pointers. 2) A program to print a pattern using nested for loops. 3) A program to print the Fibonacci series of a given number of terms. 4) A program to perform arithmetic operations like addition and subtraction using switch case.

Uploaded by

tanisq10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views

Programming in C Language

The document provides examples of C programming code for various tasks: 1) A program to calculate simple interest using pointers. 2) A program to print a pattern using nested for loops. 3) A program to print the Fibonacci series of a given number of terms. 4) A program to perform arithmetic operations like addition and subtraction using switch case.

Uploaded by

tanisq10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Programming in ‘c’ language

NO.1=Write a program to calculate simple intrest?


Coding=
//wap to simple interest
#include <stdio.h>
#include <conio.h>
void main()
{
float p,r,t,si,*p1,*p2,*p3;
p1=&p;
p2=&r;
p3=&t;
printf("\n Enter the principal amount: ");
scanf("%f",&p1);
printf("\n Enter the Rate amount: ");
scanf("%f",&p2);
printf("\n Enter the Time: ");
scanf("%f",&p3);
si=(*p1**p2**p3)/100;
printf("\n the Simple Intrest is=%f",si);
}
Output=
No 2=Write a program to print following pattern ?
Coding=
#include <stdio.h>
#include <conio.h>
void main()
{
int i,j,n;
printf("Enter the rows");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",i);
}
printf("\n");
}
}
Output=

No 3=. Write a program to print fibanky series of terms felony?


Coding=
#include <stdio.h>
#include <conio.h>
void main()
{
int i,n,n1=0,n2=1,n3;
printf("Enter the number;");
scanf("%d",&n);
printf("the fibonnaci series--> \n");
printf("%d \n",n2);
for(i=3;i<=n;i++)
{
n3=n1+n2;
printf("%d \n",n3);
n1=n2;
n2=n3;
}
}
Output=

No 4=Write a program to perform arithmetic operations using switch case?


Coding=
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,ch;
printf("Enter 2 numbers");
scanf("%d%d",&a,&b);
printf("\n1.Add");
printf("\n2.sub");
printf("\nSelect option\n");
scanf("%d",&ch);
switch(ch)
{
case 1:
c=a+b;
printf("add,%d",c);
break;
case 2:
c=b-a;
printf("sub,%d",c);
default:
printf("invalid option");
}
}
Output=
No5=Write a program to find length and reverse of a string?
Coding=
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int I;
char s[10];
printf("enter the string ");
gets(s);
I=strlen(s);
printf("the length of string is %d",I);
}
Output=

No6=. Write a program to call the number of vowels and consonants in each
word of a sentence.?
Coding=
#include <stdio.h>
#include <conio.h>
void main()
{
char str[100];
int i, vowel=0,consonant=0,space=0;
printf("Enter the string: ");
gets(str);//for taking string as an input from user...
for(i=0;str[i]!='\0';i++)
{
if (str[i]=='a'|| str[i]=='e'|| str[i]=='i'||str[i]=='o'||str[i]=='u')
{
vowel++; //for number of vowels...
}
else if(str[i]==' '){
space++; //for number of spaces
}
else
{
consonant=consonant+1; //for number of consonant..
}
}
printf("Number of vowels is :%d\n",vowel);
printf("Number of consonants is : %d",consonant);
}
Output=
No7=Write a program for addition and multiplication of two matrices.?
Coding=

#include<stdio.h>
#include<conio.h>
void main()
{
int r,c,a[100][100],b[100][100],sum[100][100],i,j;
printf("Enter number of rows (belween 1 and 100): ");
scanf("%d",&r);
printf("Enter number of columns (between 1 and 100): ");
scanf("%d",&c);
printf("\nEnter elements of 1st matrix:\n");
/* storing elements of first matrix entered by user.. */
for(i=0;i<r;++i)
for (j=0;j<c;++j)
{
printf("Entert elements a%d%d: ",i+1,j+1);
scanf("%d",&a[i][j]);
}
//storing elements of second matrix entered by user. */
printf("Enter elements od 2ad matrix;\n");
for(i=0;i<r;++i)
for(j=0;j<c;++j)
{
printf("Enter elements a%d%d: ",i+1,j+1);
scanf("%d",&b[i][j]);
}
/*Adding two matrices*/
for(i=0;i<r;++i)
for(j=0;j<c;++j)
sum[i][j]=a[i][j]+b[i][j];
/* Displaying the resultant sum matrix. */
printf("\nSum of two matrix is: /n/n");
for(i=0;i<r;++i)
for(j=0;j<c;++j)
{
printf("%d",sum[i][j]);
if(j==c-1)
printf("\n\n");
}
}
Output=
No8= Write a program to factorial of ane using rewastale.?
Coding=
#include<stdio.h>
#include<conio.h>
int fact(int num);
void main()
{
int num;
printf("enter number\n");
scanf("%d",&num);
printf("factorial of the given is %d",fact(num));
getch();
}
int fact(int num)
{
int f;
if (num==1)
return(1);
else
{
f=num*fact(num-1);
}
}
Output=

No9=Write a program to display the result of the students Using structure.?


Coding=
#include<stdio.h>
#include<conio.h>
int main(){
int marks;

printf("Enter your marks between 0 to 100\n");


scanf("%d",&marks);
switch(marks/10){
case 10:
case 9:
/*marks between 90_100*/
printf("your grade : A\n");
break;
case 8:
case 7:
/*marks between 70-89*/
printf("your grade : B\n");
break;
case 6:
/*marks between 60-69*/
printf("your grade : C\n");
break;
case 5:
case 4:
/*marks between 40-59*/
printf("your grade : D\n");
break;
default:
/*marks less then 40*/
printf("you failed\n");
}
return 0;
}
Output=

No10=Write a program of suapping of tow numbers to demonstrate call by anr


call reference.?
Coding=
#include<stdio.h>
void swap(int * num1, int * num2);
int main()
{
int num1, num2;
printf("enter two numbers;");
scanf("%d%d", &num1, &num2);
printf("before swapping in main n");
printf("valvue of num1 = %d \n", num1);
printf("valvue of num2 =%d \n\n", num2);
swap(&num1, &num2);
printf("before swapping in main n");
printf("valvue of num1 = %d \n", num1);
printf("valvue of num2 =%d \n\n", num2);
return 0;
}
void swap(int * num1, int * num2)
{
int temp;
temp = *num1;
*num1 = *num2;
*num2 = temp;
printf("after swapping in swap function n");
printf("valvue of num1 = %d \n", num1);
printf("valvue of num2 =%d \n\n", num2);
}
Output=

No11=Write a program to demonstrate potter arithmetic.?


Coding=
#include <stdio.h>
#include <conio.h>
void main()
{
int a;
printf("Enter the value of a:");
int *p;
scanf("%d",&a);
p=&a;
printf("the intial value entered is =%d\n",*p);
*p=*p+5;
printf("the value after adding 5 is =%d\n",*p);
*p=*p-2;
printf("the value after substracting by 2 is =%d\n",*p);
*p=++(*p);
printf("the value after increament is =%d\n",*p);
*p=--(*p);
printf("the value after decreament is =%d\n",*p);
}
Output=
END
Chirag singh thakur.

You might also like