C Programs
Program 1: Reverse a String Using Pointer
#include <stdio.h>
int main()
{
char str[50];
char *p;
printf("Enter a string: ");
scanf("%s", str);
p = str;
while (*p != '\0')
p++;
printf("Reversed string: ");
while (p != str)
{
p--;
printf("%c", *p);
}
return 0;
}
Program 2: Largest Number Using Command Line Arguments
Program No 17: Largest among a set of numbers using command line argument
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int i, max;
if (argc < 2)
{
printf("Please enter numbers");
return 0;
}
max = atoi(argv[1]);
for (i = 2; i < argc; i++)
{
if (atoi(argv[i]) > max)
max = atoi(argv[i]);
}
printf("Largest number = %d", max);
return 0;
}