Tag Archives: c program

C program to reverse a given number

This c program reverse a number given by user.


// C program to reverse a given number
//Author:Sani kamal
//date: 24-08-2017

#include<stdio.h>

int main(){
int num,a ,rev=0;
printf("Enter any integer:\n");
scanf("%d",&num);
while(num>=1){
a=num%10;
rev=rev*10+a;
num=num/10;

}
printf("Reverse:%d",rev);

&nbsp;

return 0;

}

Oputput:

Enter any integers:123

Reverse:321

 

C program to show swap of two number without using third variables

Algorithm paradigms (Introduction)

C program to show swap of two number without using third variables

This c program show swap of two number without using third variables.


// C program to show swap of two number without using third variables
//Author:Sani kamal
//date: 24-08-2017

#include<stdio.h>

int main(){
int num1,num2;
printf("Enter the value for num1 and num2:\n");
scanf("%d%d",&num1,&num2);
num1=num1+num2;
num2=num1-num2;
num1=num1-num2;
printf("After swapping the value of num1 and num2:%d %d",num1,num2);

&nbsp;

return 0;

}

Output:

Enter the value for num1 and num2:

3

5

After swapping the value of num1 and num2 :5  3

 

 

 

C program to calculate sum of 5 subjects and find percentage

C program to convert temperature degree centigrade to fahrenheit

C program to convert temperature degree centigrade to fahrenheit

This C program convert temperature centigrade  to fahrenheit scale.


// C program to convert temperature centigrade to fahrenheit
//Author: Sani Kamal

#include<stdio.h>

int main(){
float c,f;
printf("Enter Temperature in centigrade:\n");
scanf("%f",&c);
f=9/5.0*c+32; //formula to convert centigrade to fahrenheit
printf("Temperature in fahrenheit is:%f",f);
return 0;

}

 

Output:

Enter Temperature in centigrade:

14

Temperature in fahrenheit is: 57.200001

 

C Program to find sum of two number

C program to return absolute value

C program to return absolute value like abs() function.

The program need one user input.


// C program to return absolute value like abs() function
//Author: Sani Kamal

#include<stdio.h>

int main(){
int user_abs(int);
int n;
printf("Enter a +VE/-VE number:\n");
scanf("%d",&n);
int result=user_abs(n);
printf("Absolute Value is:%d",result);
return 0;
}
// function to finding absolute value
user_abs(int x){
if(x<0)
return (x*-1);
return x;
}

Output:

Enter +VE/-VE number: -19

Absolute value is: 19